Upgraded the rest of Time.
Change-Id: I0ee083837e51d8f74a798b7ba14a3b6bb3859f35
diff --git a/frc971/control_loops/drivetrain/drivetrain_lib_test.cc b/frc971/control_loops/drivetrain/drivetrain_lib_test.cc
index d3ea2f0..21a968a 100644
--- a/frc971/control_loops/drivetrain/drivetrain_lib_test.cc
+++ b/frc971/control_loops/drivetrain/drivetrain_lib_test.cc
@@ -1,5 +1,6 @@
#include <unistd.h>
+#include <chrono>
#include <memory>
#include "aos/common/controls/control_loop_test.h"
@@ -24,8 +25,8 @@
namespace drivetrain {
namespace testing {
-using ::aos::time::Time;
-
+namespace chrono = ::std::chrono;
+using ::aos::monotonic_clock;
using ::y2016::control_loops::drivetrain::MakeDrivetrainPlant;
// TODO(Comran): Make one that doesn't depend on the actual values for a
@@ -235,9 +236,9 @@
SimulateTimestep(true);
}
- void RunForTime(const Time run_for) {
- const auto end_time = Time::Now() + run_for;
- while (Time::Now() < end_time) {
+ void RunForTime(monotonic_clock::duration run_for) {
+ const auto end_time = monotonic_clock::now() + run_for;
+ while (monotonic_clock::now() < end_time) {
RunIteration();
}
}
@@ -261,7 +262,7 @@
.left_goal(-1.0)
.right_goal(1.0)
.Send();
- RunForTime(Time::InSeconds(2.0));
+ RunForTime(chrono::seconds(2));
VerifyNearGoal();
}
@@ -275,7 +276,7 @@
.Send();
drivetrain_motor_plant_.set_left_voltage_offset(1.0);
drivetrain_motor_plant_.set_right_voltage_offset(1.0);
- RunForTime(Time::InSeconds(1.5));
+ RunForTime(chrono::milliseconds(1500));
VerifyNearGoal();
}
@@ -311,7 +312,7 @@
// Tests that never having a goal, but having driver's station messages, doesn't
// break.
TEST_F(DrivetrainTest, NoGoalWithRobotState) {
- RunForTime(Time::InSeconds(0.1));
+ RunForTime(chrono::milliseconds(100));
}
// Tests that the robot successfully drives straight forward.
@@ -393,7 +394,8 @@
goal.Send();
}
- while (Time::Now() < Time::InSeconds(6)) {
+ while (monotonic_clock::now() <
+ monotonic_clock::time_point(chrono::seconds(6))) {
RunIteration();
ASSERT_TRUE(my_drivetrain_queue_.output.FetchLatest());
EXPECT_NEAR(my_drivetrain_queue_.output->left_voltage,
@@ -423,7 +425,8 @@
goal.Send();
}
- while (Time::Now() < Time::InSeconds(6)) {
+ while (monotonic_clock::now() <
+ monotonic_clock::time_point(chrono::seconds(6))) {
RunIteration();
ASSERT_TRUE(my_drivetrain_queue_.output.FetchLatest());
EXPECT_NEAR(my_drivetrain_queue_.output->left_voltage,
@@ -453,7 +456,8 @@
goal.Send();
}
- while (Time::Now() < Time::InSeconds(3)) {
+ while (monotonic_clock::now() <
+ monotonic_clock::time_point(chrono::seconds(3))) {
RunIteration();
ASSERT_TRUE(my_drivetrain_queue_.output.FetchLatest());
}
@@ -471,7 +475,7 @@
.quickturn(false)
.Send();
- RunForTime(Time::InSeconds(1.0));
+ RunForTime(chrono::seconds(1));
my_drivetrain_queue_.goal.MakeWithBuilder()
.control_loop_driving(false)
@@ -481,7 +485,7 @@
.quickturn(false)
.Send();
- RunForTime(Time::InSeconds(1.0));
+ RunForTime(chrono::seconds(1));
my_drivetrain_queue_.goal.MakeWithBuilder()
.control_loop_driving(false)
@@ -491,7 +495,7 @@
.quickturn(false)
.Send();
- RunForTime(Time::InSeconds(10.0));
+ RunForTime(chrono::seconds(10));
{
::aos::ScopedMessagePtr<::frc971::control_loops::DrivetrainQueue::Goal>
@@ -508,8 +512,8 @@
goal.Send();
}
- const auto end_time = Time::Now() + Time::InSeconds(4);
- while (Time::Now() < end_time) {
+ const auto end_time = monotonic_clock::now() + chrono::seconds(4);
+ while (monotonic_clock::now() < end_time) {
drivetrain_motor_plant_.SendPositionMessage();
drivetrain_motor_.Iterate();
drivetrain_motor_plant_.Simulate();
diff --git a/frc971/control_loops/voltage_cap/voltage_cap_test.cc b/frc971/control_loops/voltage_cap/voltage_cap_test.cc
index 4bee640..23e2f34 100644
--- a/frc971/control_loops/voltage_cap/voltage_cap_test.cc
+++ b/frc971/control_loops/voltage_cap/voltage_cap_test.cc
@@ -7,8 +7,6 @@
#include "aos/common/queue.h"
#include "aos/testing/test_shm.h"
-using ::aos::time::Time;
-
namespace frc971 {
namespace control_loops {
namespace testing {
diff --git a/frc971/control_loops/zeroed_joint.h b/frc971/control_loops/zeroed_joint.h
index f25434f..fcfd29f 100644
--- a/frc971/control_loops/zeroed_joint.h
+++ b/frc971/control_loops/zeroed_joint.h
@@ -135,12 +135,11 @@
ZeroedJoint(StateFeedbackLoop<3, 1, 1> loop)
: loop_(new ZeroedStateFeedbackLoop<kNumZeroSensors>(loop, this)),
- last_good_time_(0, 0),
+ last_good_time_(::aos::monotonic_clock::min_time()),
state_(UNINITIALIZED),
error_count_(0),
zero_offset_(0.0),
- capped_goal_(false) {
- }
+ capped_goal_(false) {}
// Copies the provided configuration data locally.
void set_config_data(const ConfigurationData &config_data) {
@@ -191,14 +190,14 @@
friend class testing::WristTest_NoWindupPositive_Test;
friend class testing::WristTest_NoWindupNegative_Test;
- static const ::aos::time::Time kRezeroTime;
+ static constexpr ::aos::monotonic_clock::duration kRezeroTime;
// The state feedback control loop to talk to.
::std::unique_ptr<ZeroedStateFeedbackLoop<kNumZeroSensors>> loop_;
ConfigurationData config_data_;
- ::aos::time::Time last_good_time_;
+ ::aos::monotonic_clock::time_point last_good_time_;
// Returns the index of the first active sensor, or -1 if none are active.
int ActiveSensorIndex(
@@ -262,8 +261,8 @@
};
template <int kNumZeroSensors>
-const ::aos::time::Time ZeroedJoint<kNumZeroSensors>::kRezeroTime =
- ::aos::time::Time::InSeconds(2);
+constexpr ::aos::monotonic_clock::duration
+ ZeroedJoint<kNumZeroSensors>::kRezeroTime = ::std::chrono::seconds(2);
template <int kNumZeroSensors>
/*static*/ const double ZeroedJoint<kNumZeroSensors>::dt = 0.01;
@@ -283,7 +282,7 @@
output_enabled = false;
LOG(WARNING, "err_count is %d so disabling\n", error_count_);
- if ((::aos::time::Time::Now() - last_good_time_) > kRezeroTime) {
+ if (::aos::monotonic_clock::now() > kRezeroTime + last_good_time_) {
LOG(WARNING, "err_count is %d (or 1st time) so forcing a re-zero\n",
error_count_);
state_ = UNINITIALIZED;
@@ -291,7 +290,7 @@
}
}
if (position != NULL) {
- last_good_time_ = ::aos::time::Time::Now();
+ last_good_time_ = ::aos::monotonic_clock::now();
error_count_ = 0;
}