Converted WaitOrCancel over to the chrono library
Change-Id: I5ebf2883117045f50f0f241e7b365d3bfe8773bf
diff --git a/aos/common/actions/actor.h b/aos/common/actions/actor.h
index e591084..5d0c70d 100644
--- a/aos/common/actions/actor.h
+++ b/aos/common/actions/actor.h
@@ -58,19 +58,20 @@
// end_time is when to stop and return true. Time(0, 0) (the default) means
// never time out.
bool WaitUntil(::std::function<bool(void)> done_condition,
- const ::aos::time::Time& end_time = ::aos::time::Time(0, 0));
+ ::aos::monotonic_clock::time_point end_time =
+ ::aos::monotonic_clock::min_time);
// Waits for a certain amount of time from when this method is called.
// Returns false if the action was canceled or failed, and true if the wait
// succeeded.
- bool WaitOrCancel(const ::aos::time::Time& duration) {
+ bool WaitOrCancel(monotonic_clock::duration duration) {
return !WaitUntil([]() {
::aos::time::PhasedLoopXMS(
::std::chrono::duration_cast<::std::chrono::milliseconds>(
::aos::controls::kLoopFrequency).count(),
2500);
return false;
- }, ::aos::time::Time::Now() + duration);
+ }, ::aos::monotonic_clock::now() + duration);
}
// Returns true if the action should be canceled.
@@ -207,15 +208,15 @@
template <class T>
bool ActorBase<T>::WaitUntil(::std::function<bool(void)> done_condition,
- const ::aos::time::Time& end_time) {
+ ::aos::monotonic_clock::time_point end_time) {
while (!done_condition()) {
if (ShouldCancel() || abort_) {
// Clear abort bit as we have just aborted.
abort_ = false;
return true;
}
- if (end_time != ::aos::time::Time(0, 0) &&
- ::aos::time::Time::Now() >= end_time) {
+ if (end_time != ::aos::monotonic_clock::min_time &&
+ ::aos::monotonic_clock::now() >= end_time) {
LOG(DEBUG, "WaitUntil timed out\n");
return false;
}
diff --git a/y2015/actors/held_to_lift_actor.cc b/y2015/actors/held_to_lift_actor.cc
index ddb2e29..29d68ef 100644
--- a/y2015/actors/held_to_lift_actor.cc
+++ b/y2015/actors/held_to_lift_actor.cc
@@ -73,8 +73,8 @@
DoFridgeProfile(params.bottom_height, 0.0, kElevatorMove, kArmMove, false);
if (ShouldCancel()) return true;
- if (!WaitOrCancel(
- aos::time::Time::InSeconds(params.before_lift_settle_time))) {
+ if (!WaitOrCancel(chrono::duration_cast<::aos::monotonic_clock::duration>(
+ chrono::duration<double>(params.before_lift_settle_time)))) {
return true;
}
@@ -82,7 +82,8 @@
DoFridgeProfile(params.bottom_height, 0.0, kElevatorMove, kArmMove, true);
if (ShouldCancel()) return true;
- if (!WaitOrCancel(aos::time::Time::InSeconds(params.clamp_pause_time))) {
+ if (!WaitOrCancel(chrono::duration_cast<::aos::monotonic_clock::duration>(
+ chrono::duration<double>(params.clamp_pause_time)))) {
return true;
}
}
diff --git a/y2015/actors/horizontal_can_pickup_actor.cc b/y2015/actors/horizontal_can_pickup_actor.cc
index fb6e542..82d01a7 100644
--- a/y2015/actors/horizontal_can_pickup_actor.cc
+++ b/y2015/actors/horizontal_can_pickup_actor.cc
@@ -27,6 +27,8 @@
} // namespace
+namespace chrono = ::std::chrono;
+
HorizontalCanPickupActor::HorizontalCanPickupActor(
HorizontalCanPickupActionQueueGroup *queues)
: FridgeActorBase<HorizontalCanPickupActionQueueGroup>(queues) {}
@@ -86,7 +88,8 @@
MoveArm(control_loops::claw_queue.status->angle, params.spit_power);
- if (!WaitOrCancel(aos::time::Time::InSeconds(params.spit_time))) {
+ if (!WaitOrCancel(chrono::duration_cast<::aos::monotonic_clock::duration>(
+ chrono::duration<double>(params.spit_time)))) {
return true;
}
@@ -98,7 +101,8 @@
MoveArm(params.pickup_angle, params.suck_power);
- if (!WaitOrCancel(aos::time::Time::InSeconds(params.suck_time))) {
+ if (!WaitOrCancel(chrono::duration_cast<::aos::monotonic_clock::duration>(
+ chrono::duration<double>(params.suck_time)))) {
return true;
}
@@ -110,7 +114,8 @@
MoveArm(0.0, params.claw_settle_power);
- if (!WaitOrCancel(aos::time::Time::InSeconds(params.claw_settle_time))) {
+ if (!WaitOrCancel(chrono::duration_cast<::aos::monotonic_clock::duration>(
+ chrono::duration<double>(params.claw_settle_time)))) {
return true;
}
diff --git a/y2015/actors/score_actor.cc b/y2015/actors/score_actor.cc
index 50b5f35..45c0bc4 100644
--- a/y2015/actors/score_actor.cc
+++ b/y2015/actors/score_actor.cc
@@ -154,7 +154,7 @@
LOG(ERROR, "Sending fridge message failed.\n");
return false;
}
- if (!WaitOrCancel(::aos::time::Time::InSeconds(0.1))) return true;
+ if (!WaitOrCancel(chrono::milliseconds(100))) return true;
// Go back to the home position.
if (!SendGoal(0.0, params.place_height, false, kReallyFastMaxXVelocity,
diff --git a/y2015/actors/stack_and_hold_actor.cc b/y2015/actors/stack_and_hold_actor.cc
index 1e87ff3..41a650c 100644
--- a/y2015/actors/stack_and_hold_actor.cc
+++ b/y2015/actors/stack_and_hold_actor.cc
@@ -90,7 +90,8 @@
}
}
- if (!WaitOrCancel(aos::time::Time::InSeconds(params.clamp_pause_time))) {
+ if (!WaitOrCancel(chrono::duration_cast<::aos::monotonic_clock::duration>(
+ chrono::duration<double>(params.clamp_pause_time)))) {
return true;
}
diff --git a/y2015/actors/stack_and_lift_actor.cc b/y2015/actors/stack_and_lift_actor.cc
index bff3c85..84b5c2c 100644
--- a/y2015/actors/stack_and_lift_actor.cc
+++ b/y2015/actors/stack_and_lift_actor.cc
@@ -67,7 +67,8 @@
}
}
- if (!WaitOrCancel(aos::time::Time::InSeconds(params.clamp_pause_time))) {
+ if (!WaitOrCancel(chrono::duration_cast<::aos::monotonic_clock::duration>(
+ chrono::duration<double>(params.clamp_pause_time)))) {
return true;
}
diff --git a/y2016/actors/superstructure_actor.cc b/y2016/actors/superstructure_actor.cc
index c2d7c4d..d621b9d 100644
--- a/y2016/actors/superstructure_actor.cc
+++ b/y2016/actors/superstructure_actor.cc
@@ -10,6 +10,8 @@
namespace y2016 {
namespace actors {
+namespace chrono = ::std::chrono;
+
SuperstructureActor::SuperstructureActor(
actors::SuperstructureActionQueueGroup *s)
: aos::common::actions::ActorBase<actors::SuperstructureActionQueueGroup>(
@@ -23,7 +25,9 @@
WaitForSuperstructure();
if (ShouldCancel()) return true;
MoveSuperstructure(params.partial_angle, params.shooter_angle, true);
- if (!WaitOrCancel(::aos::time::Time::InSeconds(params.delay_time))) return true;
+ if (!WaitOrCancel(chrono::duration_cast<::aos::monotonic_clock::duration>(
+ chrono::duration<double>(params.delay_time))))
+ return true;
MoveSuperstructure(params.full_angle, params.shooter_angle, true);
WaitForSuperstructure();
if (ShouldCancel()) return true;