Converted mock time over to using monotonic_clock
Change-Id: I17850e25586be9bf732a0ca3a4e0b1a76146a539
diff --git a/aos/common/controls/control_loop_test.cc b/aos/common/controls/control_loop_test.cc
index 44af93a..b71aa3a 100644
--- a/aos/common/controls/control_loop_test.cc
+++ b/aos/common/controls/control_loop_test.cc
@@ -5,14 +5,14 @@
namespace aos {
namespace testing {
-constexpr ::aos::time::Time ControlLoopTest::kTimeTick;
-constexpr ::aos::time::Time ControlLoopTest::kDSPacketTime;
+constexpr ::std::chrono::milliseconds ControlLoopTest::kTimeTick;
+constexpr ::std::chrono::milliseconds ControlLoopTest::kDSPacketTime;
ControlLoopTest::ControlLoopTest() {
::aos::joystick_state.Clear();
::aos::robot_state.Clear();
- ::aos::time::Time::EnableMockTime(current_time_);
+ ::aos::time::EnableMockTime(current_time_);
SendMessages(false);
}
@@ -21,11 +21,11 @@
::aos::joystick_state.Clear();
::aos::robot_state.Clear();
- ::aos::time::Time::DisableMockTime();
+ ::aos::time::DisableMockTime();
}
void ControlLoopTest::SendMessages(bool enabled) {
- if (current_time_ - last_ds_time_ >= kDSPacketTime ||
+ if (current_time_ >= kDSPacketTime + last_ds_time_ ||
last_enabled_ != enabled) {
last_ds_time_ = current_time_;
auto new_state = ::aos::joystick_state.MakeMessage();
diff --git a/aos/common/controls/control_loop_test.h b/aos/common/controls/control_loop_test.h
index 14fdd60..88ccfa5 100644
--- a/aos/common/controls/control_loop_test.h
+++ b/aos/common/controls/control_loop_test.h
@@ -25,9 +25,7 @@
// Sends out all of the required queue messages.
void SendMessages(bool enabled);
// Ticks time for a single control loop cycle.
- void TickTime() {
- ::aos::time::Time::SetMockTime(current_time_ += kTimeTick);
- }
+ void TickTime() { ::aos::time::SetMockTime(current_time_ += kTimeTick); }
// Simulates everything that happens during 1 loop time step.
void SimulateTimestep(bool enabled) {
@@ -47,16 +45,17 @@
}
private:
- static constexpr ::aos::time::Time kTimeTick = ::aos::time::Time::InUS(5000);
- static constexpr ::aos::time::Time kDSPacketTime =
- ::aos::time::Time::InMS(20);
+ static constexpr ::std::chrono::milliseconds kTimeTick{5};
+ static constexpr ::std::chrono::milliseconds kDSPacketTime{20};
uint16_t team_id_ = 971;
int32_t reader_pid_ = 1;
double battery_voltage_ = 12.4;
- ::aos::time::Time last_ds_time_ = ::aos::time::Time::InSeconds(0);
- ::aos::time::Time current_time_ = ::aos::time::Time::InSeconds(0);
+ ::aos::monotonic_clock::time_point last_ds_time_ =
+ ::aos::monotonic_clock::epoch();
+ ::aos::monotonic_clock::time_point current_time_ =
+ ::aos::monotonic_clock::epoch();
::aos::testing::TestSharedMemory my_shm_;