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 | |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame] | 4 | #include <cassert> |
Tyler Chatow | 6738c36 | 2019-02-16 14:12:30 -0800 | [diff] [blame] | 5 | #include <chrono> |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 6 | #include <memory> |
| 7 | #include <utility> |
| 8 | #include <vector> |
Brian Silverman | c571e05 | 2013-03-13 17:58:56 -0700 | [diff] [blame] | 9 | |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 10 | #include "Eigen/Dense" |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame] | 11 | |
Austin Schuh | 3ad5ed8 | 2017-02-25 21:36:19 -0800 | [diff] [blame] | 12 | #include "unsupported/Eigen/MatrixFunctions" |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 13 | |
Brian Silverman | 6260c09 | 2018-01-14 15:21:36 -0800 | [diff] [blame] | 14 | #if defined(__linux__) |
Austin Schuh | b39f452 | 2022-03-27 13:29:42 -0700 | [diff] [blame] | 15 | #include "glog/logging.h" |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame] | 16 | |
| 17 | #include "aos/logging/logging.h" |
Brian Silverman | 6260c09 | 2018-01-14 15:21:36 -0800 | [diff] [blame] | 18 | #endif |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 19 | #include "aos/macros.h" |
Brian Silverman | 0a151c9 | 2014-05-02 15:28:44 -0700 | [diff] [blame] | 20 | |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 21 | template <int number_of_states, int number_of_inputs, int number_of_outputs, |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 22 | typename PlantType, typename ObserverType, typename Scalar> |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 23 | class StateFeedbackLoop; |
| 24 | |
Brian Silverman | 5808bcb | 2014-09-14 21:40:43 -0400 | [diff] [blame] | 25 | // For everything in this file, "inputs" and "outputs" are defined from the |
| 26 | // perspective of the plant. This means U is an input and Y is an output |
| 27 | // (because you give the plant U (powers) and it gives you back a Y (sensor |
| 28 | // values). This is the opposite of what they mean from the perspective of the |
| 29 | // controller (U is an output because that's what goes to the motors and Y is an |
| 30 | // input because that's what comes back from the sensors). |
| 31 | |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 32 | template <int number_of_states, int number_of_inputs, int number_of_outputs, |
| 33 | typename Scalar = double> |
Austin Schuh | 64f17a5 | 2017-02-25 14:41:58 -0800 | [diff] [blame] | 34 | struct StateFeedbackPlantCoefficients final { |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 35 | public: |
| 36 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW; |
| 37 | |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 38 | StateFeedbackPlantCoefficients(const StateFeedbackPlantCoefficients &other) |
Austin Schuh | 64f17a5 | 2017-02-25 14:41:58 -0800 | [diff] [blame] | 39 | : A(other.A), |
Austin Schuh | 64f17a5 | 2017-02-25 14:41:58 -0800 | [diff] [blame] | 40 | B(other.B), |
Austin Schuh | 64f17a5 | 2017-02-25 14:41:58 -0800 | [diff] [blame] | 41 | C(other.C), |
| 42 | D(other.D), |
| 43 | U_min(other.U_min), |
James Kuszmaul | 03be124 | 2020-02-21 14:52:04 -0800 | [diff] [blame] | 44 | U_max(other.U_max), |
Ravago Jones | c471ebe | 2023-07-05 20:37:00 -0700 | [diff] [blame] | 45 | U_limit_coefficient(other.U_limit_coefficient), |
| 46 | U_limit_constant(other.U_limit_constant), |
Austin Schuh | 64433f1 | 2022-02-21 19:40:38 -0800 | [diff] [blame] | 47 | dt(other.dt), |
| 48 | delayed_u(other.delayed_u) {} |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 49 | |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 50 | StateFeedbackPlantCoefficients( |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 51 | const Eigen::Matrix<Scalar, number_of_states, number_of_states> &A, |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 52 | const Eigen::Matrix<Scalar, number_of_states, number_of_inputs> &B, |
| 53 | const Eigen::Matrix<Scalar, number_of_outputs, number_of_states> &C, |
| 54 | const Eigen::Matrix<Scalar, number_of_outputs, number_of_inputs> &D, |
| 55 | const Eigen::Matrix<Scalar, number_of_inputs, 1> &U_max, |
James Kuszmaul | 03be124 | 2020-02-21 14:52:04 -0800 | [diff] [blame] | 56 | const Eigen::Matrix<Scalar, number_of_inputs, 1> &U_min, |
Ravago Jones | c471ebe | 2023-07-05 20:37:00 -0700 | [diff] [blame] | 57 | const Eigen::Matrix<Scalar, number_of_inputs, number_of_states> |
| 58 | &U_limit_coefficient, |
| 59 | const Eigen::Matrix<Scalar, number_of_inputs, 1> &U_limit_constant, |
Austin Schuh | b39f452 | 2022-03-27 13:29:42 -0700 | [diff] [blame] | 60 | const std::chrono::nanoseconds dt, size_t delayed_u) |
Austin Schuh | 64433f1 | 2022-02-21 19:40:38 -0800 | [diff] [blame] | 61 | : A(A), |
| 62 | B(B), |
| 63 | C(C), |
| 64 | D(D), |
| 65 | U_min(U_min), |
| 66 | U_max(U_max), |
Ravago Jones | c471ebe | 2023-07-05 20:37:00 -0700 | [diff] [blame] | 67 | U_limit_coefficient(U_limit_coefficient), |
| 68 | U_limit_constant(U_limit_constant), |
Austin Schuh | 64433f1 | 2022-02-21 19:40:38 -0800 | [diff] [blame] | 69 | dt(dt), |
| 70 | delayed_u(delayed_u) {} |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 71 | |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 72 | const Eigen::Matrix<Scalar, number_of_states, number_of_states> A; |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 73 | const Eigen::Matrix<Scalar, number_of_states, number_of_inputs> B; |
| 74 | const Eigen::Matrix<Scalar, number_of_outputs, number_of_states> C; |
| 75 | const Eigen::Matrix<Scalar, number_of_outputs, number_of_inputs> D; |
| 76 | const Eigen::Matrix<Scalar, number_of_inputs, 1> U_min; |
| 77 | const Eigen::Matrix<Scalar, number_of_inputs, 1> U_max; |
Ravago Jones | c471ebe | 2023-07-05 20:37:00 -0700 | [diff] [blame] | 78 | const Eigen::Matrix<Scalar, number_of_inputs, number_of_states> |
| 79 | U_limit_coefficient; |
| 80 | const Eigen::Matrix<Scalar, number_of_inputs, 1> U_limit_constant; |
James Kuszmaul | 03be124 | 2020-02-21 14:52:04 -0800 | [diff] [blame] | 81 | const std::chrono::nanoseconds dt; |
Austin Schuh | 64433f1 | 2022-02-21 19:40:38 -0800 | [diff] [blame] | 82 | |
| 83 | // If true, this adds a single cycle output delay model to the plant. This is |
| 84 | // useful for modeling a control loop cycle where you sample, compute, and |
| 85 | // then queue the outputs to be ready to be executed when the next cycle |
| 86 | // happens. |
Austin Schuh | b39f452 | 2022-03-27 13:29:42 -0700 | [diff] [blame] | 87 | const size_t delayed_u; |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 88 | }; |
| 89 | |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 90 | template <int number_of_states, int number_of_inputs, int number_of_outputs, |
| 91 | typename Scalar = double> |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 92 | class StateFeedbackPlant { |
| 93 | public: |
| 94 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW; |
Brian Silverman | 0a151c9 | 2014-05-02 15:28:44 -0700 | [diff] [blame] | 95 | |
| 96 | StateFeedbackPlant( |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 97 | ::std::vector<::std::unique_ptr<StateFeedbackPlantCoefficients< |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 98 | number_of_states, number_of_inputs, number_of_outputs, Scalar>>> |
Austin Schuh | b02bf5b | 2021-07-31 21:28:21 -0700 | [diff] [blame] | 99 | &&coefficients) |
| 100 | : coefficients_(::std::move(coefficients)), index_(0) { |
Austin Schuh | b39f452 | 2022-03-27 13:29:42 -0700 | [diff] [blame] | 101 | if (coefficients_.size() > 1u) { |
| 102 | for (size_t i = 1; i < coefficients_.size(); ++i) { |
| 103 | if (coefficients_[i]->delayed_u != coefficients_[0]->delayed_u) { |
| 104 | abort(); |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | last_U_ = Eigen::Matrix<Scalar, number_of_inputs, Eigen::Dynamic>( |
| 109 | number_of_inputs, |
| 110 | std::max(static_cast<size_t>(1u), coefficients_[0]->delayed_u)); |
Brian Silverman | 0a151c9 | 2014-05-02 15:28:44 -0700 | [diff] [blame] | 111 | Reset(); |
| 112 | } |
| 113 | |
Tyler Chatow | 6738c36 | 2019-02-16 14:12:30 -0800 | [diff] [blame] | 114 | StateFeedbackPlant(StateFeedbackPlant &&other) : index_(other.index_) { |
Brian Silverman | 0a151c9 | 2014-05-02 15:28:44 -0700 | [diff] [blame] | 115 | ::std::swap(coefficients_, other.coefficients_); |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 116 | X_.swap(other.X_); |
| 117 | Y_.swap(other.Y_); |
Austin Schuh | 64433f1 | 2022-02-21 19:40:38 -0800 | [diff] [blame] | 118 | last_U_.swap(other.last_U_); |
Brian Silverman | 0a151c9 | 2014-05-02 15:28:44 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Austin Schuh | 1a38796 | 2015-01-31 16:36:20 -0800 | [diff] [blame] | 121 | virtual ~StateFeedbackPlant() {} |
Brian Silverman | 0a151c9 | 2014-05-02 15:28:44 -0700 | [diff] [blame] | 122 | |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 123 | const Eigen::Matrix<Scalar, number_of_states, number_of_states> &A() const { |
Austin Schuh | 64f17a5 | 2017-02-25 14:41:58 -0800 | [diff] [blame] | 124 | return coefficients().A; |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 125 | } |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 126 | Scalar A(int i, int j) const { return A()(i, j); } |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 127 | const Eigen::Matrix<Scalar, number_of_states, number_of_inputs> &B() const { |
Austin Schuh | 64f17a5 | 2017-02-25 14:41:58 -0800 | [diff] [blame] | 128 | return coefficients().B; |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 129 | } |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 130 | Scalar B(int i, int j) const { return B()(i, j); } |
| 131 | const Eigen::Matrix<Scalar, number_of_outputs, number_of_states> &C() const { |
Austin Schuh | 64f17a5 | 2017-02-25 14:41:58 -0800 | [diff] [blame] | 132 | return coefficients().C; |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 133 | } |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 134 | Scalar C(int i, int j) const { return C()(i, j); } |
| 135 | const Eigen::Matrix<Scalar, number_of_outputs, number_of_inputs> &D() const { |
Austin Schuh | 64f17a5 | 2017-02-25 14:41:58 -0800 | [diff] [blame] | 136 | return coefficients().D; |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 137 | } |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 138 | Scalar D(int i, int j) const { return D()(i, j); } |
| 139 | const Eigen::Matrix<Scalar, number_of_inputs, 1> &U_min() const { |
Austin Schuh | 64f17a5 | 2017-02-25 14:41:58 -0800 | [diff] [blame] | 140 | return coefficients().U_min; |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 141 | } |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 142 | Scalar U_min(int i, int j) const { return U_min()(i, j); } |
| 143 | const Eigen::Matrix<Scalar, number_of_inputs, 1> &U_max() const { |
Austin Schuh | 64f17a5 | 2017-02-25 14:41:58 -0800 | [diff] [blame] | 144 | return coefficients().U_max; |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 145 | } |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 146 | Scalar U_max(int i, int j = 0) const { return U_max()(i, j); } |
Austin Schuh | 50e3dca | 2023-07-23 14:34:27 -0700 | [diff] [blame] | 147 | const Eigen::Matrix<Scalar, number_of_inputs, number_of_states> & |
| 148 | U_limit_coefficient() const { |
Ravago Jones | c471ebe | 2023-07-05 20:37:00 -0700 | [diff] [blame] | 149 | return coefficients().U_limit_coefficient; |
| 150 | } |
| 151 | Scalar U_limit_coefficient(int i, int j) const { |
| 152 | return U_limit_coefficient()(i, j); |
| 153 | } |
| 154 | const Eigen::Matrix<Scalar, number_of_inputs, 1> &U_limit_constant() const { |
| 155 | return coefficients().U_limit_constant; |
| 156 | } |
| 157 | Scalar U_limit_constant(int i, int j = 0) const { |
| 158 | return U_limit_constant()(i, j); |
| 159 | } |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 160 | |
Austin Schuh | 43b9ae9 | 2020-02-29 23:08:38 -0800 | [diff] [blame] | 161 | const std::chrono::nanoseconds dt() const { return coefficients().dt; } |
| 162 | |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 163 | const Eigen::Matrix<Scalar, number_of_states, 1> &X() const { return X_; } |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 164 | Scalar X(int i, int j = 0) const { return X()(i, j); } |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 165 | const Eigen::Matrix<Scalar, number_of_outputs, 1> &Y() const { return Y_; } |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 166 | Scalar Y(int i, int j = 0) const { return Y()(i, j); } |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 167 | |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 168 | Eigen::Matrix<Scalar, number_of_states, 1> &mutable_X() { return X_; } |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 169 | Scalar &mutable_X(int i, int j = 0) { return mutable_X()(i, j); } |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 170 | Eigen::Matrix<Scalar, number_of_outputs, 1> &mutable_Y() { return Y_; } |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 171 | Scalar &mutable_Y(int i, int j = 0) { return mutable_Y()(i, j); } |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 172 | |
James Kuszmaul | 109ed8d | 2019-02-17 21:41:04 -0800 | [diff] [blame] | 173 | size_t coefficients_size() const { return coefficients_.size(); } |
| 174 | |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 175 | const StateFeedbackPlantCoefficients<number_of_states, number_of_inputs, |
Austin Schuh | 50e3dca | 2023-07-23 14:34:27 -0700 | [diff] [blame] | 176 | number_of_outputs, Scalar> & |
| 177 | coefficients(int index) const { |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 178 | return *coefficients_[index]; |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 181 | const StateFeedbackPlantCoefficients<number_of_states, number_of_inputs, |
Austin Schuh | 50e3dca | 2023-07-23 14:34:27 -0700 | [diff] [blame] | 182 | number_of_outputs, Scalar> & |
| 183 | coefficients() const { |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 184 | return *coefficients_[index_]; |
| 185 | } |
| 186 | |
| 187 | int index() const { return index_; } |
| 188 | void set_index(int index) { |
| 189 | assert(index >= 0); |
| 190 | assert(index < static_cast<int>(coefficients_.size())); |
| 191 | index_ = index; |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | void Reset() { |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 195 | X_.setZero(); |
| 196 | Y_.setZero(); |
Austin Schuh | 64433f1 | 2022-02-21 19:40:38 -0800 | [diff] [blame] | 197 | last_U_.setZero(); |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 198 | } |
| 199 | |
Austin Schuh | 849f003 | 2013-03-03 23:59:53 -0800 | [diff] [blame] | 200 | // Assert that U is within the hardware range. |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 201 | virtual void CheckU(const Eigen::Matrix<Scalar, number_of_inputs, 1> &U) { |
Brian Silverman | 5808bcb | 2014-09-14 21:40:43 -0400 | [diff] [blame] | 202 | for (int i = 0; i < kNumInputs; ++i) { |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 203 | if (U(i, 0) > U_max(i, 0) + static_cast<Scalar>(0.00001) || |
| 204 | U(i, 0) < U_min(i, 0) - static_cast<Scalar>(0.00001)) { |
Brian Silverman | 6260c09 | 2018-01-14 15:21:36 -0800 | [diff] [blame] | 205 | #if defined(__linux__) |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 206 | AOS_LOG(FATAL, "U out of range\n"); |
Brian Silverman | 6260c09 | 2018-01-14 15:21:36 -0800 | [diff] [blame] | 207 | #else |
| 208 | abort(); |
| 209 | #endif |
Austin Schuh | 66c1988 | 2017-02-25 13:36:28 -0800 | [diff] [blame] | 210 | } |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 211 | } |
| 212 | } |
Austin Schuh | 849f003 | 2013-03-03 23:59:53 -0800 | [diff] [blame] | 213 | |
Austin Schuh | b39f452 | 2022-03-27 13:29:42 -0700 | [diff] [blame] | 214 | const Eigen::Matrix<Scalar, number_of_inputs, 1> last_U( |
| 215 | size_t index = 0) const { |
| 216 | return last_U_.template block<number_of_inputs, 1>(0, index); |
| 217 | } |
| 218 | |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 219 | // Computes the new X and Y given the control input. |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 220 | void Update(const Eigen::Matrix<Scalar, number_of_inputs, 1> &U) { |
Austin Schuh | 849f003 | 2013-03-03 23:59:53 -0800 | [diff] [blame] | 221 | // Powers outside of the range are more likely controller bugs than things |
| 222 | // that the plant should deal with. |
Austin Schuh | 66c1988 | 2017-02-25 13:36:28 -0800 | [diff] [blame] | 223 | CheckU(U); |
Austin Schuh | b39f452 | 2022-03-27 13:29:42 -0700 | [diff] [blame] | 224 | if (coefficients().delayed_u > 0) { |
| 225 | #if defined(__linux__) |
| 226 | DCHECK_EQ(static_cast<ssize_t>(coefficients().delayed_u), last_U_.cols()); |
| 227 | #endif |
| 228 | X_ = Update(X(), last_U(coefficients().delayed_u - 1)); |
| 229 | UpdateY(last_U(coefficients().delayed_u - 1)); |
| 230 | for (int i = coefficients().delayed_u; i > 1; --i) { |
| 231 | last_U_.template block<number_of_inputs, 1>(0, i - 1) = |
| 232 | last_U_.template block<number_of_inputs, 1>(0, i - 2); |
| 233 | } |
| 234 | last_U_.template block<number_of_inputs, 1>(0, 0) = U; |
Austin Schuh | 64433f1 | 2022-02-21 19:40:38 -0800 | [diff] [blame] | 235 | } else { |
| 236 | X_ = Update(X(), U); |
| 237 | UpdateY(U); |
| 238 | } |
Austin Schuh | 01c7b25 | 2017-03-05 00:59:31 -0800 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | // Computes the new Y given the control input. |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 242 | void UpdateY(const Eigen::Matrix<Scalar, number_of_inputs, 1> &U) { |
Austin Schuh | 66c1988 | 2017-02-25 13:36:28 -0800 | [diff] [blame] | 243 | Y_ = C() * X() + D() * U; |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 244 | } |
| 245 | |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 246 | Eigen::Matrix<Scalar, number_of_states, 1> Update( |
| 247 | const Eigen::Matrix<Scalar, number_of_states, 1> X, |
| 248 | const Eigen::Matrix<Scalar, number_of_inputs, 1> &U) const { |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 249 | return A() * X + B() * U; |
| 250 | } |
| 251 | |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 252 | protected: |
| 253 | // these are accessible from non-templated subclasses |
Austin Schuh | b1cdb38 | 2013-03-01 22:53:52 -0800 | [diff] [blame] | 254 | static const int kNumStates = number_of_states; |
| 255 | static const int kNumOutputs = number_of_outputs; |
| 256 | static const int kNumInputs = number_of_inputs; |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 257 | |
| 258 | private: |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 259 | Eigen::Matrix<Scalar, number_of_states, 1> X_; |
| 260 | Eigen::Matrix<Scalar, number_of_outputs, 1> Y_; |
Austin Schuh | b39f452 | 2022-03-27 13:29:42 -0700 | [diff] [blame] | 261 | Eigen::Matrix<Scalar, number_of_inputs, Eigen::Dynamic> last_U_; |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 262 | |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 263 | ::std::vector<::std::unique_ptr<StateFeedbackPlantCoefficients< |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 264 | number_of_states, number_of_inputs, number_of_outputs, Scalar>>> |
Austin Schuh | 64f17a5 | 2017-02-25 14:41:58 -0800 | [diff] [blame] | 265 | coefficients_; |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 266 | |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 267 | int index_; |
Brian Silverman | 0a151c9 | 2014-05-02 15:28:44 -0700 | [diff] [blame] | 268 | |
| 269 | DISALLOW_COPY_AND_ASSIGN(StateFeedbackPlant); |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 270 | }; |
| 271 | |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 272 | // A container for all the controller coefficients. |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 273 | template <int number_of_states, int number_of_inputs, int number_of_outputs, |
| 274 | typename Scalar = double> |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 275 | struct StateFeedbackControllerCoefficients final { |
Austin Schuh | 9644e1c | 2013-03-12 00:40:36 -0700 | [diff] [blame] | 276 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW; |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 277 | |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 278 | const Eigen::Matrix<Scalar, number_of_inputs, number_of_states> K; |
| 279 | const Eigen::Matrix<Scalar, number_of_inputs, number_of_states> Kff; |
Austin Schuh | 9644e1c | 2013-03-12 00:40:36 -0700 | [diff] [blame] | 280 | |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 281 | StateFeedbackControllerCoefficients( |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 282 | const Eigen::Matrix<Scalar, number_of_inputs, number_of_states> &K, |
| 283 | const Eigen::Matrix<Scalar, number_of_inputs, number_of_states> &Kff) |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 284 | : K(K), Kff(Kff) {} |
| 285 | }; |
| 286 | |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 287 | template <int number_of_states, int number_of_inputs, int number_of_outputs, |
| 288 | typename Scalar = double> |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 289 | class StateFeedbackController { |
| 290 | public: |
| 291 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW; |
| 292 | |
| 293 | explicit StateFeedbackController( |
| 294 | ::std::vector<::std::unique_ptr<StateFeedbackControllerCoefficients< |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 295 | number_of_states, number_of_inputs, number_of_outputs, Scalar>>> |
Austin Schuh | b02bf5b | 2021-07-31 21:28:21 -0700 | [diff] [blame] | 296 | &&controllers) |
| 297 | : coefficients_(::std::move(controllers)) {} |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 298 | |
| 299 | StateFeedbackController(StateFeedbackController &&other) |
| 300 | : index_(other.index_) { |
| 301 | ::std::swap(coefficients_, other.coefficients_); |
| 302 | } |
| 303 | |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 304 | const Eigen::Matrix<Scalar, number_of_inputs, number_of_states> &K() const { |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 305 | return coefficients().K; |
| 306 | } |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 307 | Scalar K(int i, int j) const { return K()(i, j); } |
| 308 | const Eigen::Matrix<Scalar, number_of_inputs, number_of_states> &Kff() const { |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 309 | return coefficients().Kff; |
| 310 | } |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 311 | Scalar Kff(int i, int j) const { return Kff()(i, j); } |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 312 | |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 313 | void Reset() {} |
| 314 | |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 315 | // Sets the current controller to be index, clamped to be within range. |
| 316 | void set_index(int index) { |
| 317 | if (index < 0) { |
| 318 | index_ = 0; |
| 319 | } else if (index >= static_cast<int>(coefficients_.size())) { |
| 320 | index_ = static_cast<int>(coefficients_.size()) - 1; |
| 321 | } else { |
| 322 | index_ = index; |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | int index() const { return index_; } |
| 327 | |
| 328 | const StateFeedbackControllerCoefficients<number_of_states, number_of_inputs, |
Austin Schuh | 50e3dca | 2023-07-23 14:34:27 -0700 | [diff] [blame] | 329 | number_of_outputs, Scalar> & |
| 330 | coefficients(int index) const { |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 331 | return *coefficients_[index]; |
| 332 | } |
| 333 | |
| 334 | const StateFeedbackControllerCoefficients<number_of_states, number_of_inputs, |
Austin Schuh | 50e3dca | 2023-07-23 14:34:27 -0700 | [diff] [blame] | 335 | number_of_outputs, Scalar> & |
| 336 | coefficients() const { |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 337 | return *coefficients_[index_]; |
| 338 | } |
| 339 | |
| 340 | private: |
| 341 | int index_ = 0; |
| 342 | ::std::vector<::std::unique_ptr<StateFeedbackControllerCoefficients< |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 343 | number_of_states, number_of_inputs, number_of_outputs, Scalar>>> |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 344 | coefficients_; |
| 345 | }; |
| 346 | |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 347 | // A container for all the observer coefficients. |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 348 | template <int number_of_states, int number_of_inputs, int number_of_outputs, |
| 349 | typename Scalar = double> |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 350 | struct StateFeedbackObserverCoefficients final { |
| 351 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW; |
| 352 | |
Sabina Davis | 3922dfa | 2018-02-10 23:10:05 -0800 | [diff] [blame] | 353 | const Eigen::Matrix<Scalar, number_of_states, number_of_outputs> KalmanGain; |
James Kuszmaul | 4d752d5 | 2019-02-09 17:27:55 -0800 | [diff] [blame] | 354 | const Eigen::Matrix<Scalar, number_of_states, number_of_states> Q; |
| 355 | const Eigen::Matrix<Scalar, number_of_outputs, number_of_outputs> R; |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 356 | |
Austin Schuh | 64433f1 | 2022-02-21 19:40:38 -0800 | [diff] [blame] | 357 | // If true, this adds a single cycle output delay model to the plant. This is |
| 358 | // useful for modeling a control loop cycle where you sample, compute, and |
| 359 | // then queue the outputs to be ready to be executed when the next cycle |
| 360 | // happens. |
Austin Schuh | b39f452 | 2022-03-27 13:29:42 -0700 | [diff] [blame] | 361 | const size_t delayed_u; |
Austin Schuh | 64433f1 | 2022-02-21 19:40:38 -0800 | [diff] [blame] | 362 | |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 363 | StateFeedbackObserverCoefficients( |
Tyler Chatow | 6738c36 | 2019-02-16 14:12:30 -0800 | [diff] [blame] | 364 | const Eigen::Matrix<Scalar, number_of_states, number_of_outputs> |
| 365 | &KalmanGain, |
James Kuszmaul | 4d752d5 | 2019-02-09 17:27:55 -0800 | [diff] [blame] | 366 | const Eigen::Matrix<Scalar, number_of_states, number_of_states> &Q, |
Austin Schuh | 64433f1 | 2022-02-21 19:40:38 -0800 | [diff] [blame] | 367 | const Eigen::Matrix<Scalar, number_of_outputs, number_of_outputs> &R, |
Austin Schuh | b39f452 | 2022-03-27 13:29:42 -0700 | [diff] [blame] | 368 | size_t delayed_u) |
Austin Schuh | 64433f1 | 2022-02-21 19:40:38 -0800 | [diff] [blame] | 369 | : KalmanGain(KalmanGain), Q(Q), R(R), delayed_u(delayed_u) {} |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 370 | }; |
| 371 | |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 372 | template <int number_of_states, int number_of_inputs, int number_of_outputs, |
| 373 | typename Scalar = double> |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 374 | class StateFeedbackObserver { |
| 375 | public: |
| 376 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW; |
| 377 | |
| 378 | explicit StateFeedbackObserver( |
| 379 | ::std::vector<::std::unique_ptr<StateFeedbackObserverCoefficients< |
Tyler Chatow | 6738c36 | 2019-02-16 14:12:30 -0800 | [diff] [blame] | 380 | number_of_states, number_of_inputs, number_of_outputs, Scalar>>> |
Austin Schuh | b02bf5b | 2021-07-31 21:28:21 -0700 | [diff] [blame] | 381 | &&observers) |
Austin Schuh | b39f452 | 2022-03-27 13:29:42 -0700 | [diff] [blame] | 382 | : coefficients_(::std::move(observers)) { |
| 383 | last_U_ = Eigen::Matrix<Scalar, number_of_inputs, Eigen::Dynamic>( |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame] | 384 | number_of_inputs, |
| 385 | std::max(static_cast<size_t>(1u), coefficients().delayed_u)); |
Austin Schuh | b39f452 | 2022-03-27 13:29:42 -0700 | [diff] [blame] | 386 | } |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 387 | |
| 388 | StateFeedbackObserver(StateFeedbackObserver &&other) |
Austin Schuh | 64433f1 | 2022-02-21 19:40:38 -0800 | [diff] [blame] | 389 | : X_hat_(other.X_hat_), last_U_(other.last_U_), index_(other.index_) { |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 390 | ::std::swap(coefficients_, other.coefficients_); |
| 391 | } |
| 392 | |
Tyler Chatow | 6738c36 | 2019-02-16 14:12:30 -0800 | [diff] [blame] | 393 | const Eigen::Matrix<Scalar, number_of_states, number_of_outputs> &KalmanGain() |
| 394 | const { |
Sabina Davis | 3922dfa | 2018-02-10 23:10:05 -0800 | [diff] [blame] | 395 | return coefficients().KalmanGain; |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 396 | } |
Sabina Davis | 3922dfa | 2018-02-10 23:10:05 -0800 | [diff] [blame] | 397 | Scalar KalmanGain(int i, int j) const { return KalmanGain()(i, j); } |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 398 | |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 399 | const Eigen::Matrix<Scalar, number_of_states, 1> &X_hat() const { |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 400 | return X_hat_; |
| 401 | } |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 402 | Eigen::Matrix<Scalar, number_of_states, 1> &mutable_X_hat() { return X_hat_; } |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 403 | |
Austin Schuh | b39f452 | 2022-03-27 13:29:42 -0700 | [diff] [blame] | 404 | const Eigen::Matrix<Scalar, number_of_inputs, 1> last_U( |
| 405 | size_t index = 0) const { |
| 406 | return last_U_.template block<number_of_inputs, 1>(0, index); |
Austin Schuh | 482a914 | 2022-02-23 16:54:39 -0800 | [diff] [blame] | 407 | } |
| 408 | |
Austin Schuh | 6501d23 | 2017-11-23 20:35:27 -0800 | [diff] [blame] | 409 | void Reset(StateFeedbackPlant<number_of_states, number_of_inputs, |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 410 | number_of_outputs, Scalar> * /*loop*/) { |
Austin Schuh | 3ad5ed8 | 2017-02-25 21:36:19 -0800 | [diff] [blame] | 411 | X_hat_.setZero(); |
Austin Schuh | 64433f1 | 2022-02-21 19:40:38 -0800 | [diff] [blame] | 412 | last_U_.setZero(); |
Austin Schuh | 3ad5ed8 | 2017-02-25 21:36:19 -0800 | [diff] [blame] | 413 | } |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 414 | |
Austin Schuh | 6501d23 | 2017-11-23 20:35:27 -0800 | [diff] [blame] | 415 | void Predict(StateFeedbackPlant<number_of_states, number_of_inputs, |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 416 | number_of_outputs, Scalar> *plant, |
| 417 | const Eigen::Matrix<Scalar, number_of_inputs, 1> &new_u, |
Austin Schuh | 6501d23 | 2017-11-23 20:35:27 -0800 | [diff] [blame] | 418 | ::std::chrono::nanoseconds /*dt*/) { |
Austin Schuh | b39f452 | 2022-03-27 13:29:42 -0700 | [diff] [blame] | 419 | if (plant->coefficients().delayed_u > 0) { |
| 420 | mutable_X_hat() = |
| 421 | plant->Update(X_hat(), last_U(coefficients().delayed_u - 1)); |
| 422 | for (int i = coefficients().delayed_u; i > 1; --i) { |
| 423 | last_U_.template block<number_of_inputs, 1>(0, i - 1) = |
| 424 | last_U_.template block<number_of_inputs, 1>(0, i - 2); |
| 425 | } |
| 426 | last_U_.template block<number_of_inputs, 1>(0, 0) = new_u; |
Austin Schuh | 64433f1 | 2022-02-21 19:40:38 -0800 | [diff] [blame] | 427 | } else { |
| 428 | mutable_X_hat() = plant->Update(X_hat(), new_u); |
| 429 | } |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 430 | } |
| 431 | |
Austin Schuh | 6501d23 | 2017-11-23 20:35:27 -0800 | [diff] [blame] | 432 | void Correct(const StateFeedbackPlant<number_of_states, number_of_inputs, |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 433 | number_of_outputs, Scalar> &plant, |
| 434 | const Eigen::Matrix<Scalar, number_of_inputs, 1> &U, |
| 435 | const Eigen::Matrix<Scalar, number_of_outputs, 1> &Y) { |
Tyler Chatow | 6738c36 | 2019-02-16 14:12:30 -0800 | [diff] [blame] | 436 | mutable_X_hat() += KalmanGain() * (Y - plant.C() * X_hat() - plant.D() * U); |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 437 | } |
| 438 | |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 439 | // Sets the current controller to be index, clamped to be within range. |
| 440 | void set_index(int index) { |
| 441 | if (index < 0) { |
| 442 | index_ = 0; |
| 443 | } else if (index >= static_cast<int>(coefficients_.size())) { |
| 444 | index_ = static_cast<int>(coefficients_.size()) - 1; |
| 445 | } else { |
| 446 | index_ = index; |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | int index() const { return index_; } |
| 451 | |
| 452 | const StateFeedbackObserverCoefficients<number_of_states, number_of_inputs, |
Austin Schuh | 50e3dca | 2023-07-23 14:34:27 -0700 | [diff] [blame] | 453 | number_of_outputs, Scalar> & |
| 454 | coefficients(int index) const { |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 455 | return *coefficients_[index]; |
| 456 | } |
| 457 | |
| 458 | const StateFeedbackObserverCoefficients<number_of_states, number_of_inputs, |
Austin Schuh | 50e3dca | 2023-07-23 14:34:27 -0700 | [diff] [blame] | 459 | number_of_outputs, Scalar> & |
| 460 | coefficients() const { |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 461 | return *coefficients_[index_]; |
| 462 | } |
| 463 | |
| 464 | private: |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 465 | // Internal state estimate. |
James Kuszmaul | eeb98e9 | 2024-01-14 22:15:32 -0800 | [diff] [blame^] | 466 | Eigen::Matrix<Scalar, number_of_states, 1> X_hat_ = |
| 467 | Eigen::Matrix<Scalar, number_of_states, 1>::Zero(); |
Austin Schuh | b39f452 | 2022-03-27 13:29:42 -0700 | [diff] [blame] | 468 | Eigen::Matrix<Scalar, number_of_inputs, Eigen::Dynamic> last_U_; |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 469 | |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 470 | int index_ = 0; |
| 471 | ::std::vector<::std::unique_ptr<StateFeedbackObserverCoefficients< |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 472 | number_of_states, number_of_inputs, number_of_outputs, Scalar>>> |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 473 | coefficients_; |
Austin Schuh | 9644e1c | 2013-03-12 00:40:36 -0700 | [diff] [blame] | 474 | }; |
| 475 | |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 476 | template <int number_of_states, int number_of_inputs, int number_of_outputs, |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 477 | typename Scalar = double, |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 478 | typename PlantType = StateFeedbackPlant< |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 479 | number_of_states, number_of_inputs, number_of_outputs, Scalar>, |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 480 | typename ObserverType = StateFeedbackObserver< |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 481 | number_of_states, number_of_inputs, number_of_outputs, Scalar>> |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 482 | class StateFeedbackLoop { |
| 483 | public: |
| 484 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW; |
| 485 | |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 486 | explicit StateFeedbackLoop( |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 487 | PlantType &&plant, |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 488 | StateFeedbackController<number_of_states, number_of_inputs, |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 489 | number_of_outputs, Scalar> &&controller, |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 490 | ObserverType &&observer) |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 491 | : plant_(::std::move(plant)), |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 492 | controller_(::std::move(controller)), |
| 493 | observer_(::std::move(observer)) { |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 494 | Reset(); |
| 495 | } |
| 496 | |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 497 | StateFeedbackLoop(StateFeedbackLoop &&other) |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 498 | : plant_(::std::move(other.plant_)), |
| 499 | controller_(::std::move(other.controller_)), |
| 500 | observer_(::std::move(other.observer_)) { |
Austin Schuh | 36f8c4e | 2020-02-29 20:29:41 -0800 | [diff] [blame] | 501 | ff_U_.swap(other.ff_U_); |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 502 | R_.swap(other.R_); |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 503 | next_R_.swap(other.next_R_); |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 504 | U_.swap(other.U_); |
| 505 | U_uncapped_.swap(other.U_uncapped_); |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 506 | } |
| 507 | |
Austin Schuh | 1a38796 | 2015-01-31 16:36:20 -0800 | [diff] [blame] | 508 | virtual ~StateFeedbackLoop() {} |
Brian Silverman | 0a151c9 | 2014-05-02 15:28:44 -0700 | [diff] [blame] | 509 | |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 510 | const Eigen::Matrix<Scalar, number_of_states, 1> &X_hat() const { |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 511 | return observer().X_hat(); |
Austin Schuh | 9644e1c | 2013-03-12 00:40:36 -0700 | [diff] [blame] | 512 | } |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 513 | Scalar X_hat(int i, int j = 0) const { return X_hat()(i, j); } |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 514 | const Eigen::Matrix<Scalar, number_of_states, 1> &R() const { return R_; } |
Austin Schuh | 95771d9 | 2021-01-23 14:42:25 -0800 | [diff] [blame] | 515 | Scalar R(int i, int j = 0) const { return R()(i, j); } |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 516 | const Eigen::Matrix<Scalar, number_of_states, 1> &next_R() const { |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 517 | return next_R_; |
| 518 | } |
Austin Schuh | 95771d9 | 2021-01-23 14:42:25 -0800 | [diff] [blame] | 519 | Scalar next_R(int i, int j = 0) const { return next_R()(i, j); } |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 520 | const Eigen::Matrix<Scalar, number_of_inputs, 1> &U() const { return U_; } |
Austin Schuh | 95771d9 | 2021-01-23 14:42:25 -0800 | [diff] [blame] | 521 | Scalar U(int i, int j = 0) const { return U()(i, j); } |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 522 | const Eigen::Matrix<Scalar, number_of_inputs, 1> &U_uncapped() const { |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 523 | return U_uncapped_; |
Austin Schuh | 9644e1c | 2013-03-12 00:40:36 -0700 | [diff] [blame] | 524 | } |
Austin Schuh | 95771d9 | 2021-01-23 14:42:25 -0800 | [diff] [blame] | 525 | Scalar U_uncapped(int i, int j = 0) const { return U_uncapped()(i, j); } |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 526 | const Eigen::Matrix<Scalar, number_of_inputs, 1> &ff_U() const { |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 527 | return ff_U_; |
| 528 | } |
Austin Schuh | 95771d9 | 2021-01-23 14:42:25 -0800 | [diff] [blame] | 529 | Scalar ff_U(int i, int j = 0) const { return ff_U()(i, j); } |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 530 | |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 531 | Eigen::Matrix<Scalar, number_of_states, 1> &mutable_X_hat() { |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 532 | return observer_.mutable_X_hat(); |
| 533 | } |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 534 | Scalar &mutable_X_hat(int i, int j = 0) { return mutable_X_hat()(i, j); } |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 535 | Eigen::Matrix<Scalar, number_of_states, 1> &mutable_R() { return R_; } |
Austin Schuh | 95771d9 | 2021-01-23 14:42:25 -0800 | [diff] [blame] | 536 | Scalar &mutable_R(int i, int j = 0) { return mutable_R()(i, j); } |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 537 | Eigen::Matrix<Scalar, number_of_states, 1> &mutable_next_R() { |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 538 | return next_R_; |
| 539 | } |
Austin Schuh | 95771d9 | 2021-01-23 14:42:25 -0800 | [diff] [blame] | 540 | Scalar &mutable_next_R(int i, int j = 0) { return mutable_next_R()(i, j); } |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 541 | Eigen::Matrix<Scalar, number_of_inputs, 1> &mutable_U() { return U_; } |
Austin Schuh | 95771d9 | 2021-01-23 14:42:25 -0800 | [diff] [blame] | 542 | Scalar &mutable_U(int i, int j = 0) { return mutable_U()(i, j); } |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 543 | Eigen::Matrix<Scalar, number_of_inputs, 1> &mutable_U_uncapped() { |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 544 | return U_uncapped_; |
| 545 | } |
Austin Schuh | 95771d9 | 2021-01-23 14:42:25 -0800 | [diff] [blame] | 546 | Scalar &mutable_U_uncapped(int i, int j = 0) { |
Brian Silverman | a21c3a2 | 2014-06-12 21:49:15 -0700 | [diff] [blame] | 547 | return mutable_U_uncapped()(i, j); |
| 548 | } |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 549 | |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 550 | const PlantType &plant() const { return plant_; } |
Austin Schuh | 3ad5ed8 | 2017-02-25 21:36:19 -0800 | [diff] [blame] | 551 | PlantType *mutable_plant() { return &plant_; } |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 552 | |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 553 | const StateFeedbackController<number_of_states, number_of_inputs, |
Austin Schuh | 50e3dca | 2023-07-23 14:34:27 -0700 | [diff] [blame] | 554 | number_of_outputs, Scalar> & |
| 555 | controller() const { |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 556 | return controller_; |
Austin Schuh | 9644e1c | 2013-03-12 00:40:36 -0700 | [diff] [blame] | 557 | } |
| 558 | |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 559 | const ObserverType &observer() const { return observer_; } |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 560 | |
Austin Schuh | 9644e1c | 2013-03-12 00:40:36 -0700 | [diff] [blame] | 561 | void Reset() { |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 562 | R_.setZero(); |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 563 | next_R_.setZero(); |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 564 | U_.setZero(); |
| 565 | U_uncapped_.setZero(); |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 566 | ff_U_.setZero(); |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 567 | |
| 568 | plant_.Reset(); |
| 569 | controller_.Reset(); |
Austin Schuh | 6501d23 | 2017-11-23 20:35:27 -0800 | [diff] [blame] | 570 | observer_.Reset(this->mutable_plant()); |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | // If U is outside the hardware range, limit it before the plant tries to use |
| 574 | // it. |
| 575 | virtual void CapU() { |
Ravago Jones | c471ebe | 2023-07-05 20:37:00 -0700 | [diff] [blame] | 576 | // TODO(Ravago): this runs before the state update step, so it's limiting |
| 577 | // the future control based on the old state. This gets even worse when we |
| 578 | // have delayed_u. |
| 579 | Eigen::Matrix<Scalar, number_of_inputs, 1> U_max_computed = |
| 580 | plant().U_limit_coefficient() * plant().X() + |
| 581 | plant().U_limit_constant(); |
| 582 | Eigen::Matrix<Scalar, number_of_inputs, 1> U_min_computed = |
| 583 | plant().U_limit_coefficient() * plant().X() - |
| 584 | plant().U_limit_constant(); |
| 585 | |
| 586 | U_max_computed = U_max_computed.cwiseMin(plant().U_max()); |
| 587 | U_min_computed = U_min_computed.cwiseMax(plant().U_min()); |
| 588 | |
Brian Silverman | 5808bcb | 2014-09-14 21:40:43 -0400 | [diff] [blame] | 589 | for (int i = 0; i < kNumInputs; ++i) { |
Ravago Jones | c471ebe | 2023-07-05 20:37:00 -0700 | [diff] [blame] | 590 | if (U(i, 0) > U_max_computed(i, 0)) { |
| 591 | U_(i, 0) = U_max_computed(i, 0); |
| 592 | } else if (U(i, 0) < U_min_computed(i, 0)) { |
| 593 | U_(i, 0) = U_min_computed(i, 0); |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 594 | } |
| 595 | } |
| 596 | } |
| 597 | |
Austin Schuh | f9286cd | 2014-02-11 00:51:09 -0800 | [diff] [blame] | 598 | // Corrects X_hat given the observation in Y. |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 599 | void Correct(const Eigen::Matrix<Scalar, number_of_outputs, 1> &Y) { |
Austin Schuh | 6501d23 | 2017-11-23 20:35:27 -0800 | [diff] [blame] | 600 | observer_.Correct(this->plant(), U(), Y); |
Austin Schuh | f9286cd | 2014-02-11 00:51:09 -0800 | [diff] [blame] | 601 | } |
| 602 | |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 603 | const Eigen::Matrix<Scalar, number_of_states, 1> error() const { |
Austin Schuh | 3f862bb | 2016-02-27 14:48:05 -0800 | [diff] [blame] | 604 | return R() - X_hat(); |
| 605 | } |
| 606 | |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 607 | // Returns the calculated controller power. |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 608 | virtual const Eigen::Matrix<Scalar, number_of_inputs, 1> ControllerOutput() { |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 609 | // TODO(austin): Should this live in StateSpaceController? |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 610 | ff_U_ = FeedForward(); |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 611 | return controller().K() * error() + ff_U_; |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | // Calculates the feed forwards power. |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 615 | virtual const Eigen::Matrix<Scalar, number_of_inputs, 1> FeedForward() { |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 616 | // TODO(austin): Should this live in StateSpaceController? |
| 617 | return controller().Kff() * (next_R() - plant().A() * R()); |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 618 | } |
| 619 | |
Austin Schuh | 43b9ae9 | 2020-02-29 23:08:38 -0800 | [diff] [blame] | 620 | void UpdateController(bool stop_motors) { |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 621 | if (stop_motors) { |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 622 | U_.setZero(); |
| 623 | U_uncapped_.setZero(); |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 624 | ff_U_.setZero(); |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 625 | } else { |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 626 | U_ = U_uncapped_ = ControllerOutput(); |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 627 | CapU(); |
| 628 | } |
Austin Schuh | 43b9ae9 | 2020-02-29 23:08:38 -0800 | [diff] [blame] | 629 | UpdateFFReference(); |
| 630 | } |
| 631 | |
| 632 | // stop_motors is whether or not to output all 0s. |
| 633 | void Update(bool stop_motors, |
| 634 | ::std::chrono::nanoseconds dt = ::std::chrono::milliseconds(0)) { |
| 635 | UpdateController(stop_motors); |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 636 | |
Austin Schuh | 3ad5ed8 | 2017-02-25 21:36:19 -0800 | [diff] [blame] | 637 | UpdateObserver(U_, dt); |
Austin Schuh | 093535c | 2016-03-05 23:21:00 -0800 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | // Updates R() after any CapU operations happen on U(). |
| 641 | void UpdateFFReference() { |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 642 | ff_U_ -= U_uncapped() - U(); |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 643 | if (!controller().Kff().isZero(0)) { |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 644 | R_ = plant().A() * R() + plant().B() * ff_U_; |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 645 | } |
Ben Fredrickson | 890c3fe | 2014-03-02 00:15:16 +0000 | [diff] [blame] | 646 | } |
| 647 | |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 648 | void UpdateObserver(const Eigen::Matrix<Scalar, number_of_inputs, 1> &new_u, |
Austin Schuh | 3ad5ed8 | 2017-02-25 21:36:19 -0800 | [diff] [blame] | 649 | ::std::chrono::nanoseconds dt) { |
Austin Schuh | 6501d23 | 2017-11-23 20:35:27 -0800 | [diff] [blame] | 650 | observer_.Predict(this->mutable_plant(), new_u, dt); |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 651 | } |
| 652 | |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 653 | // Sets the current controller to be index. |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 654 | void set_index(int index) { |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 655 | plant_.set_index(index); |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 656 | controller_.set_index(index); |
| 657 | observer_.set_index(index); |
Austin Schuh | 9644e1c | 2013-03-12 00:40:36 -0700 | [diff] [blame] | 658 | } |
| 659 | |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 660 | int index() const { return plant_.index(); } |
Austin Schuh | 9644e1c | 2013-03-12 00:40:36 -0700 | [diff] [blame] | 661 | |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 662 | protected: |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 663 | PlantType plant_; |
Austin Schuh | c5fceb8 | 2017-02-25 16:24:12 -0800 | [diff] [blame] | 664 | |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 665 | StateFeedbackController<number_of_states, number_of_inputs, number_of_outputs, |
| 666 | Scalar> |
Austin Schuh | 3250183 | 2017-02-25 18:32:56 -0800 | [diff] [blame] | 667 | controller_; |
| 668 | |
Austin Schuh | e91f14c | 2017-02-25 19:43:57 -0800 | [diff] [blame] | 669 | ObserverType observer_; |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 670 | |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 671 | // These are accessible from non-templated subclasses. |
Austin Schuh | f59b6bc | 2016-03-11 21:26:19 -0800 | [diff] [blame] | 672 | static constexpr int kNumStates = number_of_states; |
| 673 | static constexpr int kNumOutputs = number_of_outputs; |
| 674 | static constexpr int kNumInputs = number_of_inputs; |
| 675 | |
| 676 | // Portion of U which is based on the feed-forwards. |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 677 | Eigen::Matrix<Scalar, number_of_inputs, 1> ff_U_; |
Austin Schuh | 9644e1c | 2013-03-12 00:40:36 -0700 | [diff] [blame] | 678 | |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 679 | private: |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 680 | // Current goal (Used by the feed-back controller). |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 681 | Eigen::Matrix<Scalar, number_of_states, 1> R_; |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 682 | // Goal to go to in the next cycle (Used by Feed-Forward controller.) |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 683 | Eigen::Matrix<Scalar, number_of_states, 1> next_R_; |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 684 | // Computed output after being capped. |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 685 | Eigen::Matrix<Scalar, number_of_inputs, 1> U_; |
Austin Schuh | b6a6d82 | 2016-02-08 00:20:40 -0800 | [diff] [blame] | 686 | // Computed output before being capped. |
Austin Schuh | 20388b6 | 2017-11-23 22:40:46 -0800 | [diff] [blame] | 687 | Eigen::Matrix<Scalar, number_of_inputs, 1> U_uncapped_; |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 688 | |
Brian Silverman | 0a151c9 | 2014-05-02 15:28:44 -0700 | [diff] [blame] | 689 | DISALLOW_COPY_AND_ASSIGN(StateFeedbackLoop); |
Austin Schuh | dc1c84a | 2013-02-23 16:33:10 -0800 | [diff] [blame] | 690 | }; |
| 691 | |
Brian Silverman | 273d8a3 | 2014-05-10 22:19:09 -0700 | [diff] [blame] | 692 | #endif // FRC971_CONTROL_LOOPS_STATE_FEEDBACK_LOOP_H_ |