Make a DurationInSeconds function
Also, run clang-format on all the files I changed because I am too lazy
to figure out how to call clang-format on just the lines I changed.
Change-Id: I071c6f81dced533a0a269f25a258348132a7056a
diff --git a/y2014/autonomous/auto.cc b/y2014/autonomous/auto.cc
index ef59ba4..18e490e 100644
--- a/y2014/autonomous/auto.cc
+++ b/y2014/autonomous/auto.cc
@@ -3,12 +3,12 @@
#include <chrono>
#include <memory>
-#include "aos/util/phased_loop.h"
-#include "aos/time/time.h"
-#include "aos/util/trapezoid_profile.h"
+#include "aos/actions/actions.h"
#include "aos/logging/logging.h"
#include "aos/logging/queue_logging.h"
-#include "aos/actions/actions.h"
+#include "aos/time/time.h"
+#include "aos/util/phased_loop.h"
+#include "aos/util/trapezoid_profile.h"
#include "frc971/autonomous/auto.q.h"
#include "frc971/control_loops/drivetrain/drivetrain.q.h"
@@ -29,15 +29,6 @@
namespace this_thread = ::std::this_thread;
using ::aos::monotonic_clock;
-namespace {
-
-double DoubleSeconds(monotonic_clock::duration duration) {
- return ::std::chrono::duration_cast<::std::chrono::duration<double>>(duration)
- .count();
-}
-
-} // namespace
-
static double left_initial_position, right_initial_position;
bool ShouldExitAuto() {
@@ -104,7 +95,8 @@
right_initial_position = right_goal;
}
-void PositionClawVertically(double intake_power = 0.0, double centering_power = 0.0) {
+void PositionClawVertically(double intake_power = 0.0,
+ double centering_power = 0.0) {
if (!control_loops::claw_queue.goal.MakeWithBuilder()
.bottom_angle(0.0)
.separation_angle(0.0)
@@ -166,12 +158,12 @@
while (true) {
if (ShouldExitAuto()) return;
::frc971::control_loops::drivetrain_queue.status.FetchAnother();
- double left_error = ::std::abs(
- left_initial_position -
- ::frc971::control_loops::drivetrain_queue.status->estimated_left_position);
- double right_error = ::std::abs(
- right_initial_position -
- ::frc971::control_loops::drivetrain_queue.status->estimated_right_position);
+ double left_error = ::std::abs(left_initial_position -
+ ::frc971::control_loops::drivetrain_queue
+ .status->estimated_left_position);
+ double right_error = ::std::abs(right_initial_position -
+ ::frc971::control_loops::drivetrain_queue
+ .status->estimated_right_position);
const double kPositionThreshold = 0.05 + distance;
if (right_error < kPositionThreshold && left_error < kPositionThreshold) {
LOG(INFO, "At the goal\n");
@@ -220,8 +212,8 @@
::frc971::control_loops::drivetrain_queue.status.FetchAnother();
left_initial_position =
::frc971::control_loops::drivetrain_queue.status->estimated_left_position;
- right_initial_position =
- ::frc971::control_loops::drivetrain_queue.status->estimated_right_position;
+ right_initial_position = ::frc971::control_loops::drivetrain_queue.status
+ ->estimated_right_position;
}
void WaitUntilClawDone() {
@@ -241,14 +233,11 @@
}
bool ans =
control_loops::claw_queue.status->zeroed &&
- (::std::abs(control_loops::claw_queue.status->bottom_velocity) <
- 1.0) &&
+ (::std::abs(control_loops::claw_queue.status->bottom_velocity) < 1.0) &&
(::std::abs(control_loops::claw_queue.status->bottom -
- control_loops::claw_queue.goal->bottom_angle) <
- 0.10) &&
+ control_loops::claw_queue.goal->bottom_angle) < 0.10) &&
(::std::abs(control_loops::claw_queue.status->separation -
- control_loops::claw_queue.goal->separation_angle) <
- 0.4);
+ control_loops::claw_queue.goal->separation_angle) < 0.4);
if (ans) {
return;
}
@@ -258,9 +247,7 @@
class HotGoalDecoder {
public:
- HotGoalDecoder() {
- ResetCounts();
- }
+ HotGoalDecoder() { ResetCounts(); }
void ResetCounts() {
hot_goal.FetchLatest();
@@ -393,7 +380,7 @@
// Turn the claw on, keep it straight up until the ball has been grabbed.
LOG(INFO, "Claw going up at %f\n",
- DoubleSeconds(monotonic_clock::now() - start_time));
+ ::aos::time::DurationInSeconds(monotonic_clock::now() - start_time));
PositionClawVertically(12.0, 4.0);
SetShotPower(115.0);
@@ -401,7 +388,7 @@
this_thread::sleep_for(chrono::milliseconds(250));
if (ShouldExitAuto()) return;
LOG(INFO, "Readying claw for shot at %f\n",
- DoubleSeconds(monotonic_clock::now() - start_time));
+ ::aos::time::DurationInSeconds(monotonic_clock::now() - start_time));
{
if (ShouldExitAuto()) return;
@@ -448,7 +435,7 @@
// Shoot.
LOG(INFO, "Shooting at %f\n",
- DoubleSeconds(monotonic_clock::now() - start_time));
+ ::aos::time::DurationInSeconds(monotonic_clock::now() - start_time));
Shoot();
this_thread::sleep_for(chrono::milliseconds(50));
@@ -460,7 +447,7 @@
if (ShouldExitAuto()) return;
} else if (auto_version == AutoVersion::kSingleHot) {
LOG(INFO, "auto done at %f\n",
- DoubleSeconds(monotonic_clock::now() - start_time));
+ ::aos::time::DurationInSeconds(monotonic_clock::now() - start_time));
PositionClawVertically(0.0, 0.0);
return;
}
@@ -469,7 +456,7 @@
if (ShouldExitAuto()) return;
// Intake the new ball.
LOG(INFO, "Claw ready for intake at %f\n",
- DoubleSeconds(monotonic_clock::now() - start_time));
+ ::aos::time::DurationInSeconds(monotonic_clock::now() - start_time));
PositionClawBackIntake();
auto drivetrain_action =
SetDriveGoal(kShootDistance + kPickupDistance, drive_params);
@@ -477,7 +464,7 @@
WaitUntilDoneOrCanceled(::std::move(drivetrain_action));
if (ShouldExitAuto()) return;
LOG(INFO, "Wait for the claw at %f\n",
- DoubleSeconds(monotonic_clock::now() - start_time));
+ ::aos::time::DurationInSeconds(monotonic_clock::now() - start_time));
WaitUntilClawDone();
if (ShouldExitAuto()) return;
}
@@ -485,7 +472,7 @@
// Drive back.
{
LOG(INFO, "Driving back at %f\n",
- DoubleSeconds(monotonic_clock::now() - start_time));
+ ::aos::time::DurationInSeconds(monotonic_clock::now() - start_time));
auto drivetrain_action =
SetDriveGoal(-(kShootDistance + kPickupDistance), drive_params);
this_thread::sleep_for(chrono::milliseconds(300));
@@ -525,7 +512,7 @@
}
LOG(INFO, "Shooting at %f\n",
- DoubleSeconds(monotonic_clock::now() - start_time));
+ ::aos::time::DurationInSeconds(monotonic_clock::now() - start_time));
// Shoot
Shoot();
if (ShouldExitAuto()) return;
diff --git a/y2014/autonomous/auto_main.cc b/y2014/autonomous/auto_main.cc
index d38e1e6..f125cc2 100644
--- a/y2014/autonomous/auto_main.cc
+++ b/y2014/autonomous/auto_main.cc
@@ -1,12 +1,12 @@
#include <stdio.h>
-#include "aos/time/time.h"
#include "aos/init.h"
#include "aos/logging/logging.h"
+#include "aos/time/time.h"
#include "frc971/autonomous/auto.q.h"
#include "y2014/autonomous/auto.h"
-int main(int /*argc*/, char * /*argv*/[]) {
+int main(int /*argc*/, char * /*argv*/ []) {
::aos::Init(-1);
LOG(INFO, "Auto main started\n");
@@ -28,9 +28,7 @@
auto elapsed_time = ::aos::monotonic_clock::now() - start_time;
LOG(INFO, "Auto mode exited in %f, waiting for it to finish.\n",
- ::std::chrono::duration_cast<::std::chrono::duration<double>>(
- elapsed_time)
- .count());
+ ::aos::time::DurationInSeconds(elapsed_time));
while (::frc971::autonomous::autonomous->run_auto) {
::frc971::autonomous::autonomous.FetchNextBlocking();
LOG(INFO, "Got another auto packet\n");
@@ -40,4 +38,3 @@
::aos::Cleanup();
return 0;
}
-