blob: a8deecffce355f6fcbe6794d8250fcf690b5d67e [file] [log] [blame]
Brian Silverman65e49702014-04-30 17:36:40 -07001#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 Silverman65e49702014-04-30 17:36:40 -07006
7namespace aos {
8namespace testing {
9
Brian Silvermane6f64ab2015-02-05 17:03:56 -050010constexpr ::aos::time::Time ControlLoopTest::kTimeTick;
11constexpr ::aos::time::Time ControlLoopTest::kDSPacketTime;
12
Brian Silverman65e49702014-04-30 17:36:40 -070013ControlLoopTest::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 Silvermanbbc86782014-08-19 12:13:05 -040022 ::aos::time::Time::EnableMockTime(current_time_);
Brian Silverman65e49702014-04-30 17:36:40 -070023
24 SimulateTimestep(false);
25}
26
27ControlLoopTest::~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 Silvermane6f64ab2015-02-05 17:03:56 -050035void ControlLoopTest::SendMessages(bool enabled) {
36 if (current_time_ - last_ds_time_ >= kDSPacketTime) {
Brian Silverman65e49702014-04-30 17:36:40 -070037 ::aos::robot_state.MakeWithBuilder()
38 .enabled(enabled)
39 .autonomous(false)
40 .fake(true)
41 .team_id(971)
42 .Send();
Brian Silvermane6f64ab2015-02-05 17:03:56 -050043 last_ds_time_ = current_time_;
Brian Silverman65e49702014-04-30 17:36:40 -070044 }
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 Silverman65e49702014-04-30 17:36:40 -070053}
54
55} // namespace testing
56} // namespace aos