Add Extend Constants
Signed-off-by: Mirabel Wang <mirabel.17.wang@gmail.com>
Change-Id: Iac9692569b52fb9fd121cb3ab45e513202ddbba6
diff --git a/y2024/control_loops/python/BUILD b/y2024/control_loops/python/BUILD
index 93d4fe2..9cbfcf8 100644
--- a/y2024/control_loops/python/BUILD
+++ b/y2024/control_loops/python/BUILD
@@ -122,6 +122,22 @@
],
)
+py_binary(
+ name = "extend",
+ srcs = [
+ "extend.py",
+ ],
+ legacy_create_init = False,
+ target_compatible_with = ["@platforms//cpu:x86_64"],
+ deps = [
+ ":python_init",
+ "//frc971/control_loops/python:controls",
+ "//frc971/control_loops/python:linear_system",
+ "@pip//glog",
+ "@pip//python_gflags",
+ ],
+)
+
py_library(
name = "python_init",
srcs = ["__init__.py"],
diff --git a/y2024/control_loops/python/extend.py b/y2024/control_loops/python/extend.py
new file mode 100644
index 0000000..e84b45e
--- /dev/null
+++ b/y2024/control_loops/python/extend.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 linear_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.')
+
+kExtend = linear_system.LinearSystemParams(
+ name='Extend',
+ motor=control_loop.KrakenFOC(),
+ G=(14. / 60.) * (32. / 48.),
+ radius=36 * 0.005 / numpy.pi / 2.0,
+ mass=5.0,
+ 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,
+)
+
+
+def main(argv):
+ if FLAGS.plot:
+ R = numpy.matrix([[numpy.pi / 2.0], [0.0]])
+ linear_system.PlotKick(kExtend, R)
+ linear_system.PlotMotion(kExtend, 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 extend pivot and integral extend pivot.'
+ )
+ else:
+ namespaces = ['y2024', 'control_loops', 'superstructure', 'extend']
+ linear_system.WriteLinearSystem(kExtend, 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/extend/BUILD b/y2024/control_loops/superstructure/extend/BUILD
new file mode 100644
index 0000000..7a28bde
--- /dev/null
+++ b/y2024/control_loops/superstructure/extend/BUILD
@@ -0,0 +1,42 @@
+package(default_visibility = ["//y2024:__subpackages__"])
+
+genrule(
+ name = "genrule_extend",
+ outs = [
+ "extend_plant.h",
+ "extend_plant.cc",
+ "extend_plant.json",
+ "integral_extend_plant.h",
+ "integral_extend_plant.cc",
+ "integral_extend_plant.json",
+ ],
+ cmd = "$(location //y2024/control_loops/python:extend) $(OUTS)",
+ target_compatible_with = ["@platforms//os:linux"],
+ tools = [
+ "//y2024/control_loops/python:extend",
+ ],
+)
+
+cc_library(
+ name = "extend_plants",
+ srcs = [
+ "extend_plant.cc",
+ "integral_extend_plant.cc",
+ ],
+ hdrs = [
+ "extend_plant.h",
+ "integral_extend_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 = "extend_json",
+ srcs = ["integral_extend_plant.json"],
+ visibility = ["//visibility:public"],
+)