Add shooter python codegen
Signed-off-by: Maxwell Henderson <mxwhenderson@gmail.com>
Change-Id: I8b76968b8c7628822136155d7a15a149e6d236d6
diff --git a/y2024/control_loops/python/BUILD b/y2024/control_loops/python/BUILD
index da80d87..93d4fe2 100644
--- a/y2024/control_loops/python/BUILD
+++ b/y2024/control_loops/python/BUILD
@@ -77,6 +77,51 @@
],
)
+py_binary(
+ name = "catapult",
+ srcs = [
+ "catapult.py",
+ ],
+ legacy_create_init = False,
+ target_compatible_with = ["@platforms//cpu:x86_64"],
+ deps = [
+ "//frc971/control_loops/python:angular_system",
+ "//frc971/control_loops/python:controls",
+ ],
+)
+
+py_binary(
+ name = "turret",
+ srcs = [
+ "turret.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",
+ ],
+)
+
+py_binary(
+ name = "altitude",
+ srcs = [
+ "altitude.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",
+ ],
+)
+
py_library(
name = "python_init",
srcs = ["__init__.py"],
diff --git a/y2024/control_loops/python/altitude.py b/y2024/control_loops/python/altitude.py
new file mode 100644
index 0000000..157c4a5
--- /dev/null
+++ b/y2024/control_loops/python/altitude.py
@@ -0,0 +1,58 @@
+#!/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
+
+gflags.DEFINE_bool('hybrid', False, 'If true, make it hybrid.')
+
+kAltitude = angular_system.AngularSystemParams(
+ name='Altitude',
+ motor=control_loop.KrakenFOC(),
+ G=(16.0 / 60.0) * (16.0 / 162.0),
+ # 4340 in^ lb
+ J=1.27,
+ q_pos=0.40,
+ q_vel=3.0,
+ kalman_q_pos=0.12,
+ kalman_q_vel=2.0,
+ kalman_q_voltage=4.0,
+ kalman_r_position=0.05,
+ radius=10.5 * 0.0254)
+
+
+def main(argv):
+ if FLAGS.plot:
+ R = numpy.matrix([[numpy.pi / 2.0], [0.0]])
+ angular_system.PlotKick(kAltitude, R)
+ angular_system.PlotMotion(kAltitude, R)
+ return
+
+ # Write the generated constants out to a file.
+ if len(argv) != 7:
+ glog.fatal(
+ 'Expected .h file name and .cc file name for the intake and integral intake.'
+ )
+ else:
+ namespaces = ['y2024', 'control_loops', 'superstructure', 'altitude']
+ angular_system.WriteAngularSystem(kAltitude, argv[1:4], argv[4:7],
+ namespaces)
+
+
+if __name__ == '__main__':
+ argv = FLAGS(sys.argv)
+ glog.init()
+ sys.exit(main(argv))
diff --git a/y2024/control_loops/python/catapult.py b/y2024/control_loops/python/catapult.py
new file mode 100644
index 0000000..c1b1472
--- /dev/null
+++ b/y2024/control_loops/python/catapult.py
@@ -0,0 +1,73 @@
+#!/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
+
+gflags.DEFINE_bool('hybrid', False, 'If true, make it hybrid.')
+
+kCatapultWithGamePiece = angular_system.AngularSystemParams(
+ name='Catapult',
+ motor=control_loop.KrakenFOC(),
+ G=(14.0 / 60.0) * (12.0 / 24.0),
+ # 208.7328 in^2 lb
+ J=0.065,
+ q_pos=0.40,
+ q_vel=3.0,
+ kalman_q_pos=0.12,
+ kalman_q_vel=2.0,
+ kalman_q_voltage=4.0,
+ kalman_r_position=0.05,
+ radius=12 * 0.0254)
+
+kCatapultWithoutGamePiece = angular_system.AngularSystemParams(
+ name='Catapult',
+ motor=control_loop.KrakenFOC(),
+ G=(14.0 / 60.0) * (12.0 / 24.0),
+ # 135.2928 in^2 lb
+ J=0.04,
+ q_pos=0.40,
+ q_vel=3.0,
+ kalman_q_pos=0.12,
+ kalman_q_vel=2.0,
+ kalman_q_voltage=4.0,
+ kalman_r_position=0.05,
+ radius=12 * 0.0254)
+
+
+def main(argv):
+ if FLAGS.plot:
+ R = numpy.matrix([[numpy.pi / 2.0], [0.0]])
+ angular_system.PlotKick(kCatapult, R)
+ angular_system.PlotMotion(kCatapult, R)
+ return
+
+ # Write the generated constants out to a file.
+ if len(argv) != 7:
+ glog.fatal(
+ 'Expected .h file name and .cc file name for the intake and integral intake.'
+ )
+ else:
+ namespaces = ['y2024', 'control_loops', 'superstructure', 'catapult']
+ angular_system.WriteAngularSystem(
+ [kCatapultWithGamePiece, kCatapultWithoutGamePiece], argv[1:4],
+ argv[4:7], namespaces)
+
+
+if __name__ == '__main__':
+ argv = FLAGS(sys.argv)
+ glog.init()
+ sys.exit(main(argv))
diff --git a/y2024/control_loops/python/turret.py b/y2024/control_loops/python/turret.py
new file mode 100644
index 0000000..259e104
--- /dev/null
+++ b/y2024/control_loops/python/turret.py
@@ -0,0 +1,55 @@
+#!/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
+
+kTurret = angular_system.AngularSystemParams(
+ name='Turret',
+ motor=control_loop.KrakenFOC(),
+ G=(14.0 / 60.0) * (28.0 / 48.0) * (22.0 / 100.0),
+ # 1305 in^2 lb
+ J=0.4,
+ 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=24 * 0.0254)
+
+
+def main(argv):
+ if FLAGS.plot:
+ R = numpy.matrix([[numpy.pi], [0.0]])
+ angular_system.PlotKick(kTurret, R)
+ angular_system.PlotMotion(kTurret, R)
+
+ # Write the generated constants out to a file.
+ if len(argv) != 7:
+ glog.fatal(
+ 'Expected .h file name and .cc file name for the turret and integral turret.'
+ )
+ else:
+ namespaces = ['y2024', 'control_loops', 'superstructure', 'turret']
+ angular_system.WriteAngularSystem(kTurret, argv[1:4], argv[4:7],
+ namespaces)
+
+
+if __name__ == '__main__':
+ argv = FLAGS(sys.argv)
+ glog.init()
+ sys.exit(main(argv))
diff --git a/y2024/control_loops/superstructure/altitude/BUILD b/y2024/control_loops/superstructure/altitude/BUILD
new file mode 100644
index 0000000..71e2e3b
--- /dev/null
+++ b/y2024/control_loops/superstructure/altitude/BUILD
@@ -0,0 +1,42 @@
+package(default_visibility = ["//y2024:__subpackages__"])
+
+genrule(
+ name = "genrule_altitude",
+ outs = [
+ "altitude_plant.h",
+ "altitude_plant.cc",
+ "altitude_plant.json",
+ "integral_altitude_plant.h",
+ "integral_altitude_plant.cc",
+ "integral_altitude_plant.json",
+ ],
+ cmd = "$(location //y2024/control_loops/python:altitude) $(OUTS)",
+ target_compatible_with = ["@platforms//os:linux"],
+ tools = [
+ "//y2024/control_loops/python:altitude",
+ ],
+)
+
+cc_library(
+ name = "altitude_plants",
+ srcs = [
+ "altitude_plant.cc",
+ "integral_altitude_plant.cc",
+ ],
+ hdrs = [
+ "altitude_plant.h",
+ "integral_altitude_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",
+ ],
+)
+
+filegroup(
+ name = "altitude_json",
+ srcs = ["integral_altitude_plant.json"],
+ visibility = ["//visibility:public"],
+)
diff --git a/y2024/control_loops/superstructure/catapult/BUILD b/y2024/control_loops/superstructure/catapult/BUILD
new file mode 100644
index 0000000..a6025d8
--- /dev/null
+++ b/y2024/control_loops/superstructure/catapult/BUILD
@@ -0,0 +1,42 @@
+package(default_visibility = ["//y2024:__subpackages__"])
+
+genrule(
+ name = "genrule_catapult",
+ outs = [
+ "catapult_plant.h",
+ "catapult_plant.cc",
+ "catapult_plant.json",
+ "integral_catapult_plant.h",
+ "integral_catapult_plant.cc",
+ "integral_catapult_plant.json",
+ ],
+ cmd = "$(location //y2024/control_loops/python:catapult) $(OUTS)",
+ target_compatible_with = ["@platforms//os:linux"],
+ tools = [
+ "//y2024/control_loops/python:catapult",
+ ],
+)
+
+cc_library(
+ name = "catapult_plants",
+ srcs = [
+ "catapult_plant.cc",
+ "integral_catapult_plant.cc",
+ ],
+ hdrs = [
+ "catapult_plant.h",
+ "integral_catapult_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",
+ ],
+)
+
+filegroup(
+ name = "catapult_json",
+ srcs = ["integral_catapult_plant.json"],
+ visibility = ["//visibility:public"],
+)
diff --git a/y2024/control_loops/superstructure/superstructure_can_position.fbs b/y2024/control_loops/superstructure/superstructure_can_position.fbs
index 69bcdd0..0f751ab 100644
--- a/y2024/control_loops/superstructure/superstructure_can_position.fbs
+++ b/y2024/control_loops/superstructure/superstructure_can_position.fbs
@@ -26,6 +26,12 @@
// CAN Position of the retention roller falcon
retention_roller:frc971.control_loops.CANTalonFX (id: 6);
+
+ // CAN Position of the shooter turret falcon
+ turret:frc971.control_loops.CANTalonFX (id: 7);
+
+ // CAN Position of the shooter altitude falcon
+ altitude:frc971.control_loops.CANTalonFX (id: 8);
}
root_type CANPosition;
diff --git a/y2024/control_loops/superstructure/superstructure_status.fbs b/y2024/control_loops/superstructure/superstructure_status.fbs
index 3a4b443..ceed417 100644
--- a/y2024/control_loops/superstructure/superstructure_status.fbs
+++ b/y2024/control_loops/superstructure/superstructure_status.fbs
@@ -57,6 +57,9 @@
// Estimated angle and angular velocitiy of the climber.
climber_state:frc971.control_loops.PotAndAbsoluteEncoderProfiledJointStatus (id: 5);
+
+ // Status of the subsytems involved in the shooter
+ shooter_status:ShooterStatus (id: 6);
}
root_type Status;
diff --git a/y2024/control_loops/superstructure/turret/BUILD b/y2024/control_loops/superstructure/turret/BUILD
new file mode 100644
index 0000000..c67eb89
--- /dev/null
+++ b/y2024/control_loops/superstructure/turret/BUILD
@@ -0,0 +1,42 @@
+package(default_visibility = ["//y2024:__subpackages__"])
+
+genrule(
+ name = "genrule_turret",
+ outs = [
+ "turret_plant.h",
+ "turret_plant.cc",
+ "turret_plant.json",
+ "integral_turret_plant.h",
+ "integral_turret_plant.cc",
+ "integral_turret_plant.json",
+ ],
+ cmd = "$(location //y2024/control_loops/python:turret) $(OUTS)",
+ target_compatible_with = ["@platforms//os:linux"],
+ tools = [
+ "//y2024/control_loops/python:turret",
+ ],
+)
+
+cc_library(
+ name = "turret_plants",
+ srcs = [
+ "integral_turret_plant.cc",
+ "turret_plant.cc",
+ ],
+ hdrs = [
+ "integral_turret_plant.h",
+ "turret_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",
+ ],
+)
+
+filegroup(
+ name = "turret_json",
+ srcs = ["integral_turret_plant.json"],
+ visibility = ["//visibility:public"],
+)