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/y2016/control_loops/shooter/shooter.cc b/y2016/control_loops/shooter/shooter.cc
index 6ae7f0e..08ab1be 100644
--- a/y2016/control_loops/shooter/shooter.cc
+++ b/y2016/control_loops/shooter/shooter.cc
@@ -8,7 +8,6 @@
#include "y2016/control_loops/shooter/shooter_plant.h"
-
namespace y2016 {
namespace control_loops {
namespace shooter {
@@ -37,9 +36,7 @@
history_position_ = (history_position_ + 1) % kHistoryLength;
}
-double ShooterSide::voltage() const {
- return loop_->U(0, 0);
-}
+double ShooterSide::voltage() const { return loop_->U(0, 0); }
void ShooterSide::Update(bool disabled) {
loop_->mutable_R() = loop_->next_R();
@@ -60,8 +57,7 @@
// Compute the distance moved over that time period.
status->avg_angular_velocity =
(history_[oldest_history_position] - history_[history_position_]) /
- (chrono::duration_cast<chrono::duration<double>>(
- ::aos::controls::kLoopFrequency).count() *
+ (::aos::time::DurationInSeconds(::aos::controls::kLoopFrequency) *
static_cast<double>(kHistoryLength - 1));
status->angular_velocity = loop_->X_hat(1, 0);
diff --git a/y2016/control_loops/superstructure/superstructure_lib_test.cc b/y2016/control_loops/superstructure/superstructure_lib_test.cc
index d0c4362..e7983f3 100644
--- a/y2016/control_loops/superstructure/superstructure_lib_test.cc
+++ b/y2016/control_loops/superstructure/superstructure_lib_test.cc
@@ -88,11 +88,12 @@
pot_encoder_shoulder_(
constants::Values::kShoulderEncoderIndexDifference),
pot_encoder_wrist_(constants::Values::kWristEncoderIndexDifference),
- superstructure_queue_(".y2016.control_loops.superstructure_queue",
- ".y2016.control_loops.superstructure_queue.goal",
- ".y2016.control_loops.superstructure_queue.position",
- ".y2016.control_loops.superstructure_queue.output",
- ".y2016.control_loops.superstructure_queue.status") {
+ superstructure_queue_(
+ ".y2016.control_loops.superstructure_queue",
+ ".y2016.control_loops.superstructure_queue.goal",
+ ".y2016.control_loops.superstructure_queue.position",
+ ".y2016.control_loops.superstructure_queue.output",
+ ".y2016.control_loops.superstructure_queue.status") {
InitializeIntakePosition(0.0);
InitializeShoulderPosition(0.0);
InitializeRelativeWristPosition(0.0);
@@ -246,11 +247,12 @@
class SuperstructureTest : public ::aos::testing::ControlLoopTest {
protected:
SuperstructureTest()
- : superstructure_queue_(".y2016.control_loops.superstructure_queue",
- ".y2016.control_loops.superstructure_queue.goal",
- ".y2016.control_loops.superstructure_queue.position",
- ".y2016.control_loops.superstructure_queue.output",
- ".y2016.control_loops.superstructure_queue.status"),
+ : superstructure_queue_(
+ ".y2016.control_loops.superstructure_queue",
+ ".y2016.control_loops.superstructure_queue.goal",
+ ".y2016.control_loops.superstructure_queue.position",
+ ".y2016.control_loops.superstructure_queue.output",
+ ".y2016.control_loops.superstructure_queue.status"),
superstructure_(&event_loop_),
superstructure_plant_() {}
@@ -300,9 +302,8 @@
double begin_wrist_velocity =
superstructure_plant_.wrist_angular_velocity();
RunIteration(enabled);
- const double loop_time =
- chrono::duration_cast<chrono::duration<double>>(
- monotonic_clock::now() - loop_start_time).count();
+ const double loop_time = ::aos::time::DurationInSeconds(
+ monotonic_clock::now() - loop_start_time);
const double shoulder_acceleration =
(superstructure_plant_.shoulder_angular_velocity() -
begin_shoulder_velocity) /
@@ -921,8 +922,8 @@
superstructure_queue_.goal.MakeWithBuilder()
.angle_intake(0.0)
.angle_shoulder(
- CollisionAvoidance::kMinShoulderAngleForIntakeUpInterference +
- 0.1)
+ CollisionAvoidance::kMinShoulderAngleForIntakeUpInterference +
+ 0.1)
.angle_wrist(0.0)
.max_angular_velocity_intake(20)
.max_angular_acceleration_intake(20)
@@ -941,8 +942,8 @@
superstructure_queue_.goal.MakeWithBuilder()
.angle_intake(0.0)
.angle_shoulder(
- CollisionAvoidance::kMinShoulderAngleForIntakeUpInterference +
- 0.1)
+ CollisionAvoidance::kMinShoulderAngleForIntakeUpInterference +
+ 0.1)
.angle_wrist(0.5)
.max_angular_velocity_intake(1)
.max_angular_acceleration_intake(1)
@@ -967,7 +968,7 @@
superstructure_queue_.goal.MakeWithBuilder()
.angle_intake(0.0)
.angle_shoulder(
- CollisionAvoidance::kMinShoulderAngleForIntakeUpInterference)
+ CollisionAvoidance::kMinShoulderAngleForIntakeUpInterference)
.angle_wrist(0.0)
.max_angular_velocity_intake(20)
.max_angular_acceleration_intake(20)
@@ -986,7 +987,7 @@
superstructure_queue_.goal.MakeWithBuilder()
.angle_intake(0.5)
.angle_shoulder(
- CollisionAvoidance::kMinShoulderAngleForIntakeUpInterference)
+ CollisionAvoidance::kMinShoulderAngleForIntakeUpInterference)
.angle_wrist(0.0)
.max_angular_velocity_intake(4.5)
.max_angular_acceleration_intake(800)
@@ -1051,8 +1052,8 @@
superstructure_queue_.goal.MakeWithBuilder()
.angle_intake(0.0)
.angle_shoulder(
- CollisionAvoidance::kMinShoulderAngleForIntakeUpInterference +
- 0.1)
+ CollisionAvoidance::kMinShoulderAngleForIntakeUpInterference +
+ 0.1)
.angle_wrist(0.0)
.max_angular_velocity_intake(20)
.max_angular_acceleration_intake(20)
@@ -1071,8 +1072,8 @@
superstructure_queue_.goal.MakeWithBuilder()
.angle_intake(0.0)
.angle_shoulder(
- CollisionAvoidance::kMinShoulderAngleForIntakeUpInterference +
- 0.1)
+ CollisionAvoidance::kMinShoulderAngleForIntakeUpInterference +
+ 0.1)
.angle_wrist(1.3)
.max_angular_velocity_intake(1.0)
.max_angular_acceleration_intake(1.0)
@@ -1139,7 +1140,7 @@
superstructure_queue_.goal.MakeWithBuilder()
.angle_intake(constants::Values::kIntakeRange.upper) // stowed
.angle_shoulder(M_PI / 2.0) // in the collision area
- .angle_wrist(M_PI) // forward
+ .angle_wrist(M_PI) // forward
.Send());
RunForTime(chrono::seconds(5));
@@ -1341,4 +1342,4 @@
} // namespace testing
} // namespace superstructure
} // namespace control_loops
-} // namespace frc971
+} // namespace y2016