Create a nice general SimpleCappedStateFeedbackLoop

Change-Id: I79e686b1c6d689735b73634ccf9877e00bac4348
diff --git a/y2016/control_loops/superstructure/BUILD b/y2016/control_loops/superstructure/BUILD
index c584135..17653ad 100644
--- a/y2016/control_loops/superstructure/BUILD
+++ b/y2016/control_loops/superstructure/BUILD
@@ -78,6 +78,7 @@
     '//aos/common/controls:control_loop',
     '//aos/common/util:trapezoid_profile',
     '//frc971/control_loops:state_feedback_loop',
+    '//frc971/control_loops:simple_capped_state_feedback_loop',
     '//frc971/zeroing',
     '//y2016:constants',
   ],
diff --git a/y2016/control_loops/superstructure/superstructure_controls.cc b/y2016/control_loops/superstructure/superstructure_controls.cc
index 7cd67e3..3c3e690 100644
--- a/y2016/control_loops/superstructure/superstructure_controls.cc
+++ b/y2016/control_loops/superstructure/superstructure_controls.cc
@@ -25,22 +25,10 @@
 }
 }  // namespace
 
-void SimpleCappedStateFeedbackLoop::CapU() {
-  mutable_U(0, 0) = ::std::min(U(0, 0), max_voltage_);
-  mutable_U(0, 0) = ::std::max(U(0, 0), -max_voltage_);
-}
-
-void DoubleCappedStateFeedbackLoop::CapU() {
-  mutable_U(0, 0) = ::std::min(U(0, 0), shoulder_max_voltage_);
-  mutable_U(0, 0) = ::std::max(U(0, 0), -shoulder_max_voltage_);
-  mutable_U(1, 0) = ::std::min(U(1, 0), wrist_max_voltage_);
-  mutable_U(1, 0) = ::std::max(U(1, 0), -wrist_max_voltage_);
-}
-
 // Intake
 Intake::Intake()
-    : loop_(new SimpleCappedStateFeedbackLoop(StateFeedbackLoop<3, 1, 1>(
-          ::y2016::control_loops::superstructure::MakeIntegralIntakeLoop()))),
+    : loop_(new ::frc971::control_loops::SimpleCappedStateFeedbackLoop<3, 1, 1>(
+          ::y2016::control_loops::superstructure::MakeIntegralIntakeLoop())),
       estimator_(constants::GetValues().intake.zeroing),
       profile_(::aos::controls::kLoopFrequency) {
   Y_.setZero();
@@ -147,7 +135,7 @@
 }
 
 void Intake::set_max_voltage(double voltage) {
-  loop_->set_max_voltage(voltage);
+  loop_->set_max_voltages(voltage);
 }
 
 void Intake::AdjustProfile(double max_angular_velocity,
@@ -171,7 +159,7 @@
 }
 
 Arm::Arm()
-    : loop_(new DoubleCappedStateFeedbackLoop(
+    : loop_(new ::frc971::control_loops::SimpleCappedStateFeedbackLoop<6, 2, 2>(
           ::y2016::control_loops::superstructure::MakeIntegralArmLoop())),
       shoulder_profile_(::aos::controls::kLoopFrequency),
       wrist_profile_(::aos::controls::kLoopFrequency),
@@ -368,7 +356,7 @@
 
 void Arm::set_max_voltage(double shoulder_max_voltage,
                           double wrist_max_voltage) {
-  loop_->set_max_voltage(shoulder_max_voltage, wrist_max_voltage);
+  loop_->set_max_voltages(shoulder_max_voltage, wrist_max_voltage);
 }
 
 void Arm::Reset() {
diff --git a/y2016/control_loops/superstructure/superstructure_controls.h b/y2016/control_loops/superstructure/superstructure_controls.h
index d96e24d..f3d8752 100644
--- a/y2016/control_loops/superstructure/superstructure_controls.h
+++ b/y2016/control_loops/superstructure/superstructure_controls.h
@@ -5,6 +5,7 @@
 
 #include "aos/common/controls/control_loop.h"
 #include "frc971/control_loops/state_feedback_loop.h"
+#include "frc971/control_loops/simple_capped_state_feedback_loop.h"
 #include "aos/common/util/trapezoid_profile.h"
 
 #include "frc971/zeroing/zeroing.h"
@@ -17,41 +18,6 @@
 class SuperstructureTest_DisabledGoalTest_Test;
 }  // namespace testing
 
-class SimpleCappedStateFeedbackLoop : public StateFeedbackLoop<3, 1, 1> {
- public:
-  SimpleCappedStateFeedbackLoop(StateFeedbackLoop<3, 1, 1> &&loop)
-      : StateFeedbackLoop<3, 1, 1>(::std::move(loop)), max_voltage_(12.0) {}
-
-  void set_max_voltage(double max_voltage) {
-    max_voltage_ = ::std::max(0.0, ::std::min(12.0, max_voltage));
-  }
-
-  void CapU() override;
-
- private:
-  double max_voltage_;
-};
-
-class DoubleCappedStateFeedbackLoop : public StateFeedbackLoop<6, 2, 2> {
- public:
-  DoubleCappedStateFeedbackLoop(StateFeedbackLoop<6, 2, 2> &&loop)
-      : StateFeedbackLoop<6, 2, 2>(::std::move(loop)),
-        shoulder_max_voltage_(12.0),
-        wrist_max_voltage_(12.0) {}
-
-  void set_max_voltage(double shoulder_max_voltage, double wrist_max_voltage) {
-    shoulder_max_voltage_ =
-        ::std::max(0.0, ::std::min(12.0, shoulder_max_voltage));
-    wrist_max_voltage_ = ::std::max(0.0, ::std::min(12.0, wrist_max_voltage));
-  }
-
-  void CapU() override;
-
- private:
-  double shoulder_max_voltage_;
-  double wrist_max_voltage_;
-};
-
 class Intake {
  public:
   Intake();
@@ -114,7 +80,8 @@
 
   void UpdateIntakeOffset(double offset);
 
-  ::std::unique_ptr<SimpleCappedStateFeedbackLoop> loop_;
+  ::std::unique_ptr<
+      ::frc971::control_loops::SimpleCappedStateFeedbackLoop<3, 1, 1>> loop_;
 
   ::frc971::zeroing::ZeroingEstimator estimator_;
   aos::util::TrapezoidProfile profile_;
@@ -204,7 +171,8 @@
   void UpdateShoulderOffset(double offset);
 
   friend class testing::SuperstructureTest_DisabledGoalTest_Test;
-  ::std::unique_ptr<DoubleCappedStateFeedbackLoop> loop_;
+  ::std::unique_ptr<
+      ::frc971::control_loops::SimpleCappedStateFeedbackLoop<6, 2, 2>> loop_;
 
   aos::util::TrapezoidProfile shoulder_profile_, wrist_profile_;
   ::frc971::zeroing::ZeroingEstimator shoulder_estimator_, wrist_estimator_;