make the claw and fridge tests use standard infrastructure

Change-Id: I65cbc5e665ecb8099abf41e2503c2b0e80ad3f88
diff --git a/aos/common/controls/control_loop_test.cc b/aos/common/controls/control_loop_test.cc
index ab47477..a8deecf 100644
--- a/aos/common/controls/control_loop_test.cc
+++ b/aos/common/controls/control_loop_test.cc
@@ -7,6 +7,9 @@
 namespace aos {
 namespace testing {
 
+constexpr ::aos::time::Time ControlLoopTest::kTimeTick;
+constexpr ::aos::time::Time ControlLoopTest::kDSPacketTime;
+
 ControlLoopTest::ControlLoopTest() {
   ::aos::robot_state.Clear();
   ::aos::controls::sensor_generation.Clear();
@@ -29,17 +32,15 @@
   ::aos::time::Time::DisableMockTime();
 }
 
-void ControlLoopTest::SimulateTimestep(bool enabled) {
-  if (sent_robot_state_last_time_) {
-    sent_robot_state_last_time_ = false;
-  } else {
+void ControlLoopTest::SendMessages(bool enabled) {
+  if (current_time_ - last_ds_time_ >= kDSPacketTime) {
     ::aos::robot_state.MakeWithBuilder()
         .enabled(enabled)
         .autonomous(false)
         .fake(true)
         .team_id(971)
         .Send();
-    sent_robot_state_last_time_ = true;
+    last_ds_time_ = current_time_;
   }
   if (enabled) {
     // TODO(brians): Actually make this realistic once we figure out what that
@@ -49,8 +50,6 @@
         .pulse_length(0)
         .Send();
   }
-  ::aos::time::Time::SetMockTime(current_time_ +=
-                                 ::aos::time::Time::InMS(10.0));
 }
 
 }  // namespace testing
diff --git a/aos/common/controls/control_loop_test.h b/aos/common/controls/control_loop_test.h
index de048ba..76c68d3 100644
--- a/aos/common/controls/control_loop_test.h
+++ b/aos/common/controls/control_loop_test.h
@@ -17,14 +17,27 @@
 class ControlLoopTest : public ::testing::Test {
  public:
   ControlLoopTest();
-
   virtual ~ControlLoopTest();
 
-  // Simulates everything that happens during 1 time step.
-  void SimulateTimestep(bool enabled);
+  // Sends out all of the required queue messages.
+  void SendMessages(bool enabled);
+  // Ticks time for a single control loop cycle.
+  void TickTime() {
+    ::aos::time::Time::SetMockTime(current_time_ += kTimeTick);
+  }
+
+  // Simulates everything that happens during 1 loop time step.
+  void SimulateTimestep(bool enabled) {
+    SendMessages(enabled);
+    TickTime();
+  }
 
  private:
-  bool sent_robot_state_last_time_ = false;
+  static constexpr ::aos::time::Time kTimeTick = ::aos::time::Time::InUS(10000);
+  static constexpr ::aos::time::Time kDSPacketTime =
+      ::aos::time::Time::InMS(20);
+
+  ::aos::time::Time last_ds_time_ = ::aos::time::Time::InSeconds(0);
   ::aos::time::Time current_time_ = ::aos::time::Time::InSeconds(0);
 
   ::aos::common::testing::GlobalCoreInstance my_core;
diff --git a/frc971/control_loops/claw/claw.gyp b/frc971/control_loops/claw/claw.gyp
index 78f9c18..c1f2191 100644
--- a/frc971/control_loops/claw/claw.gyp
+++ b/frc971/control_loops/claw/claw.gyp
@@ -46,8 +46,8 @@
       'dependencies': [
         '<(EXTERNALS):gtest',
         'claw_lib',
-        '<(AOS)/common/common.gyp:queue_testutils',
         '<(DEPTH)/frc971/control_loops/control_loops.gyp:state_feedback_loop',
+        '<(AOS)/common/controls/controls.gyp:control_loop_test',
       ],
     },
     {
diff --git a/frc971/control_loops/claw/claw_lib_test.cc b/frc971/control_loops/claw/claw_lib_test.cc
index 64ec631..ca9f7a0 100644
--- a/frc971/control_loops/claw/claw_lib_test.cc
+++ b/frc971/control_loops/claw/claw_lib_test.cc
@@ -3,9 +3,8 @@
 #include <memory>
 
 #include "gtest/gtest.h"
-#include "aos/common/controls/sensor_generation.q.h"
 #include "aos/common/queue.h"
-#include "aos/common/queue_testutils.h"
+#include "aos/common/controls/control_loop_test.h"
 #include "frc971/control_loops/claw/claw.q.h"
 #include "frc971/control_loops/claw/claw.h"
 #include "frc971/constants.h"
@@ -32,13 +31,6 @@
 
   // Sends a queue message with the position.
   void SendPositionMessage() {
-    ::aos::ScopedMessagePtr<aos::controls::SensorGeneration>
-        sensor_generation_msg =
-            ::aos::controls::sensor_generation.MakeMessage();
-    sensor_generation_msg->reader_pid = 0;
-    sensor_generation_msg->cape_resets = 0;
-    sensor_generation_msg.Send();
-
     ::aos::ScopedMessagePtr<control_loops::ClawQueue::Position> position =
       claw_queue_.position.MakeMessage();
     position.Send();
@@ -56,35 +48,16 @@
   ClawQueue claw_queue_;
 };
 
-class ClawTest : public ::testing::Test {
+class ClawTest : public ::aos::testing::ControlLoopTest {
  protected:
-  ClawTest() : claw_queue_(".frc971.control_loops.claw_queue",
-                                   0x9d7452fb,
-                                   ".frc971.control_loops.claw_queue.goal",
-                                   ".frc971.control_loops.claw_queue.position",
-                                   ".frc971.control_loops.claw_queue.output",
-                                   ".frc971.control_loops.claw_queue.status"),
-                  claw_(&claw_queue_),
-                  claw_plant_() {
-    // Flush the robot state queue so we can use clean shared memory for this
-    // test.
-    ::aos::robot_state.Clear();
-    SendDSPacket(true);
-  }
-
-  virtual ~ClawTest() {
-    ::aos::robot_state.Clear();
-    ::aos::controls::sensor_generation.Clear();
-  }
-
-  // Update the robot state. Without this, the Iteration of the control loop
-  // will stop all the motors and this won't go anywhere.
-  void SendDSPacket(bool enabled) {
-    ::aos::robot_state.MakeWithBuilder().enabled(enabled)
-                                        .autonomous(false)
-                                        .team_id(971).Send();
-    ::aos::robot_state.FetchLatest();
-  }
+  ClawTest()
+      : claw_queue_(".frc971.control_loops.claw_queue", 0x9d7452fb,
+                    ".frc971.control_loops.claw_queue.goal",
+                    ".frc971.control_loops.claw_queue.position",
+                    ".frc971.control_loops.claw_queue.output",
+                    ".frc971.control_loops.claw_queue.status"),
+        claw_(&claw_queue_),
+        claw_plant_() {}
 
   void VerifyNearGoal() {
     claw_queue_.goal.FetchLatest();
@@ -94,9 +67,6 @@
                 10.0);
   }
 
-  // Bring up and down Core.
-  ::aos::common::testing::GlobalCoreInstance my_core;
-
   // Create a new instance of the test queue so that it invalidates the queue
   // that it points to.  Otherwise, we will have a pointed to
   // shared memory that is no longer valid.
@@ -110,10 +80,11 @@
 // Tests that the loop does nothing when the goal is zero.
 TEST_F(ClawTest, DoesNothing) {
   claw_queue_.goal.MakeWithBuilder().angle(0.0).Send();
-  SendDSPacket(true);
+  SendMessages(true);
   claw_plant_.SendPositionMessage();
   claw_.Iterate();
   claw_plant_.Simulate();
+  TickTime();
   VerifyNearGoal();
   claw_queue_.output.FetchLatest();
   EXPECT_EQ(claw_queue_.output->voltage, 0.0);
diff --git a/frc971/control_loops/fridge/fridge.gyp b/frc971/control_loops/fridge/fridge.gyp
index 6edee2b..868bdb9 100644
--- a/frc971/control_loops/fridge/fridge.gyp
+++ b/frc971/control_loops/fridge/fridge.gyp
@@ -47,8 +47,8 @@
       'dependencies': [
         '<(EXTERNALS):gtest',
         'fridge_lib',
-        '<(AOS)/common/common.gyp:queue_testutils',
         '<(DEPTH)/frc971/control_loops/control_loops.gyp:state_feedback_loop',
+        '<(AOS)/common/controls/controls.gyp:control_loop_test',
       ],
     },
     {
diff --git a/frc971/control_loops/fridge/fridge_lib_test.cc b/frc971/control_loops/fridge/fridge_lib_test.cc
index 1eb6185..fa6ba69 100644
--- a/frc971/control_loops/fridge/fridge_lib_test.cc
+++ b/frc971/control_loops/fridge/fridge_lib_test.cc
@@ -3,9 +3,8 @@
 #include <memory>
 
 #include "gtest/gtest.h"
-#include "aos/common/controls/sensor_generation.q.h"
 #include "aos/common/queue.h"
-#include "aos/common/queue_testutils.h"
+#include "aos/common/controls/control_loop_test.h"
 #include "frc971/control_loops/fridge/fridge.q.h"
 #include "frc971/control_loops/fridge/fridge.h"
 #include "frc971/constants.h"
@@ -32,13 +31,6 @@
 
   // Sends a queue message with the position.
   void SendPositionMessage() {
-    ::aos::ScopedMessagePtr<aos::controls::SensorGeneration>
-        sensor_generation_msg =
-            ::aos::controls::sensor_generation.MakeMessage();
-    sensor_generation_msg->reader_pid = 0;
-    sensor_generation_msg->cape_resets = 0;
-    sensor_generation_msg.Send();
-
     ::aos::ScopedMessagePtr<control_loops::FridgeQueue::Position> position =
         fridge_queue_.position.MakeMessage();
     position.Send();
@@ -58,7 +50,7 @@
   FridgeQueue fridge_queue_;
 };
 
-class FridgeTest : public ::testing::Test {
+class FridgeTest : public ::aos::testing::ControlLoopTest {
  protected:
   FridgeTest()
       : fridge_queue_(".frc971.control_loops.fridge_queue", 0xe4e05855,
@@ -67,26 +59,7 @@
                       ".frc971.control_loops.fridge_queue.output",
                       ".frc971.control_loops.fridge_queue.status"),
         fridge_(&fridge_queue_),
-        fridge_plant_() {
-    // Flush the robot state queue so we can use clean shared memory for this
-    // test.
-    ::aos::robot_state.Clear();
-    SendDSPacket(true);
-  }
-
-  virtual ~FridgeTest() {
-    ::aos::robot_state.Clear();
-    ::aos::controls::sensor_generation.Clear();
-  }
-
-  // Update the robot state. Without this, the Iteration of the control loop
-  // will stop all the motors and the shooter won't go anywhere.
-  void SendDSPacket(bool enabled) {
-    ::aos::robot_state.MakeWithBuilder().enabled(enabled)
-                                        .autonomous(false)
-                                        .team_id(971).Send();
-    ::aos::robot_state.FetchLatest();
-  }
+        fridge_plant_() {}
 
   void VerifyNearGoal() {
     fridge_queue_.goal.FetchLatest();
@@ -99,9 +72,6 @@
                 10.0);
   }
 
-  // Bring up and down Core.
-  ::aos::common::testing::GlobalCoreInstance my_core;
-
   // Create a new instance of the test queue so that it invalidates the queue
   // that it points to.  Otherwise, we will have a pointed to
   // shared memory that is no longer valid.
@@ -115,10 +85,11 @@
 // Tests that the loop does nothing when the goal is zero.
 TEST_F(FridgeTest, DoesNothing) {
   fridge_queue_.goal.MakeWithBuilder().angle(0.0).height(0.0).Send();
-  SendDSPacket(true);
+  SendMessages(true);
   fridge_plant_.SendPositionMessage();
   fridge_.Iterate();
   fridge_plant_.Simulate();
+  TickTime();
   VerifyNearGoal();
   fridge_queue_.output.FetchLatest();
   EXPECT_EQ(fridge_queue_.output->left_arm, 0.0);