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/constants/971.json b/y2023/constants/971.json
index fc21b74..bc26de8 100644
--- a/y2023/constants/971.json
+++ b/y2023/constants/971.json
@@ -25,6 +25,10 @@
"lateral_position": -0.23
}
]
+ },
+ "wrist_zero": {
+ {% include 'y2023/constants/wrist_common_zeroing.json' %},
+ "measured_absolute_position": 0.616272675539221
}
},
{% include 'y2023/constants/common.json' %}
diff --git a/y2023/constants/9971.json b/y2023/constants/9971.json
index d687c9e..4b10956 100644
--- a/y2023/constants/9971.json
+++ b/y2023/constants/9971.json
@@ -25,6 +25,10 @@
"lateral_position": -0.23
}
]
+ },
+ "wrist_zero": {
+ {% include 'y2023/constants/wrist_common_zeroing.json' %},
+ "measured_absolute_position": 2.94344206522199
}
},
{% include 'y2023/constants/common.json' %}
diff --git a/y2023/constants/BUILD b/y2023/constants/BUILD
index 512e400..bbcec56 100644
--- a/y2023/constants/BUILD
+++ b/y2023/constants/BUILD
@@ -1,4 +1,5 @@
load("//aos/flatbuffers:generate.bzl", "static_flatbuffer")
+load("@aspect_bazel_lib//lib:run_binary.bzl", "run_binary")
load("//tools/build_rules:template.bzl", "jinja2_template")
cc_library(
@@ -19,7 +20,12 @@
jinja2_template(
name = "test_constants.json",
src = "test_constants.jinja2.json",
- includes = glob(["test_data/*.json"]),
+ includes = glob([
+ "test_data/*.json",
+ ]) + [
+ ":wrist_common_zeroing.json",
+ "//y2023/control_loops/superstructure/wrist:wrist_json",
+ ],
parameters = {},
visibility = ["//visibility:public"],
)
@@ -33,6 +39,8 @@
"9971.json",
"common.json",
":scoring_map",
+ ":wrist_common_zeroing.json",
+ "//y2023/control_loops/superstructure/wrist:wrist_json",
"//y2023/vision/calib_files",
"//y2023/vision/maps",
],
@@ -54,8 +62,11 @@
srcs = ["constants.fbs"],
visibility = ["//visibility:public"],
deps = [
+ "//frc971/control_loops:profiled_subsystem_fbs",
+ "//frc971/control_loops:state_feedback_loop_fbs",
"//frc971/vision:calibration_fbs",
"//frc971/vision:target_map_fbs",
+ "//frc971/zeroing:constants_fbs",
"//y2023/localizer:scoring_map_fbs",
],
)
@@ -80,3 +91,19 @@
"//frc971/constants:constants_sender_lib",
],
)
+
+cc_binary(
+ name = "json_codegen",
+ srcs = ["json_codegen.cc"],
+ deps = [
+ "//aos/util:file",
+ "//y2023:constants",
+ ],
+)
+
+run_binary(
+ name = "wrist_json_codegen",
+ outs = ["wrist_common_zeroing.json"],
+ args = ["$(location :wrist_common_zeroing.json)"],
+ tool = ":json_codegen",
+)
diff --git a/y2023/constants/common.json b/y2023/constants/common.json
index d63c518..a120e52 100644
--- a/y2023/constants/common.json
+++ b/y2023/constants/common.json
@@ -3,4 +3,24 @@
"ignore_targets": {
"red": [4],
"blue": [5]
+ },
+ "wrist": {
+ "zeroing_voltage": 3.0,
+ "operating_voltage": 12.0,
+ "zeroing_profile_params": {
+ "max_velocity": 0.5,
+ "max_acceleration": 3.0
+ },
+ "default_profile_params":{
+ "max_velocity": 0.5,
+ "max_acceleration": 5.0
+ },
+ {# The range is currently duplicated from the constants.h; try to fix this. #}
+ "range": {
+ "lower_hard": -0.10,
+ "upper_hard": 4.90,
+ "lower": 0.0,
+ "upper": 4.0
+ },
+ "loop": {% include 'y2023/control_loops/superstructure/wrist/integral_wrist_plant.json' %}
}
diff --git a/y2023/constants/constants.fbs b/y2023/constants/constants.fbs
index 61c3365..8910051 100644
--- a/y2023/constants/constants.fbs
+++ b/y2023/constants/constants.fbs
@@ -1,5 +1,7 @@
include "frc971/vision/calibration.fbs";
include "frc971/vision/target_map.fbs";
+include "frc971/control_loops/profiled_subsystem.fbs";
+include "frc971/zeroing/constants.fbs";
include "y2023/localizer/scoring_map.fbs";
namespace y2023;
@@ -27,6 +29,7 @@
// Table of time-of-flight reading positions. Until we bother using one
// of our interpolation classes, should just contain two values.
tof:TimeOfFlight (id: 0);
+ wrist_zero:frc971.zeroing.AbsoluteEncoderZeroingConstants (id: 1);
}
// Set of april tag targets, by april tag ID, to ignore when on a
@@ -42,6 +45,7 @@
scoring_map:localizer.ScoringMap (id: 2);
robot:RobotConstants (id: 3);
ignore_targets:IgnoreTargets (id: 4);
+ wrist:frc971.control_loops.StaticZeroingSingleDOFProfiledSubsystemCommonParams (id: 5);
}
root_type Constants;
diff --git a/y2023/constants/json_codegen.cc b/y2023/constants/json_codegen.cc
new file mode 100644
index 0000000..fc08df1
--- /dev/null
+++ b/y2023/constants/json_codegen.cc
@@ -0,0 +1,25 @@
+#include "aos/util/file.h"
+#include "y2023/constants.h"
+
+using namespace y2023::constants;
+
+// This file generates some JSON constants information that is currently
+// dependent on values that are located in C++ headers and would be
+// obnoxious/inappropriate to pull out.
+int main(int argc, char *argv[]) {
+ CHECK_EQ(argc, 2) << "Must supply file name to output to.";
+ std::string output_file = argv[1];
+
+ std::stringstream output;
+
+ output << "\"average_filter_size\": " << Values::kZeroingSampleSize << ",\n";
+ output << "\"one_revolution_distance\": "
+ << M_PI * 2.0 * Values::kCompWristEncoderRatio() << ",\n";
+ output << "\"zeroing_threshold\": 0.0005,\n";
+ output << "\"moving_buffer_size\": 20,\n";
+ output << "\"allowable_encoder_error\": 0.9,\n";
+ output << "\"middle_position\": " << Values::kCompWristRange().middle()
+ << "\n";
+ aos::util::WriteStringToFileOrDie(output_file, output.str());
+ return 0;
+}
diff --git a/y2023/constants/test_data/test_team.json b/y2023/constants/test_data/test_team.json
index 0a226f0..bb9c1e4 100644
--- a/y2023/constants/test_data/test_team.json
+++ b/y2023/constants/test_data/test_team.json
@@ -27,8 +27,32 @@
"lateral_position": -0.2
}
]
+ },
+ "wrist_zero": {
+ {% include 'y2023/constants/wrist_common_zeroing.json' %},
+ "measured_absolute_position": 0.0
}
},
+ "wrist": {
+ "zeroing_voltage": 3.0,
+ "operating_voltage": 12.0,
+ "zeroing_profile_params": {
+ "max_velocity": 0.5,
+ "max_acceleration": 3.0
+ },
+ "default_profile_params":{
+ "max_velocity": 0.5,
+ "max_acceleration": 5.0
+ },
+ {# The range is currently duplicated from the constants.h; try to fix this. #}
+ "range": {
+ "lower_hard": -0.10,
+ "upper_hard": 4.90,
+ "lower": 0.0,
+ "upper": 4.0
+ },
+ "loop": {% include 'y2023/control_loops/superstructure/wrist/integral_wrist_plant.json' %}
+ },
"ignore_targets": {
"red": [4],
"blue": [5]