Add 2023 wrist python codegen
Signed-off-by: milind-u <milind.upadhyay@gmail.com>
Change-Id: Id6aec917eaa81cbafec0d907145d0d0abd5533fe
diff --git a/y2023/control_loops/python/BUILD b/y2023/control_loops/python/BUILD
index f94772d..6109255 100644
--- a/y2023/control_loops/python/BUILD
+++ b/y2023/control_loops/python/BUILD
@@ -106,3 +106,19 @@
"@pip//python_gflags",
],
)
+
+py_binary(
+ name = "wrist",
+ srcs = [
+ "wrist.py",
+ ],
+ legacy_create_init = False,
+ target_compatible_with = ["@platforms//cpu:x86_64"],
+ deps = [
+ ":python_init",
+ "//frc971/control_loops/python:angular_system",
+ "//frc971/control_loops/python:controls",
+ "@pip//glog",
+ "@pip//python_gflags",
+ ],
+)
diff --git a/y2023/control_loops/python/wrist.py b/y2023/control_loops/python/wrist.py
new file mode 100644
index 0000000..26d3a16
--- /dev/null
+++ b/y2023/control_loops/python/wrist.py
@@ -0,0 +1,56 @@
+#!/usr/bin/python3
+
+from aos.util.trapezoid_profile import TrapezoidProfile
+from frc971.control_loops.python import control_loop
+from frc971.control_loops.python import angular_system
+from frc971.control_loops.python import controls
+import numpy
+import sys
+from matplotlib import pylab
+import gflags
+import glog
+
+FLAGS = gflags.FLAGS
+
+try:
+ gflags.DEFINE_bool('plot', False, 'If true, plot the loop response.')
+except gflags.DuplicateFlagError:
+ pass
+
+kWrist = angular_system.AngularSystemParams(
+ name='Wrist',
+ motor=control_loop.BAG(),
+ G=(6.0 / 48.0) * (20.0 / 100.0) * (24.0 / 36.0) * (36.0 / 60.0),
+ # Use parallel axis theorem to get the moment of inertia around
+ # the joint (I = I_cm + mh^2 = 0.001877 + 0.8332 * 0.0407162^2)
+ J=0.003258,
+ q_pos=0.40,
+ q_vel=20.0,
+ kalman_q_pos=0.12,
+ kalman_q_vel=2.0,
+ kalman_q_voltage=4.0,
+ kalman_r_position=0.05,
+ radius=5.71 * 0.0254)
+
+
+def main(argv):
+ if FLAGS.plot:
+ R = numpy.matrix([[numpy.pi / 2.0], [0.0]])
+ angular_system.PlotKick(kIntake, R)
+ angular_system.PlotMotion(kIntake, R)
+
+ # Write the generated constants out to a file.
+ if len(argv) != 5:
+ glog.fatal(
+ 'Expected .h file name and .cc file name for the wrist and integral wrist.'
+ )
+ else:
+ namespaces = ['y2023', 'control_loops', 'superstructure', 'wrist']
+ angular_system.WriteAngularSystem(kWrist, argv[1:3], argv[3:5],
+ namespaces)
+
+
+if __name__ == '__main__':
+ argv = FLAGS(sys.argv)
+ glog.init()
+ sys.exit(main(argv))
diff --git a/y2023/control_loops/superstructure/wrist/BUILD b/y2023/control_loops/superstructure/wrist/BUILD
new file mode 100644
index 0000000..694d95f
--- /dev/null
+++ b/y2023/control_loops/superstructure/wrist/BUILD
@@ -0,0 +1,34 @@
+package(default_visibility = ["//y2023:__subpackages__"])
+
+genrule(
+ name = "genrule_wrist",
+ outs = [
+ "wrist_plant.h",
+ "wrist_plant.cc",
+ "integral_wrist_plant.h",
+ "integral_wrist_plant.cc",
+ ],
+ cmd = "$(location //y2023/control_loops/python:wrist) $(OUTS)",
+ target_compatible_with = ["@platforms//os:linux"],
+ tools = [
+ "//y2023/control_loops/python:wrist",
+ ],
+)
+
+cc_library(
+ name = "wrist_plants",
+ srcs = [
+ "integral_wrist_plant.cc",
+ "wrist_plant.cc",
+ ],
+ hdrs = [
+ "integral_wrist_plant.h",
+ "wrist_plant.h",
+ ],
+ target_compatible_with = ["@platforms//os:linux"],
+ visibility = ["//visibility:public"],
+ deps = [
+ "//frc971/control_loops:hybrid_state_feedback_loop",
+ "//frc971/control_loops:state_feedback_loop",
+ ],
+)