Switch to a batch IMU message
We only send in batches. We would also like to forward these messages
across the network to the logger. The resulting 2000 hz wakeups are
swamping message_gateway, and it isn't worth adding a batch forwarding
mode yet.
Change-Id: I2c2f5bc021a660e932e086965e10bc92f27e2ec1
diff --git a/y2020/BUILD b/y2020/BUILD
index 8beb799..58a99ce 100644
--- a/y2020/BUILD
+++ b/y2020/BUILD
@@ -169,6 +169,7 @@
visibility = ["//visibility:public"],
deps = [
"//aos/events:config",
+ "//frc971/control_loops/drivetrain:config",
],
)
for pi in [
diff --git a/y2020/control_loops/drivetrain/BUILD b/y2020/control_loops/drivetrain/BUILD
index 1bd760f..0e06057 100644
--- a/y2020/control_loops/drivetrain/BUILD
+++ b/y2020/control_loops/drivetrain/BUILD
@@ -110,6 +110,15 @@
],
)
+aos_config(
+ name = "replay_config",
+ src = "drivetrain_replay_config.json",
+ visibility = ["//visibility:public"],
+ deps = [
+ "//y2020:config",
+ ],
+)
+
cc_test(
name = "localizer_test",
srcs = ["localizer_test.cc"],
@@ -131,7 +140,7 @@
name = "drivetrain_replay_test",
srcs = ["drivetrain_replay_test.cc"],
data = [
- "//y2020:config.json",
+ ":replay_config.json",
"@drivetrain_replay//file:spinning_wheels_while_still.bfbs",
],
deps = [
diff --git a/y2020/control_loops/drivetrain/drivetrain_replay_config.json b/y2020/control_loops/drivetrain/drivetrain_replay_config.json
new file mode 100644
index 0000000..987e55b
--- /dev/null
+++ b/y2020/control_loops/drivetrain/drivetrain_replay_config.json
@@ -0,0 +1,13 @@
+{
+ "channels": [
+ {
+ "name": "/drivetrain",
+ "type": "frc971.IMUValues",
+ "frequency": 2000,
+ "source_node": "roborio"
+ }
+ ],
+ "imports": [
+ "../../y2020.json"
+ ]
+}
diff --git a/y2020/control_loops/drivetrain/drivetrain_replay_test.cc b/y2020/control_loops/drivetrain/drivetrain_replay_test.cc
index 6033184..4b02923 100644
--- a/y2020/control_loops/drivetrain/drivetrain_replay_test.cc
+++ b/y2020/control_loops/drivetrain/drivetrain_replay_test.cc
@@ -23,7 +23,7 @@
DEFINE_string(
logfile, "external/drivetrain_replay/file/spinning_wheels_while_still.bfbs",
"Name of the logfile to read from.");
-DEFINE_string(config, "y2020/config.json",
+DEFINE_string(config, "y2020/control_loops/drivetrain/replay_config.json",
"Name of the config file to replay using.");
namespace y2020 {
@@ -67,7 +67,27 @@
config, drivetrain_event_loop_.get(), localizer_.get());
test_event_loop_ =
- reader_.event_loop_factory()->MakeEventLoop("drivetrain", roborio_);
+ reader_.event_loop_factory()->MakeEventLoop("drivetrain_test", roborio_);
+
+ // IMU readings used to be published out one at a time, but we now expect
+ // batches. Batch them up to upgrade the data.
+ imu_sender_ =
+ test_event_loop_->MakeSender<frc971::IMUValuesBatch>("/drivetrain");
+ test_event_loop_->MakeWatcher(
+ "/drivetrain", [this](const frc971::IMUValues &values) {
+ aos::Sender<frc971::IMUValuesBatch>::Builder builder =
+ imu_sender_.MakeBuilder();
+ flatbuffers::Offset<frc971::IMUValues> values_offsets =
+ aos::CopyFlatBuffer(&values, builder.fbb());
+ flatbuffers::Offset<
+ flatbuffers::Vector<flatbuffers::Offset<frc971::IMUValues>>>
+ values_offset = builder.fbb()->CreateVector(&values_offsets, 1);
+ frc971::IMUValuesBatch::Builder imu_values_batch_builder =
+ builder.MakeBuilder<frc971::IMUValuesBatch>();
+ imu_values_batch_builder.add_readings(values_offset);
+ builder.Send(imu_values_batch_builder.Finish());
+ });
+
status_fetcher_ = test_event_loop_->MakeFetcher<
frc971::control_loops::drivetrain::Status>("/drivetrain");
}
@@ -81,6 +101,7 @@
std::unique_ptr<frc971::control_loops::drivetrain::DrivetrainLoop>
drivetrain_;
std::unique_ptr<aos::EventLoop> test_event_loop_;
+ aos::Sender<frc971::IMUValuesBatch> imu_sender_;
aos::Fetcher<frc971::control_loops::drivetrain::Status> status_fetcher_;
};
diff --git a/y2020/y2020_roborio.json b/y2020/y2020_roborio.json
index 86d9b7e..0ab7c36 100644
--- a/y2020/y2020_roborio.json
+++ b/y2020/y2020_roborio.json
@@ -122,9 +122,10 @@
},
{
"name": "/drivetrain",
- "type": "frc971.IMUValues",
+ "type": "frc971.IMUValuesBatch",
"source_node": "roborio",
- "frequency": 2000,
+ "frequency": 200,
+ "max_size": 2000,
"num_senders": 2
},
{