Brian Silverman | 65e4970 | 2014-04-30 17:36:40 -0700 | [diff] [blame^] | 1 | #include "aos/common/controls/control_loop_test.h" |
| 2 | |
| 3 | #include "aos/common/messages/robot_state.q.h" |
| 4 | #include "aos/common/controls/sensor_generation.q.h" |
| 5 | #include "aos/common/controls/output_check.q.h" |
| 6 | #include "aos/common/time.h" |
| 7 | |
| 8 | namespace aos { |
| 9 | namespace testing { |
| 10 | |
| 11 | ControlLoopTest::ControlLoopTest() { |
| 12 | ::aos::robot_state.Clear(); |
| 13 | ::aos::controls::sensor_generation.Clear(); |
| 14 | ::aos::controls::output_check_received.Clear(); |
| 15 | |
| 16 | ::aos::controls::sensor_generation.MakeWithBuilder() |
| 17 | .reader_pid(254) |
| 18 | .cape_resets(5) |
| 19 | .Send(); |
| 20 | ::aos::time::Time::EnableMockTime(::aos::time::Time::InSeconds(0.0)); |
| 21 | |
| 22 | SimulateTimestep(false); |
| 23 | } |
| 24 | |
| 25 | ControlLoopTest::~ControlLoopTest() { |
| 26 | ::aos::robot_state.Clear(); |
| 27 | ::aos::controls::sensor_generation.Clear(); |
| 28 | ::aos::controls::output_check_received.Clear(); |
| 29 | |
| 30 | ::aos::time::Time::DisableMockTime(); |
| 31 | } |
| 32 | |
| 33 | void ControlLoopTest::SimulateTimestep(bool enabled) { |
| 34 | if (sent_robot_state_last_time_) { |
| 35 | sent_robot_state_last_time_ = false; |
| 36 | } else { |
| 37 | ::aos::robot_state.MakeWithBuilder() |
| 38 | .enabled(enabled) |
| 39 | .autonomous(false) |
| 40 | .fake(true) |
| 41 | .team_id(971) |
| 42 | .Send(); |
| 43 | sent_robot_state_last_time_ = true; |
| 44 | } |
| 45 | if (enabled) { |
| 46 | // TODO(brians): Actually make this realistic once we figure out what that |
| 47 | // means. |
| 48 | ::aos::controls::output_check_received.MakeWithBuilder() |
| 49 | .pwm_value(0) |
| 50 | .pulse_length(0) |
| 51 | .Send(); |
| 52 | } |
| 53 | ::aos::time::Time::IncrementMockTime(::aos::time::Time::InMS(10.0)); |
| 54 | } |
| 55 | |
| 56 | } // namespace testing |
| 57 | } // namespace aos |