Fix race in localizer_test
The trajectory lock wasn't being grabbed, so the localizer thread wasn't
running. This resulted in a test timeout. Make it more robust!
Change-Id: If2fc227f394060e0ba2cbe55163f96ee14162b1b
diff --git a/frc971/control_loops/drivetrain/splinedrivetrain.cc b/frc971/control_loops/drivetrain/splinedrivetrain.cc
index 1222ae0..c467e1f 100644
--- a/frc971/control_loops/drivetrain/splinedrivetrain.cc
+++ b/frc971/control_loops/drivetrain/splinedrivetrain.cc
@@ -170,6 +170,8 @@
has_started_execution_ = false;
}
mutex_.Unlock();
+ } else {
+ VLOG(1) << "Failed to acquire trajectory lock.";
}
}
diff --git a/y2019/control_loops/drivetrain/localizer_test.cc b/y2019/control_loops/drivetrain/localizer_test.cc
index d9a55f6..b126c6c 100644
--- a/y2019/control_loops/drivetrain/localizer_test.cc
+++ b/y2019/control_loops/drivetrain/localizer_test.cc
@@ -141,6 +141,9 @@
}
void SetUp() {
+ // Turn on -v 1
+ FLAGS_v = std::max(FLAGS_v, 1);
+
flatbuffers::DetachedBuffer goal_buffer;
{
flatbuffers::FlatBufferBuilder fbb;
@@ -185,10 +188,13 @@
aos::FlatbufferDetachedBuffer<frc971::control_loops::drivetrain::Goal> goal(
std::move(goal_buffer));
- spline_drivetrain_.SetGoal(&goal.message());
-
// Let the spline drivetrain compute the spline.
while (true) {
+ // We need to keep sending the goal. There are conditions when the
+ // trajectory lock isn't grabbed the first time, and we want to keep
+ // banging on it to keep trying. Otherwise we deadlock.
+ spline_drivetrain_.SetGoal(&goal.message());
+
::std::this_thread::sleep_for(::std::chrono::milliseconds(5));
flatbuffers::FlatBufferBuilder fbb;