Swap y2023 wrist over to the constants.json
There are a couple of awkward constants that show up in json_codegen.cc
as still being managed from the C++ end; there are also a couple of
codegen'd constants from the wrist python code that we use in
constants.h. However, this does move *all* of the per-robot
configuration into the constants JSON file and should allow us to remove
the superstructure's dependency on the constants.h (if the arm were also
converted over).
Change-Id: Id9fc1e80830af823d96e5f3c1e469495eba454a4
Signed-off-by: James Kuszmaul <jabukuszmaul+collab@gmail.com>
diff --git a/y2023/control_loops/python/wrist.py b/y2023/control_loops/python/wrist.py
index fe2fcf6..3ad404c 100644
--- a/y2023/control_loops/python/wrist.py
+++ b/y2023/control_loops/python/wrist.py
@@ -41,13 +41,13 @@
return
# Write the generated constants out to a file.
- if len(argv) != 5:
+ if len(argv) != 7:
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],
+ angular_system.WriteAngularSystem(kWrist, argv[1:4], argv[4:7],
namespaces)
diff --git a/y2023/control_loops/superstructure/superstructure.cc b/y2023/control_loops/superstructure/superstructure.cc
index e11092a..0ee1061 100644
--- a/y2023/control_loops/superstructure/superstructure.cc
+++ b/y2023/control_loops/superstructure/superstructure.cc
@@ -34,7 +34,8 @@
event_loop->MakeFetcher<aos::JoystickState>("/aos")),
arm_(values_, arm_trajectories.message()),
end_effector_(),
- wrist_(values->wrist.subsystem_params) {
+ wrist_(constants_fetcher_.constants().wrist(),
+ constants_fetcher_.constants().robot()->wrist_zero()) {
event_loop->SetRuntimeRealtimePriority(30);
}
diff --git a/y2023/control_loops/superstructure/superstructure_lib_test.cc b/y2023/control_loops/superstructure/superstructure_lib_test.cc
index d4fa653..5973eee 100644
--- a/y2023/control_loops/superstructure/superstructure_lib_test.cc
+++ b/y2023/control_loops/superstructure/superstructure_lib_test.cc
@@ -175,15 +175,23 @@
chrono::nanoseconds dt)
: event_loop_(event_loop),
dt_(dt),
+ constants_fetcher_(event_loop),
arm_(values->arm_proximal.zeroing, values->arm_distal.zeroing,
values->roll_joint.zeroing, dt_),
wrist_(new CappedTestPlant(wrist::MakeWristPlant()),
- PositionSensorSimulator(
- values->wrist.subsystem_params.zeroing_constants
- .one_revolution_distance),
- values->wrist, constants::Values::kCompWristRange(),
- values->wrist.subsystem_params.zeroing_constants
- .measured_absolute_position,
+ PositionSensorSimulator(constants_fetcher_.constants()
+ .robot()
+ ->wrist_zero()
+ ->one_revolution_distance()),
+ {.subsystem_params =
+ {constants_fetcher_.constants().wrist(),
+ constants_fetcher_.constants().robot()->wrist_zero()}},
+ frc971::constants::Range::FromFlatbuffer(
+ constants_fetcher_.constants().wrist()->range()),
+ constants_fetcher_.constants()
+ .robot()
+ ->wrist_zero()
+ ->measured_absolute_position(),
dt_),
superstructure_position_sender_(
event_loop_->MakeSender<Position>("/superstructure")),
@@ -257,6 +265,7 @@
::aos::EventLoop *event_loop_;
const chrono::nanoseconds dt_;
::aos::PhasedLoopHandler *phased_loop_handle_ = nullptr;
+ frc971::constants::ConstantsFetcher<Constants> constants_fetcher_;
ArmSimulation arm_;
AbsoluteEncoderSimulator wrist_;
diff --git a/y2023/control_loops/superstructure/wrist/BUILD b/y2023/control_loops/superstructure/wrist/BUILD
index 694d95f..212c203 100644
--- a/y2023/control_loops/superstructure/wrist/BUILD
+++ b/y2023/control_loops/superstructure/wrist/BUILD
@@ -5,8 +5,10 @@
outs = [
"wrist_plant.h",
"wrist_plant.cc",
+ "wrist_plant.json",
"integral_wrist_plant.h",
"integral_wrist_plant.cc",
+ "integral_wrist_plant.json",
],
cmd = "$(location //y2023/control_loops/python:wrist) $(OUTS)",
target_compatible_with = ["@platforms//os:linux"],
@@ -32,3 +34,9 @@
"//frc971/control_loops:state_feedback_loop",
],
)
+
+filegroup(
+ name = "wrist_json",
+ srcs = ["integral_wrist_plant.json"],
+ visibility = ["//visibility:public"],
+)