Make DMA pulse width work
The sensors return 1 when there is no ball...
Also fix a move before get to a get before move to fix a segfault
Change-Id: If7ebcda52c18f011eb7583a494eb52a8d038cb1b
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/y2020/control_loops/superstructure/shooter/shooter_tuning_readings.fbs b/y2020/control_loops/superstructure/shooter/shooter_tuning_readings.fbs
index ca10302..ae0c379 100644
--- a/y2020/control_loops/superstructure/shooter/shooter_tuning_readings.fbs
+++ b/y2020/control_loops/superstructure/shooter/shooter_tuning_readings.fbs
@@ -1,14 +1,14 @@
-namespace y2020.control_loops.superstructure.shooter;
-
-// Contains the readings used to tune the accelerator
-// and finisher velocities to minimize variation in ball velocity.
-// We have two sensors, and find the time that the ball takes to
-// pass between the two to find its velocity.
-// This will be sent each time a ball is detected.
-table TuningReadings {
- // The velocity (m/s) of the last ball passing between the two
- // sensors
- velocity_ball:double (id: 0);
-}
-
-root_type TuningReadings;
\ No newline at end of file
+namespace y2020.control_loops.superstructure.shooter;
+
+// Contains the readings used to tune the accelerator
+// and finisher velocities to minimize variation in ball velocity.
+// We have two sensors, and find the time that the ball takes to
+// pass between the two to find its velocity.
+// This will be sent each time a ball is detected.
+table TuningReadings {
+ // The velocity (m/s) of the last ball passing between the two
+ // sensors
+ velocity_ball:double (id: 0);
+}
+
+root_type TuningReadings;
diff --git a/y2020/wpilib_interface.cc b/y2020/wpilib_interface.cc
index c79ba88..3e91d1e 100644
--- a/y2020/wpilib_interface.cc
+++ b/y2020/wpilib_interface.cc
@@ -207,8 +207,8 @@
::std::unique_ptr<frc::DigitalInput> sensor2) {
ball_beambreak_inputs_[0] = ::std::move(sensor1);
ball_beambreak_inputs_[1] = ::std::move(sensor2);
- ball_beambreak_reader_.set_input_one(sensor1.get());
- ball_beambreak_reader_.set_input_two(sensor2.get());
+ ball_beambreak_reader_.set_input_one(ball_beambreak_inputs_[0].get());
+ ball_beambreak_reader_.set_input_two(ball_beambreak_inputs_[1].get());
}
void Start() override {
@@ -316,19 +316,20 @@
builder.Send(auto_mode_builder.Finish());
}
- if (FLAGS_shooter_tuning &&
- ball_beambreak_reader_.pulses_detected() > balls_detected_) {
- balls_detected_ = ball_beambreak_reader_.pulses_detected();
-
+ if (FLAGS_shooter_tuning) {
// Distance between beambreak sensors, in meters.
constexpr double kDistanceBetweenBeambreaks = 0.4813;
- auto builder = shooter_tuning_readings_sender_.MakeBuilder();
- auto shooter_tuning_readings_builder =
- builder.MakeBuilder<superstructure::shooter::TuningReadings>();
- shooter_tuning_readings_builder.add_velocity_ball(
- kDistanceBetweenBeambreaks / ball_beambreak_reader_.last_width());
- builder.Send(shooter_tuning_readings_builder.Finish());
+ if (ball_beambreak_reader_.pulses_detected() > balls_detected_) {
+ balls_detected_ = ball_beambreak_reader_.pulses_detected();
+
+ auto builder = shooter_tuning_readings_sender_.MakeBuilder();
+ auto shooter_tuning_readings_builder =
+ builder.MakeBuilder<superstructure::shooter::TuningReadings>();
+ shooter_tuning_readings_builder.add_velocity_ball(
+ kDistanceBetweenBeambreaks / ball_beambreak_reader_.last_width());
+ builder.Send(shooter_tuning_readings_builder.Finish());
+ }
}
}