Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 1 | #ifndef FRC971_CONTROL_LOOPS_STATE_FEEDBACK_LOOP_H_ |
| 2 | #define FRC971_CONTROL_LOOPS_STATE_FEEDBACK_LOOP_H_ |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 3 | |
Austin Schuh | 849f003 | 2013-03-03 23:59:53 -0800 | [diff] [blame] | 4 | #include <assert.h> |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 5 | |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 6 | #include <iostream> |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 7 | #include <memory> |
| 8 | #include <utility> |
| 9 | #include <vector> |
Austin Schuh | 3ad5ed8 | 2017-02-25 21:36:19 -0800 | [diff] [blame] | 10 | #include <chrono> |
Brian Silverman | c571e05 | 2013-03-13 17:58:56 -0700 | [diff] [blame] | 11 | |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 12 | #include "Eigen/Dense" |
Austin Schuh | 3ad5ed8 | 2017-02-25 21:36:19 -0800 | [diff] [blame] | 13 | #include "unsupported/Eigen/MatrixFunctions" |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 14 | |
Austin Schuh | 3ad5ed8 | 2017-02-25 21:36:19 -0800 | [diff] [blame] | 15 | #include "aos/common/controls/control_loop.h" |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 16 | #include "aos/common/logging/logging.h" |
Brian Silverman | 0a151c9 | 2014-05-02 15:28:44 -0700 | [diff] [blame] | 17 | #include "aos/common/macros.h" |
| 18 | |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 19 | template <int number_of_states, int number_of_inputs, int number_of_outputs, |
| 20 | typename PlantType, typename ObserverType> |
| 21 | class StateFeedbackLoop; |
| 22 | |
Brian Silverman | 5808bcb | 2014-09-14 21:40:43 -0400 | [diff] [blame] | 23 | // For everything in this file, "inputs" and "outputs" are defined from the |
| 24 | // perspective of the plant. This means U is an input and Y is an output |
| 25 | // (because you give the plant U (powers) and it gives you back a Y (sensor |
| 26 | // values). This is the opposite of what they mean from the perspective of the |
| 27 | // controller (U is an output because that's what goes to the motors and Y is an |
| 28 | // input because that's what comes back from the sensors). |
| 29 | |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 30 | template <int number_of_states, int number_of_inputs, int number_of_outputs> |
Austin Schuh | 64f17a5 | 2017-02-25 14:41:58 -0800 | [diff] [blame] | 31 | struct StateFeedbackPlantCoefficients final { |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 32 | public: |
| 33 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW; |
| 34 | |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 35 | StateFeedbackPlantCoefficients(const StateFeedbackPlantCoefficients &other) |
Austin Schuh | 64f17a5 | 2017-02-25 14:41:58 -0800 | [diff] [blame] | 36 | : A(other.A), |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 37 | A_inv(other.A_inv), |
Austin Schuh | 64f17a5 | 2017-02-25 14:41:58 -0800 | [diff] [blame] | 38 | B(other.B), |
Austin Schuh | 64f17a5 | 2017-02-25 14:41:58 -0800 | [diff] [blame] | 39 | C(other.C), |
| 40 | D(other.D), |
| 41 | U_min(other.U_min), |
| 42 | U_max(other.U_max) {} |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 43 | |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 44 | StateFeedbackPlantCoefficients( |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 45 | const Eigen::Matrix<double, number_of_states, number_of_states> &A, |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 46 | const Eigen::Matrix<double, number_of_states, number_of_states> &A_inv, |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 47 | const Eigen::Matrix<double, number_of_states, number_of_inputs> &B, |
| 48 | const Eigen::Matrix<double, number_of_outputs, number_of_states> &C, |
| 49 | const Eigen::Matrix<double, number_of_outputs, number_of_inputs> &D, |
Brian Silverman | 5808bcb | 2014-09-14 21:40:43 -0400 | [diff] [blame] | 50 | const Eigen::Matrix<double, number_of_inputs, 1> &U_max, |
| 51 | const Eigen::Matrix<double, number_of_inputs, 1> &U_min) |
Austin Schuh | 3ad5ed8 | 2017-02-25 21:36:19 -0800 | [diff] [blame] | 52 | : A(A), A_inv(A_inv), B(B), C(C), D(D), U_min(U_min), U_max(U_max) {} |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 53 | |
Austin Schuh | 64f17a5 | 2017-02-25 14:41:58 -0800 | [diff] [blame] | 54 | const Eigen::Matrix<double, number_of_states, number_of_states> A; |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 55 | const Eigen::Matrix<double, number_of_states, number_of_states> A_inv; |
Austin Schuh | 64f17a5 | 2017-02-25 14:41:58 -0800 | [diff] [blame] | 56 | const Eigen::Matrix<double, number_of_states, number_of_inputs> B; |
Austin Schuh | 64f17a5 | 2017-02-25 14:41:58 -0800 | [diff] [blame] | 57 | const Eigen::Matrix<double, number_of_outputs, number_of_states> C; |
| 58 | const Eigen::Matrix<double, number_of_outputs, number_of_inputs> D; |
| 59 | const Eigen::Matrix<double, number_of_inputs, 1> U_min; |
| 60 | const Eigen::Matrix<double, number_of_inputs, 1> U_max; |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | template <int number_of_states, int number_of_inputs, int number_of_outputs> |
| 64 | class StateFeedbackPlant { |
| 65 | public: |
| 66 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW; |
Brian Silverman | 0a151c9 | 2014-05-02 15:28:44 -0700 | [diff] [blame] | 67 | |
| 68 | StateFeedbackPlant( |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 69 | ::std::vector<::std::unique_ptr<StateFeedbackPlantCoefficients< |
Austin Schuh | 66c1988 | 2017-02-25 13:36:28 -0800 | [diff] [blame] | 70 | number_of_states, number_of_inputs, number_of_outputs>>> |
| 71 | *coefficients) |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 72 | : coefficients_(::std::move(*coefficients)), index_(0) { |
Brian Silverman | 0a151c9 | 2014-05-02 15:28:44 -0700 | [diff] [blame] | 73 | Reset(); |
| 74 | } |
| 75 | |
| 76 | StateFeedbackPlant(StateFeedbackPlant &&other) |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 77 | : index_(other.index_) { |
Brian Silverman | 0a151c9 | 2014-05-02 15:28:44 -0700 | [diff] [blame] | 78 | ::std::swap(coefficients_, other.coefficients_); |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 79 | X_.swap(other.X_); |
| 80 | Y_.swap(other.Y_); |
Brian Silverman | 0a151c9 | 2014-05-02 15:28:44 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Austin Schuh | 1a38796 | 2015-01-31 16:36:20 -0800 | [diff] [blame] | 83 | virtual ~StateFeedbackPlant() {} |
Brian Silverman | 0a151c9 | 2014-05-02 15:28:44 -0700 | [diff] [blame] | 84 | |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 85 | const Eigen::Matrix<double, number_of_states, number_of_states> &A() const { |
Austin Schuh | 64f17a5 | 2017-02-25 14:41:58 -0800 | [diff] [blame] | 86 | return coefficients().A; |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 87 | } |
| 88 | double A(int i, int j) const { return A()(i, j); } |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 89 | const Eigen::Matrix<double, number_of_states, number_of_states> &A_inv() const { |
| 90 | return coefficients().A_inv; |
| 91 | } |
| 92 | double A_inv(int i, int j) const { return A_inv()(i, j); } |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 93 | const Eigen::Matrix<double, number_of_states, number_of_inputs> &B() const { |
Austin Schuh | 64f17a5 | 2017-02-25 14:41:58 -0800 | [diff] [blame] | 94 | return coefficients().B; |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 95 | } |
| 96 | double B(int i, int j) const { return B()(i, j); } |
| 97 | const Eigen::Matrix<double, number_of_outputs, number_of_states> &C() const { |
Austin Schuh | 64f17a5 | 2017-02-25 14:41:58 -0800 | [diff] [blame] | 98 | return coefficients().C; |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 99 | } |
| 100 | double C(int i, int j) const { return C()(i, j); } |
| 101 | const Eigen::Matrix<double, number_of_outputs, number_of_inputs> &D() const { |
Austin Schuh | 64f17a5 | 2017-02-25 14:41:58 -0800 | [diff] [blame] | 102 | return coefficients().D; |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 103 | } |
| 104 | double D(int i, int j) const { return D()(i, j); } |
| 105 | const Eigen::Matrix<double, number_of_inputs, 1> &U_min() const { |
Austin Schuh | 64f17a5 | 2017-02-25 14:41:58 -0800 | [diff] [blame] | 106 | return coefficients().U_min; |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 107 | } |
Brian Silverman | a21c3a2 | 2014-06-12 21:49:15 -0700 | [diff] [blame] | 108 | double U_min(int i, int j) const { return U_min()(i, j); } |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 109 | const Eigen::Matrix<double, number_of_inputs, 1> &U_max() const { |
Austin Schuh | 64f17a5 | 2017-02-25 14:41:58 -0800 | [diff] [blame] | 110 | return coefficients().U_max; |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 111 | } |
Brian Silverman | a21c3a2 | 2014-06-12 21:49:15 -0700 | [diff] [blame] | 112 | double U_max(int i, int j) const { return U_max()(i, j); } |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 113 | |
| 114 | const Eigen::Matrix<double, number_of_states, 1> &X() const { return X_; } |
Brian Silverman | a21c3a2 | 2014-06-12 21:49:15 -0700 | [diff] [blame] | 115 | double X(int i, int j) const { return X()(i, j); } |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 116 | const Eigen::Matrix<double, number_of_outputs, 1> &Y() const { return Y_; } |
Brian Silverman | a21c3a2 | 2014-06-12 21:49:15 -0700 | [diff] [blame] | 117 | double Y(int i, int j) const { return Y()(i, j); } |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 118 | |
Brian Silverman | 0ca790b | 2014-06-12 21:33:08 -0700 | [diff] [blame] | 119 | Eigen::Matrix<double, number_of_states, 1> &mutable_X() { return X_; } |
Brian Silverman | a21c3a2 | 2014-06-12 21:49:15 -0700 | [diff] [blame] | 120 | double &mutable_X(int i, int j) { return mutable_X()(i, j); } |
Brian Silverman | 0ca790b | 2014-06-12 21:33:08 -0700 | [diff] [blame] | 121 | Eigen::Matrix<double, number_of_outputs, 1> &mutable_Y() { return Y_; } |
Brian Silverman | a21c3a2 | 2014-06-12 21:49:15 -0700 | [diff] [blame] | 122 | double &mutable_Y(int i, int j) { return mutable_Y()(i, j); } |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 123 | |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 124 | const StateFeedbackPlantCoefficients<number_of_states, number_of_inputs, |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 125 | number_of_outputs> |
| 126 | &coefficients(int index) const { |
| 127 | return *coefficients_[index]; |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 130 | const StateFeedbackPlantCoefficients<number_of_states, number_of_inputs, |
| 131 | number_of_outputs> |
| 132 | &coefficients() const { |
| 133 | return *coefficients_[index_]; |
| 134 | } |
| 135 | |
| 136 | int index() const { return index_; } |
| 137 | void set_index(int index) { |
| 138 | assert(index >= 0); |
| 139 | assert(index < static_cast<int>(coefficients_.size())); |
| 140 | index_ = index; |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | void Reset() { |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 144 | X_.setZero(); |
| 145 | Y_.setZero(); |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 146 | } |
| 147 | |
Austin Schuh | 849f003 | 2013-03-03 23:59:53 -0800 | [diff] [blame] | 148 | // Assert that U is within the hardware range. |
Austin Schuh | 66c1988 | 2017-02-25 13:36:28 -0800 | [diff] [blame] | 149 | virtual void CheckU(const Eigen::Matrix<double, number_of_inputs, 1> &U) { |
Brian Silverman | 5808bcb | 2014-09-14 21:40:43 -0400 | [diff] [blame] | 150 | for (int i = 0; i < kNumInputs; ++i) { |
Austin Schuh | 66c1988 | 2017-02-25 13:36:28 -0800 | [diff] [blame] | 151 | if (U(i, 0) > U_max(i, 0) + 0.00001 || U(i, 0) < U_min(i, 0) - 0.00001) { |
| 152 | LOG(FATAL, "U out of range\n"); |
| 153 | } |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 154 | } |
| 155 | } |
Austin Schuh | 849f003 | 2013-03-03 23:59:53 -0800 | [diff] [blame] | 156 | |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 157 | // Computes the new X and Y given the control input. |
Austin Schuh | 66c1988 | 2017-02-25 13:36:28 -0800 | [diff] [blame] | 158 | void Update(const Eigen::Matrix<double, number_of_inputs, 1> &U) { |
Austin Schuh | 849f003 | 2013-03-03 23:59:53 -0800 | [diff] [blame] | 159 | // Powers outside of the range are more likely controller bugs than things |
| 160 | // that the plant should deal with. |
Austin Schuh | 66c1988 | 2017-02-25 13:36:28 -0800 | [diff] [blame] | 161 | CheckU(U); |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 162 | X_ = Update(X(), U); |
Austin Schuh | 01c7b25 | 2017-03-05 00:59:31 -0800 | [diff] [blame^] | 163 | UpdateY(U); |
| 164 | } |
| 165 | |
| 166 | // Computes the new Y given the control input. |
| 167 | void UpdateY(const Eigen::Matrix<double, number_of_inputs, 1> &U) { |
Austin Schuh | 66c1988 | 2017-02-25 13:36:28 -0800 | [diff] [blame] | 168 | Y_ = C() * X() + D() * U; |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 169 | } |
| 170 | |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 171 | Eigen::Matrix<double, number_of_states, 1> Update( |
| 172 | const Eigen::Matrix<double, number_of_states, 1> X, |
Austin Schuh | 3ad5ed8 | 2017-02-25 21:36:19 -0800 | [diff] [blame] | 173 | const Eigen::Matrix<double, number_of_inputs, 1> &U) const { |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 174 | return A() * X + B() * U; |
| 175 | } |
| 176 | |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 177 | protected: |
| 178 | // these are accessible from non-templated subclasses |
Austin Schuh | b1cdb38 | 2013-03-01 22:53:52 -0800 | [diff] [blame] | 179 | static const int kNumStates = number_of_states; |
| 180 | static const int kNumOutputs = number_of_outputs; |
| 181 | static const int kNumInputs = number_of_inputs; |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 182 | |
| 183 | private: |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 184 | Eigen::Matrix<double, number_of_states, 1> X_; |
| 185 | Eigen::Matrix<double, number_of_outputs, 1> Y_; |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 186 | |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 187 | ::std::vector<::std::unique_ptr<StateFeedbackPlantCoefficients< |
Austin Schuh | 64f17a5 | 2017-02-25 14:41:58 -0800 | [diff] [blame] | 188 | number_of_states, number_of_inputs, number_of_outputs>>> |
| 189 | coefficients_; |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 190 | |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 191 | int index_; |
Brian Silverman | 0a151c9 | 2014-05-02 15:28:44 -0700 | [diff] [blame] | 192 | |
| 193 | DISALLOW_COPY_AND_ASSIGN(StateFeedbackPlant); |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 194 | }; |
| 195 | |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 196 | // A container for all the controller coefficients. |
Austin Schuh | 9644e1c | 2013-03-12 00:40:36 -0700 | [diff] [blame] | 197 | template <int number_of_states, int number_of_inputs, int number_of_outputs> |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 198 | struct StateFeedbackControllerCoefficients final { |
Austin Schuh | 9644e1c | 2013-03-12 00:40:36 -0700 | [diff] [blame] | 199 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW; |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 200 | |
Brian Silverman | 5808bcb | 2014-09-14 21:40:43 -0400 | [diff] [blame] | 201 | const Eigen::Matrix<double, number_of_inputs, number_of_states> K; |
Austin Schuh | 86093ad | 2016-02-06 14:29:34 -0800 | [diff] [blame] | 202 | const Eigen::Matrix<double, number_of_inputs, number_of_states> Kff; |
Austin Schuh | 9644e1c | 2013-03-12 00:40:36 -0700 | [diff] [blame] | 203 | |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 204 | StateFeedbackControllerCoefficients( |
Brian Silverman | 5808bcb | 2014-09-14 21:40:43 -0400 | [diff] [blame] | 205 | const Eigen::Matrix<double, number_of_inputs, number_of_states> &K, |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 206 | const Eigen::Matrix<double, number_of_inputs, number_of_states> &Kff) |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 207 | : K(K), Kff(Kff) {} |
| 208 | }; |
| 209 | |
| 210 | template <int number_of_states, int number_of_inputs, int number_of_outputs> |
Austin Schuh | 3ad5ed8 | 2017-02-25 21:36:19 -0800 | [diff] [blame] | 211 | struct StateFeedbackHybridPlantCoefficients final { |
| 212 | public: |
| 213 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW; |
| 214 | |
| 215 | StateFeedbackHybridPlantCoefficients( |
| 216 | const StateFeedbackHybridPlantCoefficients &other) |
| 217 | : A_continuous(other.A_continuous), |
| 218 | B_continuous(other.B_continuous), |
| 219 | C(other.C), |
| 220 | D(other.D), |
| 221 | U_min(other.U_min), |
| 222 | U_max(other.U_max) {} |
| 223 | |
| 224 | StateFeedbackHybridPlantCoefficients( |
| 225 | const Eigen::Matrix<double, number_of_states, number_of_states> |
| 226 | &A_continuous, |
| 227 | const Eigen::Matrix<double, number_of_states, number_of_inputs> |
| 228 | &B_continuous, |
| 229 | const Eigen::Matrix<double, number_of_outputs, number_of_states> &C, |
| 230 | const Eigen::Matrix<double, number_of_outputs, number_of_inputs> &D, |
| 231 | const Eigen::Matrix<double, number_of_inputs, 1> &U_max, |
| 232 | const Eigen::Matrix<double, number_of_inputs, 1> &U_min) |
| 233 | : A_continuous(A_continuous), |
| 234 | B_continuous(B_continuous), |
| 235 | C(C), |
| 236 | D(D), |
| 237 | U_min(U_min), |
| 238 | U_max(U_max) {} |
| 239 | |
| 240 | const Eigen::Matrix<double, number_of_states, number_of_states> A_continuous; |
| 241 | const Eigen::Matrix<double, number_of_states, number_of_inputs> B_continuous; |
| 242 | const Eigen::Matrix<double, number_of_outputs, number_of_states> C; |
| 243 | const Eigen::Matrix<double, number_of_outputs, number_of_inputs> D; |
| 244 | const Eigen::Matrix<double, number_of_inputs, 1> U_min; |
| 245 | const Eigen::Matrix<double, number_of_inputs, 1> U_max; |
| 246 | }; |
| 247 | |
| 248 | template <int number_of_states, int number_of_inputs, int number_of_outputs> |
| 249 | class StateFeedbackHybridPlant { |
| 250 | public: |
| 251 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW; |
| 252 | |
| 253 | StateFeedbackHybridPlant( |
| 254 | ::std::vector<::std::unique_ptr<StateFeedbackHybridPlantCoefficients< |
| 255 | number_of_states, number_of_inputs, number_of_outputs>>> |
| 256 | *coefficients) |
| 257 | : coefficients_(::std::move(*coefficients)), index_(0) { |
| 258 | Reset(); |
| 259 | } |
| 260 | |
| 261 | StateFeedbackHybridPlant(StateFeedbackHybridPlant &&other) |
| 262 | : index_(other.index_) { |
| 263 | ::std::swap(coefficients_, other.coefficients_); |
| 264 | X_.swap(other.X_); |
| 265 | Y_.swap(other.Y_); |
| 266 | } |
| 267 | |
| 268 | virtual ~StateFeedbackHybridPlant() {} |
| 269 | |
| 270 | const Eigen::Matrix<double, number_of_states, number_of_states> &A() const { |
| 271 | return A_; |
| 272 | } |
| 273 | double A(int i, int j) const { return A()(i, j); } |
| 274 | const Eigen::Matrix<double, number_of_states, number_of_inputs> &B() const { |
| 275 | return B_; |
| 276 | } |
| 277 | double B(int i, int j) const { return B()(i, j); } |
| 278 | const Eigen::Matrix<double, number_of_outputs, number_of_states> &C() const { |
| 279 | return coefficients().C; |
| 280 | } |
| 281 | double C(int i, int j) const { return C()(i, j); } |
| 282 | const Eigen::Matrix<double, number_of_outputs, number_of_inputs> &D() const { |
| 283 | return coefficients().D; |
| 284 | } |
| 285 | double D(int i, int j) const { return D()(i, j); } |
| 286 | const Eigen::Matrix<double, number_of_inputs, 1> &U_min() const { |
| 287 | return coefficients().U_min; |
| 288 | } |
| 289 | double U_min(int i, int j) const { return U_min()(i, j); } |
| 290 | const Eigen::Matrix<double, number_of_inputs, 1> &U_max() const { |
| 291 | return coefficients().U_max; |
| 292 | } |
| 293 | double U_max(int i, int j) const { return U_max()(i, j); } |
| 294 | |
| 295 | const Eigen::Matrix<double, number_of_states, 1> &X() const { return X_; } |
| 296 | double X(int i, int j) const { return X()(i, j); } |
| 297 | const Eigen::Matrix<double, number_of_outputs, 1> &Y() const { return Y_; } |
| 298 | double Y(int i, int j) const { return Y()(i, j); } |
| 299 | |
| 300 | Eigen::Matrix<double, number_of_states, 1> &mutable_X() { return X_; } |
| 301 | double &mutable_X(int i, int j) { return mutable_X()(i, j); } |
| 302 | Eigen::Matrix<double, number_of_outputs, 1> &mutable_Y() { return Y_; } |
| 303 | double &mutable_Y(int i, int j) { return mutable_Y()(i, j); } |
| 304 | |
| 305 | const StateFeedbackHybridPlantCoefficients<number_of_states, number_of_inputs, |
| 306 | number_of_outputs> |
| 307 | &coefficients(int index) const { |
| 308 | return *coefficients_[index]; |
| 309 | } |
| 310 | |
| 311 | const StateFeedbackHybridPlantCoefficients<number_of_states, number_of_inputs, |
| 312 | number_of_outputs> |
| 313 | &coefficients() const { |
| 314 | return *coefficients_[index_]; |
| 315 | } |
| 316 | |
| 317 | int index() const { return index_; } |
| 318 | void set_index(int index) { |
| 319 | assert(index >= 0); |
| 320 | assert(index < static_cast<int>(coefficients_.size())); |
| 321 | index_ = index; |
| 322 | } |
| 323 | |
| 324 | void Reset() { |
| 325 | X_.setZero(); |
| 326 | Y_.setZero(); |
| 327 | A_.setZero(); |
| 328 | B_.setZero(); |
| 329 | UpdateAB(::aos::controls::kLoopFrequency); |
| 330 | } |
| 331 | |
| 332 | // Assert that U is within the hardware range. |
| 333 | virtual void CheckU(const Eigen::Matrix<double, number_of_inputs, 1> &U) { |
| 334 | for (int i = 0; i < kNumInputs; ++i) { |
| 335 | if (U(i, 0) > U_max(i, 0) + 0.00001 || U(i, 0) < U_min(i, 0) - 0.00001) { |
| 336 | LOG(FATAL, "U out of range\n"); |
| 337 | } |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | // Computes the new X and Y given the control input. |
| 342 | void Update(const Eigen::Matrix<double, number_of_inputs, 1> &U, |
| 343 | ::std::chrono::nanoseconds dt) { |
| 344 | // Powers outside of the range are more likely controller bugs than things |
| 345 | // that the plant should deal with. |
| 346 | CheckU(U); |
| 347 | X_ = Update(X(), U, dt); |
| 348 | Y_ = C() * X() + D() * U; |
| 349 | } |
| 350 | |
| 351 | Eigen::Matrix<double, number_of_states, 1> Update( |
| 352 | const Eigen::Matrix<double, number_of_states, 1> X, |
| 353 | const Eigen::Matrix<double, number_of_inputs, 1> &U, |
| 354 | ::std::chrono::nanoseconds dt) { |
| 355 | UpdateAB(dt); |
| 356 | return A() * X + B() * U; |
| 357 | } |
| 358 | |
| 359 | protected: |
| 360 | // these are accessible from non-templated subclasses |
| 361 | static const int kNumStates = number_of_states; |
| 362 | static const int kNumOutputs = number_of_outputs; |
| 363 | static const int kNumInputs = number_of_inputs; |
| 364 | |
| 365 | private: |
| 366 | void UpdateAB(::std::chrono::nanoseconds dt) { |
| 367 | Eigen::Matrix<double, number_of_states + number_of_inputs, |
| 368 | number_of_states + number_of_inputs> |
| 369 | M_state_continuous; |
| 370 | M_state_continuous.setZero(); |
| 371 | M_state_continuous.template block<number_of_states, number_of_states>(0, |
| 372 | 0) = |
| 373 | coefficients().A_continuous * |
| 374 | ::std::chrono::duration_cast<::std::chrono::duration<double>>(dt) |
| 375 | .count(); |
| 376 | M_state_continuous.template block<number_of_states, number_of_inputs>( |
| 377 | 0, number_of_states) = |
| 378 | coefficients().B_continuous * |
| 379 | ::std::chrono::duration_cast<::std::chrono::duration<double>>(dt) |
| 380 | .count(); |
| 381 | |
| 382 | Eigen::Matrix<double, number_of_states + number_of_inputs, |
| 383 | number_of_states + number_of_inputs> |
| 384 | M_state = M_state_continuous.exp(); |
| 385 | A_ = M_state.template block<number_of_states, number_of_states>(0, 0); |
| 386 | B_ = M_state.template block<number_of_states, number_of_inputs>( |
| 387 | 0, number_of_states); |
| 388 | } |
| 389 | |
| 390 | Eigen::Matrix<double, number_of_states, 1> X_; |
| 391 | Eigen::Matrix<double, number_of_outputs, 1> Y_; |
| 392 | |
| 393 | Eigen::Matrix<double, number_of_states, number_of_states> A_; |
| 394 | Eigen::Matrix<double, number_of_states, number_of_inputs> B_; |
| 395 | |
| 396 | |
| 397 | ::std::vector<::std::unique_ptr<StateFeedbackHybridPlantCoefficients< |
| 398 | number_of_states, number_of_inputs, number_of_outputs>>> |
| 399 | coefficients_; |
| 400 | |
| 401 | int index_; |
| 402 | |
| 403 | DISALLOW_COPY_AND_ASSIGN(StateFeedbackHybridPlant); |
| 404 | }; |
| 405 | |
| 406 | template <int number_of_states, int number_of_inputs, int number_of_outputs> |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 407 | class StateFeedbackController { |
| 408 | public: |
| 409 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW; |
| 410 | |
| 411 | explicit StateFeedbackController( |
| 412 | ::std::vector<::std::unique_ptr<StateFeedbackControllerCoefficients< |
| 413 | number_of_states, number_of_inputs, number_of_outputs>>> *controllers) |
| 414 | : coefficients_(::std::move(*controllers)) {} |
| 415 | |
| 416 | StateFeedbackController(StateFeedbackController &&other) |
| 417 | : index_(other.index_) { |
| 418 | ::std::swap(coefficients_, other.coefficients_); |
| 419 | } |
| 420 | |
| 421 | const Eigen::Matrix<double, number_of_inputs, number_of_states> &K() const { |
| 422 | return coefficients().K; |
| 423 | } |
| 424 | double K(int i, int j) const { return K()(i, j); } |
| 425 | const Eigen::Matrix<double, number_of_inputs, number_of_states> &Kff() const { |
| 426 | return coefficients().Kff; |
| 427 | } |
| 428 | double Kff(int i, int j) const { return Kff()(i, j); } |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 429 | |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 430 | void Reset() {} |
| 431 | |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 432 | // Sets the current controller to be index, clamped to be within range. |
| 433 | void set_index(int index) { |
| 434 | if (index < 0) { |
| 435 | index_ = 0; |
| 436 | } else if (index >= static_cast<int>(coefficients_.size())) { |
| 437 | index_ = static_cast<int>(coefficients_.size()) - 1; |
| 438 | } else { |
| 439 | index_ = index; |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | int index() const { return index_; } |
| 444 | |
| 445 | const StateFeedbackControllerCoefficients<number_of_states, number_of_inputs, |
| 446 | number_of_outputs> |
| 447 | &coefficients(int index) const { |
| 448 | return *coefficients_[index]; |
| 449 | } |
| 450 | |
| 451 | const StateFeedbackControllerCoefficients<number_of_states, number_of_inputs, |
| 452 | number_of_outputs> |
| 453 | &coefficients() const { |
| 454 | return *coefficients_[index_]; |
| 455 | } |
| 456 | |
| 457 | private: |
| 458 | int index_ = 0; |
| 459 | ::std::vector<::std::unique_ptr<StateFeedbackControllerCoefficients< |
| 460 | number_of_states, number_of_inputs, number_of_outputs>>> |
| 461 | coefficients_; |
| 462 | }; |
| 463 | |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 464 | // A container for all the observer coefficients. |
| 465 | template <int number_of_states, int number_of_inputs, int number_of_outputs> |
| 466 | struct StateFeedbackObserverCoefficients final { |
| 467 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW; |
| 468 | |
| 469 | const Eigen::Matrix<double, number_of_states, number_of_outputs> L; |
| 470 | |
| 471 | StateFeedbackObserverCoefficients( |
| 472 | const Eigen::Matrix<double, number_of_states, number_of_outputs> &L) |
| 473 | : L(L) {} |
| 474 | }; |
| 475 | |
| 476 | template <int number_of_states, int number_of_inputs, int number_of_outputs> |
| 477 | class StateFeedbackObserver { |
| 478 | public: |
| 479 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW; |
| 480 | |
| 481 | explicit StateFeedbackObserver( |
| 482 | ::std::vector<::std::unique_ptr<StateFeedbackObserverCoefficients< |
| 483 | number_of_states, number_of_inputs, number_of_outputs>>> *observers) |
| 484 | : coefficients_(::std::move(*observers)) {} |
| 485 | |
| 486 | StateFeedbackObserver(StateFeedbackObserver &&other) |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 487 | : X_hat_(other.X_hat_), index_(other.index_) { |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 488 | ::std::swap(coefficients_, other.coefficients_); |
| 489 | } |
| 490 | |
| 491 | const Eigen::Matrix<double, number_of_states, number_of_outputs> &L() const { |
| 492 | return coefficients().L; |
| 493 | } |
| 494 | double L(int i, int j) const { return L()(i, j); } |
| 495 | |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 496 | const Eigen::Matrix<double, number_of_states, 1> &X_hat() const { |
| 497 | return X_hat_; |
| 498 | } |
| 499 | Eigen::Matrix<double, number_of_states, 1> &mutable_X_hat() { return X_hat_; } |
| 500 | |
Austin Schuh | 3ad5ed8 | 2017-02-25 21:36:19 -0800 | [diff] [blame] | 501 | void Reset( |
| 502 | StateFeedbackLoop<number_of_states, number_of_inputs, number_of_outputs, |
| 503 | StateFeedbackPlant<number_of_states, number_of_inputs, |
| 504 | number_of_outputs>, |
| 505 | StateFeedbackObserver> * /*loop*/) { |
| 506 | X_hat_.setZero(); |
| 507 | } |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 508 | |
Austin Schuh | 3ad5ed8 | 2017-02-25 21:36:19 -0800 | [diff] [blame] | 509 | void Predict( |
| 510 | StateFeedbackLoop<number_of_states, number_of_inputs, number_of_outputs, |
| 511 | StateFeedbackPlant<number_of_states, number_of_inputs, |
| 512 | number_of_outputs>, |
| 513 | StateFeedbackObserver> *loop, |
| 514 | const Eigen::Matrix<double, number_of_inputs, 1> &new_u, |
| 515 | ::std::chrono::nanoseconds /*dt*/) { |
| 516 | mutable_X_hat() = loop->plant().Update(X_hat(), new_u); |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | void Correct(const StateFeedbackLoop< |
| 520 | number_of_states, number_of_inputs, number_of_outputs, |
| 521 | StateFeedbackPlant<number_of_states, number_of_inputs, |
| 522 | number_of_outputs>, |
| 523 | StateFeedbackObserver> &loop, |
| 524 | const Eigen::Matrix<double, number_of_inputs, 1> &U, |
| 525 | const Eigen::Matrix<double, number_of_outputs, 1> &Y) { |
| 526 | mutable_X_hat() += loop.plant().A_inv() * L() * |
| 527 | (Y - loop.plant().C() * X_hat() - loop.plant().D() * U); |
| 528 | } |
| 529 | |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 530 | // Sets the current controller to be index, clamped to be within range. |
| 531 | void set_index(int index) { |
| 532 | if (index < 0) { |
| 533 | index_ = 0; |
| 534 | } else if (index >= static_cast<int>(coefficients_.size())) { |
| 535 | index_ = static_cast<int>(coefficients_.size()) - 1; |
| 536 | } else { |
| 537 | index_ = index; |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | int index() const { return index_; } |
| 542 | |
| 543 | const StateFeedbackObserverCoefficients<number_of_states, number_of_inputs, |
| 544 | number_of_outputs> |
| 545 | &coefficients(int index) const { |
| 546 | return *coefficients_[index]; |
| 547 | } |
| 548 | |
| 549 | const StateFeedbackObserverCoefficients<number_of_states, number_of_inputs, |
| 550 | number_of_outputs> |
| 551 | &coefficients() const { |
| 552 | return *coefficients_[index_]; |
| 553 | } |
| 554 | |
| 555 | private: |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 556 | // Internal state estimate. |
| 557 | Eigen::Matrix<double, number_of_states, 1> X_hat_; |
| 558 | |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 559 | int index_ = 0; |
| 560 | ::std::vector<::std::unique_ptr<StateFeedbackObserverCoefficients< |
| 561 | number_of_states, number_of_inputs, number_of_outputs>>> |
| 562 | coefficients_; |
Austin Schuh | 9644e1c | 2013-03-12 00:40:36 -0700 | [diff] [blame] | 563 | }; |
| 564 | |
Austin Schuh | 3ad5ed8 | 2017-02-25 21:36:19 -0800 | [diff] [blame] | 565 | // A container for all the observer coefficients. |
| 566 | template <int number_of_states, int number_of_inputs, int number_of_outputs> |
| 567 | struct HybridKalmanCoefficients final { |
| 568 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW; |
| 569 | |
| 570 | const Eigen::Matrix<double, number_of_states, number_of_states> Q_continuous; |
| 571 | const Eigen::Matrix<double, number_of_outputs, number_of_outputs> R_continuous; |
| 572 | const Eigen::Matrix<double, number_of_states, number_of_states> P_steady_state; |
| 573 | |
| 574 | HybridKalmanCoefficients( |
| 575 | const Eigen::Matrix<double, number_of_states, number_of_states> |
| 576 | &Q_continuous, |
| 577 | const Eigen::Matrix<double, number_of_outputs, number_of_outputs> |
| 578 | &R_continuous, |
| 579 | const Eigen::Matrix<double, number_of_states, number_of_states> |
| 580 | &P_steady_state) |
| 581 | : Q_continuous(Q_continuous), |
| 582 | R_continuous(R_continuous), |
| 583 | P_steady_state(P_steady_state) {} |
| 584 | }; |
| 585 | |
| 586 | template <int number_of_states, int number_of_inputs, int number_of_outputs> |
| 587 | class HybridKalman { |
| 588 | public: |
| 589 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW; |
| 590 | |
| 591 | explicit HybridKalman( |
| 592 | ::std::vector<::std::unique_ptr<HybridKalmanCoefficients< |
| 593 | number_of_states, number_of_inputs, number_of_outputs>>> *observers) |
| 594 | : coefficients_(::std::move(*observers)) {} |
| 595 | |
| 596 | HybridKalman(HybridKalman &&other) |
| 597 | : X_hat_(other.X_hat_), index_(other.index_) { |
| 598 | ::std::swap(coefficients_, other.coefficients_); |
| 599 | } |
| 600 | |
| 601 | // Getters for Q |
| 602 | const Eigen::Matrix<double, number_of_states, number_of_states> &Q() const { |
| 603 | return Q_; |
| 604 | } |
| 605 | double Q(int i, int j) const { return Q()(i, j); } |
| 606 | // Getters for R |
| 607 | const Eigen::Matrix<double, number_of_outputs, number_of_outputs> &R() const { |
| 608 | return R_; |
| 609 | } |
| 610 | double R(int i, int j) const { return R()(i, j); } |
| 611 | |
| 612 | // Getters for P |
| 613 | const Eigen::Matrix<double, number_of_states, number_of_states> &P() const { |
| 614 | return P_; |
| 615 | } |
| 616 | double P(int i, int j) const { return P()(i, j); } |
| 617 | |
| 618 | // Getters for X_hat |
| 619 | const Eigen::Matrix<double, number_of_states, 1> &X_hat() const { |
| 620 | return X_hat_; |
| 621 | } |
| 622 | Eigen::Matrix<double, number_of_states, 1> &mutable_X_hat() { return X_hat_; } |
| 623 | |
| 624 | void Reset(StateFeedbackLoop< |
| 625 | number_of_states, number_of_inputs, number_of_outputs, |
| 626 | StateFeedbackHybridPlant<number_of_states, number_of_inputs, |
| 627 | number_of_outputs>, |
| 628 | HybridKalman> *loop) { |
| 629 | X_hat_.setZero(); |
| 630 | P_ = coefficients().P_steady_state; |
| 631 | UpdateQR(loop, ::aos::controls::kLoopFrequency); |
| 632 | } |
| 633 | |
| 634 | void Predict(StateFeedbackLoop< |
| 635 | number_of_states, number_of_inputs, number_of_outputs, |
| 636 | StateFeedbackHybridPlant<number_of_states, number_of_inputs, |
| 637 | number_of_outputs>, |
| 638 | HybridKalman> *loop, |
| 639 | const Eigen::Matrix<double, number_of_inputs, 1> &new_u, |
| 640 | ::std::chrono::nanoseconds dt) { |
| 641 | // Trigger the predict step. This will update A() and B() in the plant. |
| 642 | mutable_X_hat() = loop->mutable_plant()->Update(X_hat(), new_u, dt); |
| 643 | |
| 644 | UpdateQR(loop, dt); |
| 645 | P_ = loop->plant().A() * P_ * loop->plant().A().transpose() + Q_; |
| 646 | } |
| 647 | |
| 648 | void Correct(const StateFeedbackLoop< |
| 649 | number_of_states, number_of_inputs, number_of_outputs, |
| 650 | StateFeedbackHybridPlant<number_of_states, number_of_inputs, |
| 651 | number_of_outputs>, |
| 652 | HybridKalman> &loop, |
| 653 | const Eigen::Matrix<double, number_of_inputs, 1> &U, |
| 654 | const Eigen::Matrix<double, number_of_outputs, 1> &Y) { |
| 655 | Eigen::Matrix<double, number_of_outputs, 1> Y_bar = |
| 656 | Y - (loop.plant().C() * X_hat_ + loop.plant().D() * U); |
| 657 | Eigen::Matrix<double, number_of_outputs, number_of_outputs> S = |
| 658 | loop.plant().C() * P_ * loop.plant().C().transpose() + R_; |
| 659 | Eigen::Matrix<double, number_of_states, number_of_outputs> KalmanGain; |
| 660 | KalmanGain = (S.transpose().ldlt().solve( |
| 661 | (P() * loop.plant().C().transpose()).transpose())) |
| 662 | .transpose(); |
| 663 | X_hat_ = X_hat_ + KalmanGain * Y_bar; |
| 664 | P_ = (loop.plant().coefficients().A_continuous.Identity() - |
| 665 | KalmanGain * loop.plant().C()) * |
| 666 | P(); |
| 667 | } |
| 668 | |
| 669 | // Sets the current controller to be index, clamped to be within range. |
| 670 | void set_index(int index) { |
| 671 | if (index < 0) { |
| 672 | index_ = 0; |
| 673 | } else if (index >= static_cast<int>(coefficients_.size())) { |
| 674 | index_ = static_cast<int>(coefficients_.size()) - 1; |
| 675 | } else { |
| 676 | index_ = index; |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | int index() const { return index_; } |
| 681 | |
| 682 | const HybridKalmanCoefficients<number_of_states, number_of_inputs, |
| 683 | number_of_outputs> |
| 684 | &coefficients(int index) const { |
| 685 | return *coefficients_[index]; |
| 686 | } |
| 687 | |
| 688 | const HybridKalmanCoefficients<number_of_states, number_of_inputs, |
| 689 | number_of_outputs> |
| 690 | &coefficients() const { |
| 691 | return *coefficients_[index_]; |
| 692 | } |
| 693 | |
| 694 | private: |
| 695 | void UpdateQR(StateFeedbackLoop< |
| 696 | number_of_states, number_of_inputs, number_of_outputs, |
| 697 | StateFeedbackHybridPlant<number_of_states, number_of_inputs, |
| 698 | number_of_outputs>, |
| 699 | HybridKalman> *loop, |
| 700 | ::std::chrono::nanoseconds dt) { |
| 701 | // Now, compute the discrete time Q and R coefficients. |
| 702 | Eigen::Matrix<double, number_of_states, number_of_states> Qtemp = |
| 703 | (coefficients().Q_continuous + |
| 704 | coefficients().Q_continuous.transpose()) / |
| 705 | 2.0; |
| 706 | Eigen::Matrix<double, number_of_outputs, number_of_outputs> Rtemp = |
| 707 | (coefficients().R_continuous + |
| 708 | coefficients().R_continuous.transpose()) / |
| 709 | 2.0; |
| 710 | |
| 711 | Eigen::Matrix<double, 2 * number_of_states, 2 * number_of_states> M_gain; |
| 712 | M_gain.setZero(); |
| 713 | // Set up the matrix M = [[-A, Q], [0, A.T]] |
| 714 | M_gain.template block<number_of_states, number_of_states>(0, 0) = |
| 715 | -loop->plant().coefficients().A_continuous; |
| 716 | M_gain.template block<number_of_states, number_of_states>( |
| 717 | 0, number_of_states) = Qtemp; |
| 718 | M_gain.template block<number_of_states, number_of_states>( |
| 719 | number_of_states, number_of_states) = |
| 720 | loop->plant().coefficients().A_continuous.transpose(); |
| 721 | |
| 722 | Eigen::Matrix<double, 2 * number_of_states, 2 *number_of_states> phi = |
| 723 | (M_gain * |
| 724 | ::std::chrono::duration_cast<::std::chrono::duration<double>>(dt) |
| 725 | .count()) |
| 726 | .exp(); |
| 727 | |
| 728 | // Phi12 = phi[0:number_of_states, number_of_states:2*number_of_states] |
| 729 | // Phi22 = phi[number_of_states:2*number_of_states, |
| 730 | // number_of_states:2*number_of_states] |
| 731 | Eigen::Matrix<double, number_of_states, number_of_states> phi12 = |
| 732 | phi.block(0, number_of_states, number_of_states, number_of_states); |
| 733 | Eigen::Matrix<double, number_of_states, number_of_states> phi22 = phi.block( |
| 734 | number_of_states, number_of_states, number_of_states, number_of_states); |
| 735 | |
| 736 | Q_ = phi22.transpose() * phi12; |
| 737 | Q_ = (Q_ + Q_.transpose()) / 2.0; |
| 738 | R_ = Rtemp / |
| 739 | ::std::chrono::duration_cast<::std::chrono::duration<double>>(dt) |
| 740 | .count(); |
| 741 | } |
| 742 | |
| 743 | // Internal state estimate. |
| 744 | Eigen::Matrix<double, number_of_states, 1> X_hat_; |
| 745 | // Internal covariance estimate. |
| 746 | Eigen::Matrix<double, number_of_states, number_of_states> P_; |
| 747 | |
| 748 | // Discretized Q and R for the kalman filter. |
| 749 | Eigen::Matrix<double, number_of_states, number_of_states> Q_; |
| 750 | Eigen::Matrix<double, number_of_outputs, number_of_outputs> R_; |
| 751 | |
| 752 | int index_ = 0; |
| 753 | ::std::vector<::std::unique_ptr<HybridKalmanCoefficients< |
| 754 | number_of_states, number_of_inputs, number_of_outputs>>> |
| 755 | coefficients_; |
| 756 | }; |
| 757 | |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 758 | template <int number_of_states, int number_of_inputs, int number_of_outputs, |
| 759 | typename PlantType = StateFeedbackPlant< |
| 760 | number_of_states, number_of_inputs, number_of_outputs>, |
| 761 | typename ObserverType = StateFeedbackObserver< |
| 762 | number_of_states, number_of_inputs, number_of_outputs>> |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 763 | class StateFeedbackLoop { |
| 764 | public: |
| 765 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW; |
| 766 | |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 767 | explicit StateFeedbackLoop( |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 768 | PlantType &&plant, |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 769 | StateFeedbackController<number_of_states, number_of_inputs, |
| 770 | number_of_outputs> &&controller, |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 771 | ObserverType &&observer) |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 772 | : plant_(::std::move(plant)), |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 773 | controller_(::std::move(controller)), |
| 774 | observer_(::std::move(observer)) { |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 775 | Reset(); |
| 776 | } |
| 777 | |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 778 | StateFeedbackLoop(StateFeedbackLoop &&other) |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 779 | : plant_(::std::move(other.plant_)), |
| 780 | controller_(::std::move(other.controller_)), |
| 781 | observer_(::std::move(other.observer_)) { |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 782 | R_.swap(other.R_); |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 783 | next_R_.swap(other.next_R_); |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 784 | U_.swap(other.U_); |
| 785 | U_uncapped_.swap(other.U_uncapped_); |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 786 | ff_U_.swap(other.ff_U_); |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 787 | } |
| 788 | |
Austin Schuh | 1a38796 | 2015-01-31 16:36:20 -0800 | [diff] [blame] | 789 | virtual ~StateFeedbackLoop() {} |
Brian Silverman | 0a151c9 | 2014-05-02 15:28:44 -0700 | [diff] [blame] | 790 | |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 791 | const Eigen::Matrix<double, number_of_states, 1> &X_hat() const { |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 792 | return observer().X_hat(); |
Austin Schuh | 9644e1c | 2013-03-12 00:40:36 -0700 | [diff] [blame] | 793 | } |
Brian Silverman | a21c3a2 | 2014-06-12 21:49:15 -0700 | [diff] [blame] | 794 | double X_hat(int i, int j) const { return X_hat()(i, j); } |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 795 | const Eigen::Matrix<double, number_of_states, 1> &R() const { return R_; } |
Brian Silverman | a21c3a2 | 2014-06-12 21:49:15 -0700 | [diff] [blame] | 796 | double R(int i, int j) const { return R()(i, j); } |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 797 | const Eigen::Matrix<double, number_of_states, 1> &next_R() const { |
| 798 | return next_R_; |
| 799 | } |
| 800 | double next_R(int i, int j) const { return next_R()(i, j); } |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 801 | const Eigen::Matrix<double, number_of_inputs, 1> &U() const { return U_; } |
Brian Silverman | a21c3a2 | 2014-06-12 21:49:15 -0700 | [diff] [blame] | 802 | double U(int i, int j) const { return U()(i, j); } |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 803 | const Eigen::Matrix<double, number_of_inputs, 1> &U_uncapped() const { |
| 804 | return U_uncapped_; |
Austin Schuh | 9644e1c | 2013-03-12 00:40:36 -0700 | [diff] [blame] | 805 | } |
Brian Silverman | a21c3a2 | 2014-06-12 21:49:15 -0700 | [diff] [blame] | 806 | double U_uncapped(int i, int j) const { return U_uncapped()(i, j); } |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 807 | const Eigen::Matrix<double, number_of_inputs, 1> &ff_U() const { |
| 808 | return ff_U_; |
| 809 | } |
| 810 | double ff_U(int i, int j) const { return ff_U()(i, j); } |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 811 | |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 812 | Eigen::Matrix<double, number_of_states, 1> &mutable_X_hat() { |
| 813 | return observer_.mutable_X_hat(); |
| 814 | } |
Brian Silverman | a21c3a2 | 2014-06-12 21:49:15 -0700 | [diff] [blame] | 815 | double &mutable_X_hat(int i, int j) { return mutable_X_hat()(i, j); } |
Brian Silverman | 0ca790b | 2014-06-12 21:33:08 -0700 | [diff] [blame] | 816 | Eigen::Matrix<double, number_of_states, 1> &mutable_R() { return R_; } |
Brian Silverman | a21c3a2 | 2014-06-12 21:49:15 -0700 | [diff] [blame] | 817 | double &mutable_R(int i, int j) { return mutable_R()(i, j); } |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 818 | Eigen::Matrix<double, number_of_states, 1> &mutable_next_R() { |
| 819 | return next_R_; |
| 820 | } |
| 821 | double &mutable_next_R(int i, int j) { return mutable_next_R()(i, j); } |
Brian Silverman | 0ca790b | 2014-06-12 21:33:08 -0700 | [diff] [blame] | 822 | Eigen::Matrix<double, number_of_inputs, 1> &mutable_U() { return U_; } |
Brian Silverman | a21c3a2 | 2014-06-12 21:49:15 -0700 | [diff] [blame] | 823 | double &mutable_U(int i, int j) { return mutable_U()(i, j); } |
Brian Silverman | 0ca790b | 2014-06-12 21:33:08 -0700 | [diff] [blame] | 824 | Eigen::Matrix<double, number_of_inputs, 1> &mutable_U_uncapped() { |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 825 | return U_uncapped_; |
| 826 | } |
Brian Silverman | a21c3a2 | 2014-06-12 21:49:15 -0700 | [diff] [blame] | 827 | double &mutable_U_uncapped(int i, int j) { |
| 828 | return mutable_U_uncapped()(i, j); |
| 829 | } |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 830 | |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 831 | const PlantType &plant() const { return plant_; } |
Austin Schuh | 3ad5ed8 | 2017-02-25 21:36:19 -0800 | [diff] [blame] | 832 | PlantType *mutable_plant() { return &plant_; } |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 833 | |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 834 | const StateFeedbackController<number_of_states, number_of_inputs, |
| 835 | number_of_outputs> |
Austin Schuh | 66c1988 | 2017-02-25 13:36:28 -0800 | [diff] [blame] | 836 | &controller() const { |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 837 | return controller_; |
Austin Schuh | 9644e1c | 2013-03-12 00:40:36 -0700 | [diff] [blame] | 838 | } |
| 839 | |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 840 | const ObserverType &observer() const { return observer_; } |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 841 | |
Austin Schuh | 9644e1c | 2013-03-12 00:40:36 -0700 | [diff] [blame] | 842 | void Reset() { |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 843 | R_.setZero(); |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 844 | next_R_.setZero(); |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 845 | U_.setZero(); |
| 846 | U_uncapped_.setZero(); |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 847 | ff_U_.setZero(); |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 848 | |
| 849 | plant_.Reset(); |
| 850 | controller_.Reset(); |
Austin Schuh | 3ad5ed8 | 2017-02-25 21:36:19 -0800 | [diff] [blame] | 851 | observer_.Reset(this); |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | // If U is outside the hardware range, limit it before the plant tries to use |
| 855 | // it. |
| 856 | virtual void CapU() { |
Brian Silverman | 5808bcb | 2014-09-14 21:40:43 -0400 | [diff] [blame] | 857 | for (int i = 0; i < kNumInputs; ++i) { |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 858 | if (U(i, 0) > plant().U_max(i, 0)) { |
| 859 | U_(i, 0) = plant().U_max(i, 0); |
| 860 | } else if (U(i, 0) < plant().U_min(i, 0)) { |
| 861 | U_(i, 0) = plant().U_min(i, 0); |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 862 | } |
| 863 | } |
| 864 | } |
| 865 | |
Austin Schuh | f9286cd | 2014-02-11 00:51:09 -0800 | [diff] [blame] | 866 | // Corrects X_hat given the observation in Y. |
| 867 | void Correct(const Eigen::Matrix<double, number_of_outputs, 1> &Y) { |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 868 | observer_.Correct(*this, U(), Y); |
Austin Schuh | f9286cd | 2014-02-11 00:51:09 -0800 | [diff] [blame] | 869 | } |
| 870 | |
Austin Schuh | 3f862bb | 2016-02-27 14:48:05 -0800 | [diff] [blame] | 871 | const Eigen::Matrix<double, number_of_states, 1> error() const { |
| 872 | return R() - X_hat(); |
| 873 | } |
| 874 | |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 875 | // Returns the calculated controller power. |
| 876 | virtual const Eigen::Matrix<double, number_of_inputs, 1> ControllerOutput() { |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 877 | // TODO(austin): Should this live in StateSpaceController? |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 878 | ff_U_ = FeedForward(); |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 879 | return controller().K() * error() + ff_U_; |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | // Calculates the feed forwards power. |
| 883 | virtual const Eigen::Matrix<double, number_of_inputs, 1> FeedForward() { |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 884 | // TODO(austin): Should this live in StateSpaceController? |
| 885 | return controller().Kff() * (next_R() - plant().A() * R()); |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 886 | } |
| 887 | |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 888 | // stop_motors is whether or not to output all 0s. |
Austin Schuh | 3ad5ed8 | 2017-02-25 21:36:19 -0800 | [diff] [blame] | 889 | void Update(bool stop_motors, |
| 890 | ::std::chrono::nanoseconds dt = ::std::chrono::milliseconds(5)) { |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 891 | if (stop_motors) { |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 892 | U_.setZero(); |
| 893 | U_uncapped_.setZero(); |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 894 | ff_U_.setZero(); |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 895 | } else { |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 896 | U_ = U_uncapped_ = ControllerOutput(); |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 897 | CapU(); |
| 898 | } |
| 899 | |
Austin Schuh | 3ad5ed8 | 2017-02-25 21:36:19 -0800 | [diff] [blame] | 900 | UpdateObserver(U_, dt); |
Austin Schuh | 093535c | 2016-03-05 23:21:00 -0800 | [diff] [blame] | 901 | |
| 902 | UpdateFFReference(); |
| 903 | } |
| 904 | |
| 905 | // Updates R() after any CapU operations happen on U(). |
| 906 | void UpdateFFReference() { |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 907 | ff_U_ -= U_uncapped() - U(); |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 908 | if (!controller().Kff().isZero(0)) { |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 909 | R_ = plant().A() * R() + plant().B() * ff_U_; |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 910 | } |
Ben Fredrickson | 890c3fe | 2014-03-02 00:15:16 +0000 | [diff] [blame] | 911 | } |
| 912 | |
Austin Schuh | 3ad5ed8 | 2017-02-25 21:36:19 -0800 | [diff] [blame] | 913 | void UpdateObserver(const Eigen::Matrix<double, number_of_inputs, 1> &new_u, |
| 914 | ::std::chrono::nanoseconds dt) { |
| 915 | observer_.Predict(this, new_u, dt); |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 916 | } |
| 917 | |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 918 | // Sets the current controller to be index. |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 919 | void set_index(int index) { |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 920 | plant_.set_index(index); |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 921 | controller_.set_index(index); |
| 922 | observer_.set_index(index); |
Austin Schuh | 9644e1c | 2013-03-12 00:40:36 -0700 | [diff] [blame] | 923 | } |
| 924 | |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 925 | int index() const { return plant_.index(); } |
Austin Schuh | 9644e1c | 2013-03-12 00:40:36 -0700 | [diff] [blame] | 926 | |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 927 | protected: |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 928 | PlantType plant_; |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 929 | |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 930 | StateFeedbackController<number_of_states, number_of_inputs, number_of_outputs> |
| 931 | controller_; |
| 932 | |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 933 | ObserverType observer_; |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 934 | |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 935 | // These are accessible from non-templated subclasses. |
Austin Schuh | f59b6bc | 2016-03-11 21:26:19 -0800 | [diff] [blame] | 936 | static constexpr int kNumStates = number_of_states; |
| 937 | static constexpr int kNumOutputs = number_of_outputs; |
| 938 | static constexpr int kNumInputs = number_of_inputs; |
| 939 | |
| 940 | // Portion of U which is based on the feed-forwards. |
| 941 | Eigen::Matrix<double, number_of_inputs, 1> ff_U_; |
Austin Schuh | 9644e1c | 2013-03-12 00:40:36 -0700 | [diff] [blame] | 942 | |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 943 | private: |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 944 | // Current goal (Used by the feed-back controller). |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 945 | Eigen::Matrix<double, number_of_states, 1> R_; |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 946 | // Goal to go to in the next cycle (Used by Feed-Forward controller.) |
| 947 | Eigen::Matrix<double, number_of_states, 1> next_R_; |
| 948 | // Computed output after being capped. |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 949 | Eigen::Matrix<double, number_of_inputs, 1> U_; |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 950 | // Computed output before being capped. |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 951 | Eigen::Matrix<double, number_of_inputs, 1> U_uncapped_; |
| 952 | |
Brian Silverman | 0a151c9 | 2014-05-02 15:28:44 -0700 | [diff] [blame] | 953 | DISALLOW_COPY_AND_ASSIGN(StateFeedbackLoop); |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 954 | }; |
| 955 | |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 956 | #endif // FRC971_CONTROL_LOOPS_STATE_FEEDBACK_LOOP_H_ |