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 | |
Brian Silverman | e6f64ab | 2015-02-05 17:03:56 -0500 | [diff] [blame^] | 10 | constexpr ::aos::time::Time ControlLoopTest::kTimeTick; |
| 11 | constexpr ::aos::time::Time ControlLoopTest::kDSPacketTime; |
| 12 | |
Brian Silverman | 65e4970 | 2014-04-30 17:36:40 -0700 | [diff] [blame] | 13 | ControlLoopTest::ControlLoopTest() { |
| 14 | ::aos::robot_state.Clear(); |
| 15 | ::aos::controls::sensor_generation.Clear(); |
| 16 | ::aos::controls::output_check_received.Clear(); |
| 17 | |
| 18 | ::aos::controls::sensor_generation.MakeWithBuilder() |
| 19 | .reader_pid(254) |
| 20 | .cape_resets(5) |
| 21 | .Send(); |
Brian Silverman | bbc8678 | 2014-08-19 12:13:05 -0400 | [diff] [blame] | 22 | ::aos::time::Time::EnableMockTime(current_time_); |
Brian Silverman | 65e4970 | 2014-04-30 17:36:40 -0700 | [diff] [blame] | 23 | |
| 24 | SimulateTimestep(false); |
| 25 | } |
| 26 | |
| 27 | ControlLoopTest::~ControlLoopTest() { |
| 28 | ::aos::robot_state.Clear(); |
| 29 | ::aos::controls::sensor_generation.Clear(); |
| 30 | ::aos::controls::output_check_received.Clear(); |
| 31 | |
| 32 | ::aos::time::Time::DisableMockTime(); |
| 33 | } |
| 34 | |
Brian Silverman | e6f64ab | 2015-02-05 17:03:56 -0500 | [diff] [blame^] | 35 | void ControlLoopTest::SendMessages(bool enabled) { |
| 36 | if (current_time_ - last_ds_time_ >= kDSPacketTime) { |
Brian Silverman | 65e4970 | 2014-04-30 17:36:40 -0700 | [diff] [blame] | 37 | ::aos::robot_state.MakeWithBuilder() |
| 38 | .enabled(enabled) |
| 39 | .autonomous(false) |
| 40 | .fake(true) |
| 41 | .team_id(971) |
| 42 | .Send(); |
Brian Silverman | e6f64ab | 2015-02-05 17:03:56 -0500 | [diff] [blame^] | 43 | last_ds_time_ = current_time_; |
Brian Silverman | 65e4970 | 2014-04-30 17:36:40 -0700 | [diff] [blame] | 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 | } |
Brian Silverman | 65e4970 | 2014-04-30 17:36:40 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | } // namespace testing |
| 56 | } // namespace aos |