Upgraded the rest of Time.
Change-Id: I0ee083837e51d8f74a798b7ba14a3b6bb3859f35
diff --git a/y2016/actors/autonomous_actor.cc b/y2016/actors/autonomous_actor.cc
index f298420..5194b2d 100644
--- a/y2016/actors/autonomous_actor.cc
+++ b/y2016/actors/autonomous_actor.cc
@@ -19,6 +19,9 @@
namespace y2016 {
namespace actors {
using ::frc971::control_loops::drivetrain_queue;
+using ::aos::monotonic_clock;
+namespace chrono = ::std::chrono;
+namespace this_thread = ::std::this_thread;
namespace {
const ProfileParameters kSlowDrive = {0.8, 2.5};
@@ -40,6 +43,11 @@
const ProfileParameters kTwoBallReturnSlow = {3.0, 2.5};
const ProfileParameters kTwoBallBallPickup = {2.0, 1.75};
const ProfileParameters kTwoBallBallPickupAccel = {2.0, 2.5};
+
+double DoubleSeconds(monotonic_clock::duration duration) {
+ return ::std::chrono::duration_cast<::std::chrono::duration<double>>(duration)
+ .count();
+}
} // namespace
AutonomousActor::AutonomousActor(actors::AutonomousActionQueueGroup *s)
@@ -438,16 +446,16 @@
}
void AutonomousActor::WaitForAlignedWithVision(
- ::aos::time::Time align_duration) {
+ chrono::nanoseconds align_duration) {
bool vision_valid = false;
double last_angle = 0.0;
int ready_to_fire = 0;
::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(5),
::std::chrono::milliseconds(5) / 2);
- ::aos::time::Time end_time =
- ::aos::time::Time::Now() + align_duration;
- while (end_time > ::aos::time::Time::Now()) {
+ monotonic_clock::time_point end_time =
+ monotonic_clock::now() + align_duration;
+ while (end_time > monotonic_clock::now()) {
if (ShouldCancel()) break;
::y2016::vision::vision_status.FetchLatest();
@@ -674,7 +682,7 @@
LOG(INFO, "Waiting for the superstructure\n");
WaitForSuperstructure();
- ::aos::time::SleepFor(::aos::time::Time::InSeconds(0.5));
+ this_thread::sleep_for(chrono::milliseconds(500));
if (ShouldCancel()) return;
LOG(INFO, "Triggering the vision actor\n");
@@ -683,13 +691,13 @@
// Wait for the drive base to be aligned with the target and make sure that
// the shooter is up to speed.
LOG(INFO, "Waiting for vision to be aligned\n");
- WaitForAlignedWithVision(aos::time::Time::InSeconds(2));
+ WaitForAlignedWithVision(chrono::milliseconds(2000));
if (ShouldCancel()) return;
LOG(INFO, "Waiting for shooter to be up to speed\n");
WaitForShooterSpeed();
if (ShouldCancel()) return;
- ::aos::time::SleepFor(::aos::time::Time::InSeconds(0.3));
+ this_thread::sleep_for(chrono::milliseconds(300));
LOG(INFO, "Shoot!\n");
Shoot();
@@ -822,7 +830,7 @@
}
void AutonomousActor::TwoBallAuto() {
- aos::time::Time start_time = aos::time::Time::Now();
+ monotonic_clock::time_point start_time = monotonic_clock::now();
OpenShooter();
MoveSuperstructure(0.10, -0.010, 0.0, {8.0, 60.0}, {4.0, 10.0}, {10.0, 25.0},
false, 12.0);
@@ -831,7 +839,7 @@
WaitForIntake();
LOG(INFO, "Intake done at %f seconds, starting to drive\n",
- (aos::time::Time::Now() - start_time).ToSeconds());
+ DoubleSeconds(monotonic_clock::now() - start_time));
if (ShouldCancel()) return;
const double kDriveDistance = 5.05;
StartDrive(-kDriveDistance, 0.0, kTwoBallLowDrive, kSlowTurn);
@@ -846,12 +854,12 @@
const bool ball_detected = ::y2016::sensors::ball_detector->voltage > 2.5;
first_ball_there = ball_detected;
LOG(INFO, "Saw the ball: %d at %f\n", first_ball_there,
- (aos::time::Time::Now() - start_time).ToSeconds());
+ DoubleSeconds(monotonic_clock::now() - start_time));
}
MoveSuperstructure(0.10, -0.010, 0.0, {8.0, 40.0}, {4.0, 10.0}, {10.0, 25.0},
false, 0.0);
LOG(INFO, "Shutting off rollers at %f seconds, starting to straighten out\n",
- (aos::time::Time::Now() - start_time).ToSeconds());
+ DoubleSeconds(monotonic_clock::now() - start_time));
StartDrive(0.0, -0.4, kTwoBallLowDrive, kSwerveTurn);
MoveSuperstructure(-0.05, -0.010, 0.0, {8.0, 40.0}, {4.0, 10.0}, {10.0, 25.0},
false, 0.0);
@@ -871,7 +879,7 @@
if (!WaitForDriveDone()) return;
LOG(INFO, "First shot done driving at %f seconds\n",
- (aos::time::Time::Now() - start_time).ToSeconds());
+ DoubleSeconds(monotonic_clock::now() - start_time));
WaitForSuperstructureProfile();
@@ -881,8 +889,8 @@
WaitForShooterSpeed();
if (ShouldCancel()) return;
- constexpr double kVisionExtra = 0.0;
- WaitForAlignedWithVision(aos::time::Time::InSeconds(0.5 + kVisionExtra));
+ constexpr chrono::milliseconds kVisionExtra{0};
+ WaitForAlignedWithVision(chrono::milliseconds(500) + kVisionExtra);
BackLongShotTwoBallFinish();
WaitForSuperstructureProfile();
if (ShouldCancel()) return;
@@ -894,7 +902,7 @@
}
LOG(INFO, "First shot at %f seconds\n",
- (aos::time::Time::Now() - start_time).ToSeconds());
+ DoubleSeconds(monotonic_clock::now() - start_time));
if (ShouldCancel()) return;
SetShooterSpeed(0.0);
@@ -914,7 +922,7 @@
if (!WaitForDriveNear(0.06, kDoNotTurnCare)) return;
LOG(INFO, "At Low Bar %f\n",
- (aos::time::Time::Now() - start_time).ToSeconds());
+ DoubleSeconds(monotonic_clock::now() - start_time));
OpenShooter();
constexpr double kSecondBallAfterBarDrive = 2.10;
@@ -932,7 +940,7 @@
false, 12.0);
LOG(INFO, "Done backing up %f\n",
- (aos::time::Time::Now() - start_time).ToSeconds());
+ DoubleSeconds(monotonic_clock::now() - start_time));
constexpr double kDriveBackDistance = 5.15 - 0.4;
StartDrive(-kDriveBackDistance, 0.0, kTwoBallLowDrive, kFinishTurn);
@@ -941,7 +949,7 @@
StartDrive(0.0, -kBallSmallWallTurn, kTwoBallLowDrive, kFinishTurn);
LOG(INFO, "Straightening up at %f\n",
- (aos::time::Time::Now() - start_time).ToSeconds());
+ DoubleSeconds(monotonic_clock::now() - start_time));
CloseIfBall();
if (!WaitForDriveNear(kDriveBackDistance - 2.3, kDoNotTurnCare)) return;
@@ -952,7 +960,7 @@
if (!ball_detected) {
if (!WaitForDriveDone()) return;
LOG(INFO, "Aborting, no ball %f\n",
- (aos::time::Time::Now() - start_time).ToSeconds());
+ DoubleSeconds(monotonic_clock::now() - start_time));
return;
}
}
@@ -969,7 +977,7 @@
if (!WaitForDriveDone()) return;
LOG(INFO, "Second shot done driving at %f seconds\n",
- (aos::time::Time::Now() - start_time).ToSeconds());
+ DoubleSeconds(monotonic_clock::now() - start_time));
WaitForSuperstructure();
AlignWithVisionGoal();
if (ShouldCancel()) return;
@@ -980,27 +988,29 @@
// 2.2 with 0.4 of vision.
// 1.8 without any vision.
LOG(INFO, "Going to vision align at %f\n",
- (aos::time::Time::Now() - start_time).ToSeconds());
- WaitForAlignedWithVision(start_time + aos::time::Time::InSeconds(13.5 + kVisionExtra * 2) -
- aos::time::Time::Now());
+ DoubleSeconds(monotonic_clock::now() - start_time));
+ WaitForAlignedWithVision(
+ (start_time + chrono::milliseconds(13500) + kVisionExtra * 2) -
+ monotonic_clock::now());
BackLongShotTwoBallFinish();
WaitForSuperstructureProfile();
if (ShouldCancel()) return;
- LOG(INFO, "Shoot at %f\n", (aos::time::Time::Now() - start_time).ToSeconds());
+ LOG(INFO, "Shoot at %f\n",
+ DoubleSeconds(monotonic_clock::now() - start_time));
Shoot();
LOG(INFO, "Second shot at %f seconds\n",
- (aos::time::Time::Now() - start_time).ToSeconds());
+ DoubleSeconds(monotonic_clock::now() - start_time));
if (ShouldCancel()) return;
SetShooterSpeed(0.0);
LOG(INFO, "Folding superstructure back down\n");
TuckArm(true, false);
- LOG(INFO, "Shot %f\n", (aos::time::Time::Now() - start_time).ToSeconds());
+ LOG(INFO, "Shot %f\n", DoubleSeconds(monotonic_clock::now() - start_time));
WaitForSuperstructureLow();
- LOG(INFO, "Done %f\n", (aos::time::Time::Now() - start_time).ToSeconds());
+ LOG(INFO, "Done %f\n", DoubleSeconds(monotonic_clock::now() - start_time));
}
void AutonomousActor::StealAndMoveOverBy(double distance) {
@@ -1024,7 +1034,7 @@
}
bool AutonomousActor::RunAction(const actors::AutonomousActionParams ¶ms) {
- aos::time::Time start_time = aos::time::Time::Now();
+ monotonic_clock::time_point start_time = monotonic_clock::now();
LOG(INFO, "Starting autonomous action with mode %" PRId32 "\n", params.mode);
InitializeEncoders();
@@ -1166,7 +1176,7 @@
StartDrive(0.5, 0.0, kMoatDrive, kFastTurn);
if (!WaitForDriveDone()) return true;
- LOG(INFO, "Done %f\n", (aos::time::Time::Now() - start_time).ToSeconds());
+ LOG(INFO, "Done %f\n", DoubleSeconds(monotonic_clock::now() - start_time));
::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(5),
::std::chrono::milliseconds(5) / 2);
diff --git a/y2016/actors/autonomous_actor.h b/y2016/actors/autonomous_actor.h
index 9a26731..7cf932a 100644
--- a/y2016/actors/autonomous_actor.h
+++ b/y2016/actors/autonomous_actor.h
@@ -1,15 +1,15 @@
#ifndef Y2016_ACTORS_AUTONOMOUS_ACTOR_H_
#define Y2016_ACTORS_AUTONOMOUS_ACTOR_H_
+#include <chrono>
#include <memory>
-#include "aos/common/actions/actor.h"
#include "aos/common/actions/actions.h"
-
-#include "y2016/actors/autonomous_action.q.h"
-#include "y2016/actors/vision_align_actor.h"
+#include "aos/common/actions/actor.h"
#include "frc971/control_loops/drivetrain/drivetrain.q.h"
#include "frc971/control_loops/drivetrain/drivetrain_config.h"
+#include "y2016/actors/autonomous_action.q.h"
+#include "y2016/actors/vision_align_actor.h"
namespace y2016 {
namespace actors {
@@ -111,7 +111,7 @@
void Shoot();
void AlignWithVisionGoal();
- void WaitForAlignedWithVision(aos::time::Time align_duration);
+ void WaitForAlignedWithVision(::std::chrono::nanoseconds align_duration);
void TwoBallAuto();
diff --git a/y2016/actors/autonomous_actor_main.cc b/y2016/actors/autonomous_actor_main.cc
index 8f0b305..6f01e65 100644
--- a/y2016/actors/autonomous_actor_main.cc
+++ b/y2016/actors/autonomous_actor_main.cc
@@ -4,8 +4,6 @@
#include "y2016/actors/autonomous_action.q.h"
#include "y2016/actors/autonomous_actor.h"
-using ::aos::time::Time;
-
int main(int /*argc*/, char * /*argv*/ []) {
::aos::Init(-1);
diff --git a/y2016/actors/superstructure_actor_main.cc b/y2016/actors/superstructure_actor_main.cc
index a6da2a2..0b3c4be 100644
--- a/y2016/actors/superstructure_actor_main.cc
+++ b/y2016/actors/superstructure_actor_main.cc
@@ -4,8 +4,6 @@
#include "y2016/actors/superstructure_action.q.h"
#include "y2016/actors/superstructure_actor.h"
-using ::aos::time::Time;
-
int main(int /*argc*/, char* /*argv*/ []) {
::aos::Init(-1);
diff --git a/y2016/actors/vision_align_actor_main.cc b/y2016/actors/vision_align_actor_main.cc
index ccd4734..17fdc0a 100644
--- a/y2016/actors/vision_align_actor_main.cc
+++ b/y2016/actors/vision_align_actor_main.cc
@@ -4,8 +4,6 @@
#include "y2016/actors/vision_align_action.q.h"
#include "y2016/actors/vision_align_actor.h"
-using ::aos::time::Time;
-
int main(int /*argc*/, char* /*argv*/ []) {
::aos::Init(-1);
diff --git a/y2016/control_loops/superstructure/superstructure_lib_test.cc b/y2016/control_loops/superstructure/superstructure_lib_test.cc
index 1efdfcf..e95267c 100644
--- a/y2016/control_loops/superstructure/superstructure_lib_test.cc
+++ b/y2016/control_loops/superstructure/superstructure_lib_test.cc
@@ -2,22 +2,22 @@
#include <unistd.h>
+#include <chrono>
#include <memory>
-#include "gtest/gtest.h"
-#include "aos/common/queue.h"
-#include "aos/common/controls/control_loop_test.h"
#include "aos/common/commonmath.h"
+#include "aos/common/controls/control_loop_test.h"
+#include "aos/common/queue.h"
#include "aos/common/time.h"
#include "frc971/control_loops/position_sensor_sim.h"
#include "frc971/control_loops/team_number_test_environment.h"
-#include "y2016/control_loops/superstructure/superstructure.q.h"
-#include "y2016/control_loops/superstructure/intake_plant.h"
+#include "gtest/gtest.h"
#include "y2016/control_loops/superstructure/arm_plant.h"
+#include "y2016/control_loops/superstructure/intake_plant.h"
+#include "y2016/control_loops/superstructure/superstructure.q.h"
#include "y2016/constants.h"
-using ::aos::time::Time;
using ::frc971::control_loops::PositionSensorSimulator;
namespace y2016 {
@@ -25,6 +25,9 @@
namespace superstructure {
namespace testing {
+namespace chrono = ::std::chrono;
+using ::aos::monotonic_clock;
+
class ArmPlant : public StateFeedbackPlant<4, 2, 2> {
public:
explicit ArmPlant(StateFeedbackPlant<4, 2, 2> &&other)
@@ -284,10 +287,10 @@
}
// Runs iterations until the specified amount of simulated time has elapsed.
- void RunForTime(const Time &run_for, bool enabled = true) {
- const auto start_time = Time::Now();
- while (Time::Now() < start_time + run_for) {
- const auto loop_start_time = Time::Now();
+ void RunForTime(monotonic_clock::duration run_for, bool enabled = true) {
+ const auto start_time = monotonic_clock::now();
+ while (monotonic_clock::now() < start_time + run_for) {
+ const auto loop_start_time = monotonic_clock::now();
double begin_shoulder_velocity =
superstructure_plant_.shoulder_angular_velocity();
double begin_intake_velocity =
@@ -295,7 +298,9 @@
double begin_wrist_velocity =
superstructure_plant_.wrist_angular_velocity();
RunIteration(enabled);
- const double loop_time = (Time::Now() - loop_start_time).ToSeconds();
+ const double loop_time =
+ chrono::duration_cast<chrono::duration<double>>(
+ monotonic_clock::now() - loop_start_time).count();
const double shoulder_acceleration =
(superstructure_plant_.shoulder_angular_velocity() -
begin_shoulder_velocity) /
@@ -398,7 +403,7 @@
.Send());
// TODO(phil): Send a goal of some sort.
- RunForTime(Time::InSeconds(5));
+ RunForTime(chrono::seconds(5));
VerifyNearGoal();
}
@@ -418,7 +423,7 @@
.Send());
// Give it a lot of time to get there.
- RunForTime(Time::InSeconds(8));
+ RunForTime(chrono::seconds(8));
VerifyNearGoal();
}
@@ -438,7 +443,7 @@
.max_angular_velocity_wrist(20)
.max_angular_acceleration_wrist(20)
.Send());
- RunForTime(Time::InSeconds(10));
+ RunForTime(chrono::seconds(10));
// Check that we are near our soft limit.
superstructure_queue_.status.FetchLatest();
@@ -463,7 +468,7 @@
.max_angular_acceleration_wrist(20)
.Send());
- RunForTime(Time::InSeconds(10));
+ RunForTime(chrono::seconds(10));
// Check that we are near our soft limit.
superstructure_queue_.status.FetchLatest();
@@ -488,7 +493,7 @@
.max_angular_acceleration_wrist(20)
.Send());
- RunForTime(Time::InSeconds(10));
+ RunForTime(chrono::seconds(10));
// Check that we are near our soft limit.
superstructure_queue_.status.FetchLatest();
@@ -513,14 +518,14 @@
.max_angular_acceleration_wrist(20)
.Send());
- RunForTime(Time::InSeconds(10));
+ RunForTime(chrono::seconds(10));
VerifyNearGoal();
}
// Tests that the loop zeroes when run for a while without a goal.
TEST_F(SuperstructureTest, ZeroNoGoal) {
- RunForTime(Time::InSeconds(5));
+ RunForTime(chrono::seconds(5));
EXPECT_EQ(Superstructure::RUNNING, superstructure_.state());
}
@@ -543,7 +548,7 @@
constants::Values::kShoulderRange.upper)
.Send());
// We have to wait for it to put the elevator in a safe position as well.
- RunForTime(Time::InSeconds(15));
+ RunForTime(chrono::seconds(15));
VerifyNearGoal();
}
@@ -561,8 +566,9 @@
.angle_shoulder(constants::Values::kShoulderRange.lower)
.angle_wrist(0.0)
.Send());
- // We have to wait for it to put the elevator in a safe position as well.
- RunForTime(Time::InSeconds(20));
+ // We have to wait for it to put the superstructure in a safe position as
+ // well.
+ RunForTime(chrono::seconds(20));
VerifyNearGoal();
}
@@ -581,14 +587,14 @@
.angle_shoulder(constants::Values::kShoulderRange.upper)
.angle_wrist(0.0)
.Send());
- RunForTime(Time::InSeconds(15));
+ RunForTime(chrono::seconds(15));
EXPECT_EQ(Superstructure::RUNNING, superstructure_.state());
VerifyNearGoal();
SimulateSensorReset();
- RunForTime(Time::InMS(100));
+ RunForTime(chrono::milliseconds(100));
EXPECT_NE(Superstructure::RUNNING, superstructure_.state());
- RunForTime(Time::InMS(10000));
+ RunForTime(chrono::milliseconds(10000));
EXPECT_EQ(Superstructure::RUNNING, superstructure_.state());
VerifyNearGoal();
}
@@ -605,13 +611,13 @@
.angle_wrist(constants::Values::kWristRange.lower + 0.03)
.Send());
- RunForTime(Time::InMS(100), false);
+ RunForTime(chrono::milliseconds(100), false);
EXPECT_EQ(0.0, superstructure_.intake_.goal(0, 0));
EXPECT_EQ(0.0, superstructure_.arm_.goal(0, 0));
EXPECT_EQ(0.0, superstructure_.arm_.goal(2, 0));
// Now make sure they move correctly
- RunForTime(Time::InMS(4000), true);
+ RunForTime(chrono::milliseconds(4000), true);
EXPECT_NE(0.0, superstructure_.intake_.goal(0, 0));
EXPECT_NE(0.0, superstructure_.arm_.goal(0, 0));
EXPECT_NE(0.0, superstructure_.arm_.goal(2, 0));
@@ -678,7 +684,7 @@
EXPECT_EQ(Superstructure::DISABLED_INITIALIZED, superstructure_.state());
}
- RunForTime(Time::InSeconds(10));
+ RunForTime(chrono::seconds(10));
EXPECT_EQ(Superstructure::RUNNING, superstructure_.state());
}
@@ -742,7 +748,7 @@
EXPECT_EQ(Superstructure::DISABLED_INITIALIZED, superstructure_.state());
}
- RunForTime(Time::InSeconds(10));
+ RunForTime(chrono::seconds(10));
EXPECT_EQ(Superstructure::LANDING_RUNNING, superstructure_.state());
}
@@ -771,7 +777,7 @@
.angle_wrist(0.0)
.Send();
- RunForTime(Time::InSeconds(8));
+ RunForTime(chrono::seconds(8));
VerifyNearGoal();
}
@@ -792,15 +798,15 @@
.Send();
// Run disabled for 2 seconds
- RunForTime(Time::InSeconds(2), false);
+ RunForTime(chrono::seconds(2), false);
EXPECT_EQ(Superstructure::DISABLED_INITIALIZED, superstructure_.state());
superstructure_plant_.set_power_error(1.0, 1.5, 1.0);
- RunForTime(Time::InSeconds(1), false);
+ RunForTime(chrono::seconds(1), false);
EXPECT_EQ(Superstructure::SLOW_RUNNING, superstructure_.state());
- RunForTime(Time::InSeconds(2), true);
+ RunForTime(chrono::seconds(2), true);
VerifyNearGoal();
}
@@ -839,7 +845,7 @@
.max_angular_acceleration_wrist(20)
.Send());
- RunForTime(Time::InSeconds(6));
+ RunForTime(chrono::seconds(6));
EXPECT_EQ(Superstructure::RUNNING, superstructure_.state());
VerifyNearGoal();
@@ -862,7 +868,7 @@
set_peak_intake_acceleration(1.10);
set_peak_shoulder_acceleration(1.20);
set_peak_wrist_acceleration(1.10);
- RunForTime(Time::InSeconds(6));
+ RunForTime(chrono::seconds(6));
VerifyNearGoal();
}
@@ -881,7 +887,7 @@
.max_angular_acceleration_wrist(20)
.Send());
- RunForTime(Time::InSeconds(6));
+ RunForTime(chrono::seconds(6));
EXPECT_EQ(Superstructure::RUNNING, superstructure_.state());
VerifyNearGoal();
@@ -901,7 +907,7 @@
set_peak_intake_acceleration(1.20);
set_peak_shoulder_acceleration(1.20);
set_peak_wrist_acceleration(1.20);
- RunForTime(Time::InSeconds(4));
+ RunForTime(chrono::seconds(4));
VerifyNearGoal();
}
@@ -923,7 +929,7 @@
.max_angular_acceleration_wrist(20)
.Send());
- RunForTime(Time::InSeconds(6));
+ RunForTime(chrono::seconds(6));
EXPECT_EQ(Superstructure::RUNNING, superstructure_.state());
VerifyNearGoal();
@@ -946,7 +952,7 @@
set_peak_intake_acceleration(1.05);
set_peak_shoulder_acceleration(1.05);
set_peak_wrist_acceleration(1.05);
- RunForTime(Time::InSeconds(4));
+ RunForTime(chrono::seconds(4));
VerifyNearGoal();
}
@@ -968,7 +974,7 @@
.max_angular_acceleration_wrist(20)
.Send());
- RunForTime(Time::InSeconds(6));
+ RunForTime(chrono::seconds(6));
EXPECT_EQ(Superstructure::RUNNING, superstructure_.state());
VerifyNearGoal();
@@ -990,7 +996,7 @@
set_peak_intake_velocity(4.65);
set_peak_shoulder_velocity(1.00);
set_peak_wrist_velocity(1.00);
- RunForTime(Time::InSeconds(4));
+ RunForTime(chrono::seconds(4));
VerifyNearGoal();
}
@@ -1010,7 +1016,7 @@
.max_angular_acceleration_wrist(20)
.Send());
- RunForTime(Time::InSeconds(6));
+ RunForTime(chrono::seconds(6));
EXPECT_EQ(Superstructure::RUNNING, superstructure_.state());
VerifyNearGoal();
@@ -1030,7 +1036,7 @@
set_peak_intake_velocity(1.0);
set_peak_shoulder_velocity(5.5);
set_peak_wrist_velocity(1.0);
- RunForTime(Time::InSeconds(4));
+ RunForTime(chrono::seconds(4));
VerifyNearGoal();
}
@@ -1053,7 +1059,7 @@
.max_angular_acceleration_wrist(20)
.Send());
- RunForTime(Time::InSeconds(6));
+ RunForTime(chrono::seconds(6));
EXPECT_EQ(Superstructure::RUNNING, superstructure_.state());
VerifyNearGoal();
@@ -1076,7 +1082,7 @@
set_peak_intake_velocity(1.0);
set_peak_shoulder_velocity(1.0);
set_peak_wrist_velocity(10.2);
- RunForTime(Time::InSeconds(4));
+ RunForTime(chrono::seconds(4));
VerifyNearGoal();
}
@@ -1096,7 +1102,7 @@
.angle_wrist(0.0) // Stowed
.Send());
- RunForTime(Time::InSeconds(15));
+ RunForTime(chrono::seconds(15));
ASSERT_TRUE(
superstructure_queue_.goal.MakeWithBuilder()
@@ -1105,7 +1111,7 @@
.angle_wrist(M_PI / 2.0) // down
.Send());
- RunForTime(Time::InSeconds(5));
+ RunForTime(chrono::seconds(5));
superstructure_queue_.status.FetchLatest();
ASSERT_TRUE(superstructure_queue_.status.get() != nullptr);
@@ -1133,7 +1139,7 @@
.angle_wrist(M_PI) // forward
.Send());
- RunForTime(Time::InSeconds(5));
+ RunForTime(chrono::seconds(5));
VerifyNearGoal();
}
@@ -1150,7 +1156,7 @@
.angle_wrist(M_PI) // intentionally asking for forward
.Send());
- RunForTime(Time::InSeconds(15));
+ RunForTime(chrono::seconds(15));
superstructure_queue_.status.FetchLatest();
ASSERT_TRUE(superstructure_queue_.status.get() != nullptr);
@@ -1173,7 +1179,7 @@
.angle_wrist(0.0)
.Send());
- RunForTime(Time::InSeconds(6));
+ RunForTime(chrono::seconds(6));
VerifyNearGoal();
// Since we're explicitly checking for collisions, we don't want to fail the
@@ -1186,7 +1192,7 @@
while (!collided()) {
RunIteration(false);
}
- RunForTime(Time::InSeconds(0.5), false); // Move a bit further down.
+ RunForTime(chrono::milliseconds(500), false); // Move a bit further down.
ASSERT_TRUE(collided());
EXPECT_EQ(Superstructure::SLOW_RUNNING, superstructure_.state());
@@ -1194,7 +1200,7 @@
// Make sure that the collision avoidance will properly move the limbs out of
// the collision area.
- RunForTime(Time::InSeconds(10));
+ RunForTime(chrono::seconds(10));
ASSERT_FALSE(collided());
EXPECT_EQ(Superstructure::RUNNING, superstructure_.state());
}
@@ -1208,7 +1214,7 @@
.angle_wrist(0.0)
.Send());
- RunForTime(Time::InSeconds(6));
+ RunForTime(chrono::seconds(6));
VerifyNearGoal();
// Since we're explicitly checking for collisions, we don't want to fail the
@@ -1227,7 +1233,7 @@
// Make sure that the collision avoidance will properly move the limbs out of
// the collision area.
superstructure_plant_.set_power_error(0.0, 0.0, 0.0);
- RunForTime(Time::InSeconds(3));
+ RunForTime(chrono::seconds(3));
ASSERT_FALSE(collided());
EXPECT_EQ(Superstructure::LANDING_RUNNING, superstructure_.state());
}
@@ -1245,17 +1251,17 @@
.angle_wrist(0.0) // intentionally asking for forward
.Send());
- RunForTime(Time::InSeconds(6));
+ RunForTime(chrono::seconds(6));
VerifyNearGoal();
// If we are near the bottom of the range, we won't have enough power to
// compensate for the offset. This means that we fail if we get to the goal.
superstructure_plant_.set_power_error(
0.0, -Superstructure::kLandingShoulderDownVoltage, 0.0);
- RunForTime(Time::InSeconds(2));
+ RunForTime(chrono::seconds(2));
superstructure_plant_.set_power_error(
0.0, -2.0 * Superstructure::kLandingShoulderDownVoltage, 0.0);
- RunForTime(Time::InSeconds(2));
+ RunForTime(chrono::seconds(2));
EXPECT_LE(constants::Values::kShoulderRange.lower,
superstructure_queue_.goal->angle_shoulder);
}
@@ -1268,7 +1274,7 @@
.angle_shoulder(M_PI * 0.25)
.angle_wrist(0.0)
.Send());
- RunForTime(Time::InSeconds(8));
+ RunForTime(chrono::seconds(8));
// Tell it to land in the bellypan as fast as possible.
ASSERT_TRUE(superstructure_queue_.goal.MakeWithBuilder()
@@ -1291,7 +1297,7 @@
Superstructure::kShoulderTransitionToLanded);
set_peak_shoulder_velocity(0.55);
- RunForTime(Time::InSeconds(4));
+ RunForTime(chrono::seconds(4));
}
// Make sure that we quickly take off from a land.
@@ -1302,7 +1308,7 @@
.angle_shoulder(0.0)
.angle_wrist(0.0)
.Send());
- RunForTime(Time::InSeconds(8));
+ RunForTime(chrono::seconds(8));
// Tell it to take off as fast as possible.
ASSERT_TRUE(superstructure_queue_.goal.MakeWithBuilder()
diff --git a/y2016/dashboard/dashboard.cc b/y2016/dashboard/dashboard.cc
index 16ad077..798c08b 100644
--- a/y2016/dashboard/dashboard.cc
+++ b/y2016/dashboard/dashboard.cc
@@ -1,11 +1,12 @@
#include "y2016/dashboard/dashboard.h"
+#include <chrono>
+#include <complex>
#include <iostream>
#include <sstream>
#include <string>
#include <thread>
#include <vector>
-#include <complex>
#include "seasocks/Server.h"
@@ -22,6 +23,8 @@
#include "y2016/dashboard/embedded.h"
+namespace chrono = ::std::chrono;
+
namespace y2016 {
namespace dashboard {
namespace big_indicator {
@@ -139,7 +142,7 @@
size_t index = GetIndex(sample_id_);
- ItemDatapoint datapoint{value, ::aos::time::Time::Now()};
+ ItemDatapoint datapoint{value, ::aos::monotonic_clock::now()};
if (measure_index_ >= sample_items_.size()) {
// New item in our data table.
::std::vector<ItemDatapoint> datapoints;
@@ -194,9 +197,12 @@
if (static_cast<size_t>(adjusted_index) <
sample_items_.at(0).datapoints.size()) {
message << cur_sample << "%"
- << sample_items_.at(0)
- .datapoints.at(adjusted_index)
- .time.ToSeconds() << "%"; // Send time.
+ << chrono::duration_cast<chrono::duration<double>>(
+ sample_items_.at(0)
+ .datapoints.at(adjusted_index)
+ .time.time_since_epoch())
+ .count()
+ << "%"; // Send time.
// Add comma-separated list of data points.
for (size_t cur_measure = 0; cur_measure < sample_items_.size();
cur_measure++) {
@@ -220,8 +226,10 @@
void DataCollector::operator()() {
::aos::SetCurrentThreadName("DashboardData");
+ ::aos::time::PhasedLoop phased_loop(chrono::milliseconds(100),
+ chrono::seconds(0));
while (run_) {
- ::aos::time::PhasedLoopXMS(100, 0);
+ phased_loop.SleepUntilNext();
RunIteration();
}
}
diff --git a/y2016/dashboard/dashboard.h b/y2016/dashboard/dashboard.h
index 003820c..e093cb9 100644
--- a/y2016/dashboard/dashboard.h
+++ b/y2016/dashboard/dashboard.h
@@ -52,7 +52,7 @@
struct ItemDatapoint {
double value;
- ::aos::time::Time time;
+ ::aos::monotonic_clock::time_point time;
};
struct SampleItem {
diff --git a/y2016/vision/target_receiver.cc b/y2016/vision/target_receiver.cc
index 802c6e7..7ade8e7 100644
--- a/y2016/vision/target_receiver.cc
+++ b/y2016/vision/target_receiver.cc
@@ -201,8 +201,7 @@
status.FetchAnother();
::aos::MutexLocker locker(&lock_);
- data_[data_index_].time = monotonic_clock::time_point(
- chrono::nanoseconds(status->sent_time.ToNSec()));
+ data_[data_index_].time = status->sent_time;
data_[data_index_].left = status->estimated_left_position;
data_[data_index_].right = status->estimated_right_position;
++data_index_;
diff --git a/y2016/vision/vision.q b/y2016/vision/vision.q
index 872c9ae..47906dc 100644
--- a/y2016/vision/vision.q
+++ b/y2016/vision/vision.q
@@ -23,7 +23,7 @@
// The angle in radians of the bottom of the target.
double angle;
- // Capture time of the angle using the clock behind Time::Now().
+ // Capture time of the angle using the clock behind monotonic_clock::now().
int64_t target_time;
// The estimated positions of both sides of the drivetrain when the frame