Move aos/controls to frc971/control_loops

Also put what was aos/controls/control_loops.fbs in y2012/control_loops
because that's the only user.

Change-Id: I8f402b0708103077e135a41e55ef5e4f23681d87
Signed-off-by: James Kuszmaul <jabukuszmaul@gmail.com>
diff --git a/y2017/control_loops/superstructure/BUILD b/y2017/control_loops/superstructure/BUILD
index fa835c1..a7c75ac 100644
--- a/y2017/control_loops/superstructure/BUILD
+++ b/y2017/control_loops/superstructure/BUILD
@@ -63,7 +63,7 @@
         ":superstructure_position_fbs",
         ":superstructure_status_fbs",
         ":vision_distance_average",
-        "//aos/controls:control_loop",
+        "//frc971/control_loops:control_loop",
         "//aos/events:event_loop",
         "//y2017:constants",
         "//y2017/control_loops/superstructure/column",
@@ -87,7 +87,7 @@
         ":superstructure_position_fbs",
         ":superstructure_status_fbs",
         "//aos:math",
-        "//aos/controls:control_loop_test",
+        "//frc971/control_loops:control_loop_test",
         "//aos/testing:googletest",
         "//aos/time",
         "//frc971/control_loops:position_sensor_sim",
diff --git a/y2017/control_loops/superstructure/column/BUILD b/y2017/control_loops/superstructure/column/BUILD
index 498579e..2d83482 100644
--- a/y2017/control_loops/superstructure/column/BUILD
+++ b/y2017/control_loops/superstructure/column/BUILD
@@ -48,7 +48,7 @@
         ":column_plants",
         ":column_zeroing",
         "//aos:math",
-        "//aos/controls:control_loop",
+        "//frc971/control_loops:control_loop",
         "//frc971/control_loops:profiled_subsystem",
         "//y2017:constants",
         "//y2017/control_loops/superstructure:superstructure_position_fbs",
diff --git a/y2017/control_loops/superstructure/column/column.cc b/y2017/control_loops/superstructure/column/column.cc
index f1aea39..d5e2611 100644
--- a/y2017/control_loops/superstructure/column/column.cc
+++ b/y2017/control_loops/superstructure/column/column.cc
@@ -6,7 +6,6 @@
 #include <utility>
 
 #include "Eigen/Dense"
-
 #include "aos/commonmath.h"
 #include "frc971/constants.h"
 #include "frc971/control_loops/profiled_subsystem.h"
@@ -48,7 +47,7 @@
           ::std::move(loop), {{zeroing_constants}}),
       stuck_indexer_detector_(new StateFeedbackLoop<6, 2, 2>(
           column::MakeStuckIntegralColumnLoop())),
-      profile_(::aos::controls::kLoopFrequency),
+      profile_(::frc971::controls::kLoopFrequency),
       range_(range),
       default_velocity_(default_velocity),
       default_acceleration_(default_acceleration) {
@@ -128,7 +127,7 @@
 
   indexer_dt_velocity_ =
       (new_position.indexer()->encoder() - indexer_last_position_) /
-      ::aos::time::DurationInSeconds(::aos::controls::kLoopFrequency);
+      ::aos::time::DurationInSeconds(::frc971::controls::kLoopFrequency);
   indexer_last_position_ = new_position.indexer()->encoder();
 
   stuck_indexer_detector_->Correct(Y_);
@@ -143,7 +142,7 @@
   indexer_average_angular_velocity_ =
       (indexer_history_[indexer_oldest_history_position] -
        indexer_history_[indexer_history_position_]) /
-      (::aos::time::DurationInSeconds(::aos::controls::kLoopFrequency) *
+      (::aos::time::DurationInSeconds(::frc971::controls::kLoopFrequency) *
        static_cast<double>(kHistoryLength - 1));
 
   // Ready if average angular velocity is close to the goal.
@@ -253,7 +252,7 @@
         profile_.Update(unprofiled_goal_(2, 0), unprofiled_goal_(3, 0));
 
     constexpr double kDt =
-        ::aos::time::DurationInSeconds(::aos::controls::kLoopFrequency);
+        ::aos::time::DurationInSeconds(::frc971::controls::kLoopFrequency);
 
     loop_->mutable_next_R(0, 0) = 0.0;
     // TODO(austin): This might not handle saturation right, but I'm not sure I
@@ -287,7 +286,7 @@
 
   // Run the KF predict step.
   stuck_indexer_detector_->UpdateObserver(loop_->U(),
-                                          ::aos::controls::kLoopFrequency);
+                                          ::frc971::controls::kLoopFrequency);
 }
 
 bool ColumnProfiledSubsystem::CheckHardLimits() {
@@ -382,7 +381,7 @@
   status_builder->add_voltage_error(X_hat(5, 0));
   status_builder->add_calculated_velocity(
       (turret_position() - turret_last_position_) /
-      ::aos::time::DurationInSeconds(::aos::controls::kLoopFrequency));
+      ::aos::time::DurationInSeconds(::frc971::controls::kLoopFrequency));
 
   status_builder->add_estimator_state(estimator_state_offset);
 
@@ -558,8 +557,7 @@
       if (unsafe_turret_goal && unsafe_indexer_goal) {
         profiled_subsystem_.AdjustProfile(unsafe_turret_goal->profile_params());
         profiled_subsystem_.set_unprofiled_goal(
-            unsafe_indexer_goal->angular_velocity,
-            unsafe_turret_goal->angle());
+            unsafe_indexer_goal->angular_velocity, unsafe_turret_goal->angle());
 
         if (unsafe_turret_goal->track()) {
           if (vision_time_adjuster_.valid()) {
diff --git a/y2017/control_loops/superstructure/shooter/BUILD b/y2017/control_loops/superstructure/shooter/BUILD
index 49fa341..cb351c9 100644
--- a/y2017/control_loops/superstructure/shooter/BUILD
+++ b/y2017/control_loops/superstructure/shooter/BUILD
@@ -45,7 +45,7 @@
     visibility = ["//visibility:public"],
     deps = [
         ":shooter_plants",
-        "//aos/controls:control_loop",
+        "//frc971/control_loops:control_loop",
         "//frc971/control_loops:control_loops_fbs",
         "//frc971/control_loops:profiled_subsystem_fbs",
         "//y2017/control_loops/superstructure:superstructure_goal_fbs",
diff --git a/y2017/control_loops/superstructure/shooter/shooter.cc b/y2017/control_loops/superstructure/shooter/shooter.cc
index 0ea4836..8a2dcb9 100644
--- a/y2017/control_loops/superstructure/shooter/shooter.cc
+++ b/y2017/control_loops/superstructure/shooter/shooter.cc
@@ -130,7 +130,7 @@
 
   wheel_.set_position(position);
 
-  chrono::nanoseconds dt = ::aos::controls::kLoopFrequency;
+  chrono::nanoseconds dt = ::frc971::controls::kLoopFrequency;
   if (last_time_ != ::aos::monotonic_clock::min_time) {
     dt = position_time - last_time_;
   }
diff --git a/y2017/control_loops/superstructure/shooter/shooter.h b/y2017/control_loops/superstructure/shooter/shooter.h
index 19fc7dd..afb627d 100644
--- a/y2017/control_loops/superstructure/shooter/shooter.h
+++ b/y2017/control_loops/superstructure/shooter/shooter.h
@@ -4,7 +4,7 @@
 #include <array>
 #include <memory>
 
-#include "aos/controls/control_loop.h"
+#include "frc971/control_loops/control_loop.h"
 #include "aos/time/time.h"
 #include "frc971/control_loops/state_feedback_loop.h"
 #include "Eigen/Dense"
diff --git a/y2017/control_loops/superstructure/superstructure.cc b/y2017/control_loops/superstructure/superstructure.cc
index a0448fd..c707653 100644
--- a/y2017/control_loops/superstructure/superstructure.cc
+++ b/y2017/control_loops/superstructure/superstructure.cc
@@ -23,8 +23,8 @@
 
 Superstructure::Superstructure(::aos::EventLoop *event_loop,
                                const ::std::string &name)
-    : aos::controls::ControlLoop<Goal, Position, Status, Output>(event_loop,
-                                                                 name),
+    : frc971::controls::ControlLoop<Goal, Position, Status, Output>(event_loop,
+                                                                    name),
       vision_status_fetcher_(
           event_loop->MakeFetcher<::y2017::vision::VisionStatus>("/vision")),
       drivetrain_status_fetcher_(
@@ -48,11 +48,10 @@
       });
 }
 
-void Superstructure::RunIteration(
-    const Goal *unsafe_goal,
-    const Position *position,
-    aos::Sender<Output>::Builder *output,
-    aos::Sender<Status>::Builder *status) {
+void Superstructure::RunIteration(const Goal *unsafe_goal,
+                                  const Position *position,
+                                  aos::Sender<Output>::Builder *output,
+                                  aos::Sender<Status>::Builder *status) {
   OutputT output_struct;
   const ::aos::monotonic_clock::time_point monotonic_now =
       event_loop()->monotonic_now();
@@ -104,8 +103,8 @@
     if (distance_average_.Valid()) {
       if (unsafe_goal->use_vision_for_shots()) {
         ShotParams shot_params;
-        if (shot_interpolation_table_.GetInRange(
-                distance_average_.Get(), &shot_params)) {
+        if (shot_interpolation_table_.GetInRange(distance_average_.Get(),
+                                                 &shot_params)) {
           hood_goal_angle = shot_params.angle;
           shooter_goal.angular_velocity = shot_params.power;
           if (indexer_goal.angular_velocity != 0.0) {
@@ -115,10 +114,10 @@
           in_range = false;
         }
       }
-      AOS_LOG(
-          DEBUG, "VisionDistance %f, hood %f shooter %f, indexer %f * M_PI\n",
-          vision_distance, hood_goal_angle,
-          shooter_goal.angular_velocity, indexer_goal.angular_velocity / M_PI);
+      AOS_LOG(DEBUG,
+              "VisionDistance %f, hood %f shooter %f, indexer %f * M_PI\n",
+              vision_distance, hood_goal_angle, shooter_goal.angular_velocity,
+              indexer_goal.angular_velocity / M_PI);
     } else {
       AOS_LOG(DEBUG, "VisionNotValid %f\n", vision_distance);
       if (unsafe_goal->use_vision_for_shots()) {
diff --git a/y2017/control_loops/superstructure/superstructure.h b/y2017/control_loops/superstructure/superstructure.h
index a4c824e..ae52dae 100644
--- a/y2017/control_loops/superstructure/superstructure.h
+++ b/y2017/control_loops/superstructure/superstructure.h
@@ -3,7 +3,7 @@
 
 #include <memory>
 
-#include "aos/controls/control_loop.h"
+#include "frc971/control_loops/control_loop.h"
 #include "aos/events/event_loop.h"
 #include "frc971/control_loops/state_feedback_loop.h"
 #include "y2017/control_loops/superstructure/column/column.h"
@@ -21,7 +21,7 @@
 namespace superstructure {
 
 class Superstructure
-    : public ::aos::controls::ControlLoop<Goal, Position, Status, Output> {
+    : public ::frc971::controls::ControlLoop<Goal, Position, Status, Output> {
  public:
   explicit Superstructure(::aos::EventLoop *event_loop,
                           const ::std::string &name = "/superstructure");
diff --git a/y2017/control_loops/superstructure/superstructure_lib_test.cc b/y2017/control_loops/superstructure/superstructure_lib_test.cc
index 2722024..7690937 100644
--- a/y2017/control_loops/superstructure/superstructure_lib_test.cc
+++ b/y2017/control_loops/superstructure/superstructure_lib_test.cc
@@ -1,11 +1,9 @@
-#include "y2017/control_loops/superstructure/superstructure.h"
-
 #include <unistd.h>
 
 #include <chrono>
 #include <memory>
 
-#include "aos/controls/control_loop_test.h"
+#include "frc971/control_loops/control_loop_test.h"
 #include "frc971/control_loops/position_sensor_sim.h"
 #include "frc971/control_loops/team_number_test_environment.h"
 #include "gtest/gtest.h"
@@ -14,6 +12,7 @@
 #include "y2017/control_loops/superstructure/hood/hood_plant.h"
 #include "y2017/control_loops/superstructure/intake/intake_plant.h"
 #include "y2017/control_loops/superstructure/shooter/shooter_plant.h"
+#include "y2017/control_loops/superstructure/superstructure.h"
 
 using ::frc971::control_loops::PositionSensorSimulator;
 
@@ -517,10 +516,10 @@
   double peak_hood_velocity_ = 1e10;
 };
 
-class SuperstructureTest : public ::aos::testing::ControlLoopTest {
+class SuperstructureTest : public ::frc971::testing::ControlLoopTest {
  protected:
   SuperstructureTest()
-      : ::aos::testing::ControlLoopTest(
+      : ::frc971::testing::ControlLoopTest(
             aos::configuration::ReadConfig("y2017/config.json"),
             chrono::microseconds(5050)),
         test_event_loop_(MakeEventLoop("test")),
@@ -566,20 +565,22 @@
     // Check that the angular velocity, average angular velocity, and estimated
     // angular velocity match when we are done for the shooter.
     EXPECT_NEAR(superstructure_goal_fetcher_->shooter()->angular_velocity(),
-                superstructure_status_fetcher_->shooter()->angular_velocity(), 0.1);
-    EXPECT_NEAR(superstructure_goal_fetcher_->shooter()->angular_velocity(),
-                superstructure_status_fetcher_->shooter()->avg_angular_velocity(),
+                superstructure_status_fetcher_->shooter()->angular_velocity(),
                 0.1);
+    EXPECT_NEAR(
+        superstructure_goal_fetcher_->shooter()->angular_velocity(),
+        superstructure_status_fetcher_->shooter()->avg_angular_velocity(), 0.1);
     EXPECT_NEAR(superstructure_goal_fetcher_->shooter()->angular_velocity(),
                 superstructure_plant_.shooter_velocity(), 0.1);
 
     // Check that the angular velocity, average angular velocity, and estimated
     // angular velocity match when we are done for the indexer.
     EXPECT_NEAR(superstructure_goal_fetcher_->indexer()->angular_velocity(),
-                superstructure_status_fetcher_->indexer()->angular_velocity(), 0.1);
-    EXPECT_NEAR(superstructure_goal_fetcher_->indexer()->angular_velocity(),
-                superstructure_status_fetcher_->indexer()->avg_angular_velocity(),
+                superstructure_status_fetcher_->indexer()->angular_velocity(),
                 0.1);
+    EXPECT_NEAR(
+        superstructure_goal_fetcher_->indexer()->angular_velocity(),
+        superstructure_status_fetcher_->indexer()->avg_angular_velocity(), 0.1);
     EXPECT_NEAR(superstructure_goal_fetcher_->indexer()->angular_velocity(),
                 superstructure_plant_.indexer_velocity(), 0.1);
   }