Add logger to superstructure
This lets us plot problems.
Change-Id: I24e37518962b164520075a0a71d073545db99621
diff --git a/y2020/control_loops/superstructure/BUILD b/y2020/control_loops/superstructure/BUILD
index 87ee689..631a21d 100644
--- a/y2020/control_loops/superstructure/BUILD
+++ b/y2020/control_loops/superstructure/BUILD
@@ -94,6 +94,7 @@
":superstructure_status_fbs",
"//aos:math",
"//aos/controls:control_loop_test",
+ "//aos/events/logging:logger",
"//aos/testing:googletest",
"//aos/time",
"//frc971/control_loops:capped_test_plant",
diff --git a/y2020/control_loops/superstructure/shooter_plot.pb b/y2020/control_loops/superstructure/shooter_plot.pb
new file mode 100644
index 0000000..01a1e20
--- /dev/null
+++ b/y2020/control_loops/superstructure/shooter_plot.pb
@@ -0,0 +1,44 @@
+channel {
+ name: "/superstructure"
+ type: "y2020.control_loops.superstructure.Status"
+ alias: "Status"
+}
+channel {
+ name: "/superstructure"
+ type: "y2020.control_loops.superstructure.Output"
+ alias: "Output"
+}
+channel {
+ name: "/superstructure"
+ type: "y2020.control_loops.superstructure.Position"
+ alias: "Position"
+}
+channel {
+ name: "/superstructure"
+ type: "y2020.control_loops.superstructure.Goal"
+ alias: "Goal"
+}
+
+figure {
+ axes {
+ line {
+ y_signal {
+ channel: "Status"
+ field: "hood.position"
+ }
+ }
+ line {
+ y_signal {
+ channel: "Goal"
+ field: "hood.unsafe_goal"
+ }
+ }
+ line {
+ y_signal {
+ channel: "Position"
+ field: "hood.encoder"
+ }
+ }
+ ylabel: "hood position"
+ }
+}
diff --git a/y2020/control_loops/superstructure/superstructure_lib_test.cc b/y2020/control_loops/superstructure/superstructure_lib_test.cc
index 458a771..37ee0bb 100644
--- a/y2020/control_loops/superstructure/superstructure_lib_test.cc
+++ b/y2020/control_loops/superstructure/superstructure_lib_test.cc
@@ -4,6 +4,7 @@
#include <memory>
#include "aos/controls/control_loop_test.h"
+#include "aos/events/logging/logger.h"
#include "frc971/control_loops/capped_test_plant.h"
#include "frc971/control_loops/position_sensor_sim.h"
#include "frc971/control_loops/team_number_test_environment.h"
@@ -13,6 +14,9 @@
#include "y2020/control_loops/superstructure/intake/intake_plant.h"
#include "y2020/control_loops/superstructure/superstructure.h"
+DEFINE_string(output_file, "",
+ "If set, logs all channels to the provided logfile.");
+
namespace y2020 {
namespace control_loops {
namespace superstructure {
@@ -315,6 +319,15 @@
superstructure_plant_event_loop_(MakeEventLoop("plant")),
superstructure_plant_(superstructure_plant_event_loop_.get(), dt()) {
set_team_id(::frc971::control_loops::testing::kTeamNumber);
+
+ if (!FLAGS_output_file.empty()) {
+ unlink(FLAGS_output_file.c_str());
+ log_buffer_writer_ = std::make_unique<aos::logger::DetachedBufferWriter>(
+ FLAGS_output_file);
+ logger_event_loop_ = MakeEventLoop("logger");
+ logger_ = std::make_unique<aos::logger::Logger>(log_buffer_writer_.get(),
+ logger_event_loop_.get());
+ }
}
void VerifyNearGoal() {
@@ -372,6 +385,10 @@
::std::unique_ptr<::aos::EventLoop> superstructure_plant_event_loop_;
SuperstructureSimulation superstructure_plant_;
+
+ std::unique_ptr<aos::EventLoop> logger_event_loop_;
+ std::unique_ptr<aos::logger::DetachedBufferWriter> log_buffer_writer_;
+ std::unique_ptr<aos::logger::Logger> logger_;
};
// Tests that the superstructure does nothing when the goal is to remain still.