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