blob: a1165a979c4f50ad5d706c328c24a2ff25db0b8c [file] [log] [blame]
Brian Silverman65e49702014-04-30 17:36:40 -07001#ifndef AOS_COMMON_CONTROLS_CONTROL_LOOP_TEST_H_
2#define AOS_COMMON_CONTROLS_CONTROL_LOOP_TEST_H_
3
4#include "gtest/gtest.h"
5
6#include "aos/common/queue_testutils.h"
Brian Silvermanbbc86782014-08-19 12:13:05 -04007#include "aos/common/time.h"
Brian Silverman65e49702014-04-30 17:36:40 -07008
9namespace aos {
10namespace testing {
11
12// Handles setting up the environment that all control loops need to actually
13// run.
14// This includes sending the queue messages and Clear()ing the queues when
15// appropriate.
16// It also includes dealing with ::aos::time.
17class ControlLoopTest : public ::testing::Test {
18 public:
19 ControlLoopTest();
Brian Silverman65e49702014-04-30 17:36:40 -070020 virtual ~ControlLoopTest();
21
Philipp Schraderf75a8bf2015-02-02 05:30:16 +000022 void set_team_id(uint16_t team_id) { team_id_ = team_id; }
23 uint16_t team_id() const { return team_id_; }
24
Brian Silvermane6f64ab2015-02-05 17:03:56 -050025 // Sends out all of the required queue messages.
26 void SendMessages(bool enabled);
27 // Ticks time for a single control loop cycle.
28 void TickTime() {
29 ::aos::time::Time::SetMockTime(current_time_ += kTimeTick);
30 }
31
32 // Simulates everything that happens during 1 loop time step.
33 void SimulateTimestep(bool enabled) {
34 SendMessages(enabled);
35 TickTime();
36 }
Brian Silverman65e49702014-04-30 17:36:40 -070037
38 private:
Brian Silverman699f0cb2015-02-05 19:45:01 -050039 static constexpr ::aos::time::Time kTimeTick = ::aos::time::Time::InUS(5000);
Brian Silvermane6f64ab2015-02-05 17:03:56 -050040 static constexpr ::aos::time::Time kDSPacketTime =
41 ::aos::time::Time::InMS(20);
42
Philipp Schraderf75a8bf2015-02-02 05:30:16 +000043 uint16_t team_id_ = 971;
44
Brian Silvermane6f64ab2015-02-05 17:03:56 -050045 ::aos::time::Time last_ds_time_ = ::aos::time::Time::InSeconds(0);
Brian Silvermanbbc86782014-08-19 12:13:05 -040046 ::aos::time::Time current_time_ = ::aos::time::Time::InSeconds(0);
Brian Silverman65e49702014-04-30 17:36:40 -070047
48 ::aos::common::testing::GlobalCoreInstance my_core;
49};
50
51} // namespace testing
52} // namespace aos
53
54#endif // AOS_COMMON_CONTROLS_CONTROL_LOOP_TEST_H_