make the claw and fridge tests use standard infrastructure
Change-Id: I65cbc5e665ecb8099abf41e2503c2b0e80ad3f88
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);