Austin Schuh | 54e5bb5 | 2018-02-19 01:09:18 -0800 | [diff] [blame] | 1 | #ifndef Y2018_CONTROL_LOOPS_SUPERSTRUCTURE_ARM_EKF_H_ |
| 2 | #define Y2018_CONTROL_LOOPS_SUPERSTRUCTURE_ARM_EKF_H_ |
| 3 | |
| 4 | #include "Eigen/Dense" |
| 5 | |
| 6 | namespace y2018 { |
| 7 | namespace control_loops { |
| 8 | namespace superstructure { |
| 9 | namespace arm { |
| 10 | |
| 11 | // An extended kalman filter for the Arm. |
| 12 | // Our states are: |
| 13 | // [theta0, omega0, theta1, omega1, voltage error0, voltage error1] |
| 14 | class EKF { |
| 15 | public: |
| 16 | EKF(); |
| 17 | |
| 18 | // Resets the internal state back to X. Resets the torque disturbance to 0. |
| 19 | void Reset(const ::Eigen::Matrix<double, 4, 1> &X); |
| 20 | // TODO(austin): Offset the internal state when we calibrate. |
| 21 | |
| 22 | // Corrects the state estimate with the provided sensor reading. |
| 23 | void Correct(const ::Eigen::Matrix<double, 2, 1> &Y, double dt); |
| 24 | |
| 25 | // Predicts the next state and covariance given the control input. |
| 26 | void Predict(const ::Eigen::Matrix<double, 2, 1> &U, double dt); |
| 27 | |
| 28 | // Returns the current state and covariance estimates. |
| 29 | const ::Eigen::Matrix<double, 6, 1> &X_hat() const { return X_hat_; } |
| 30 | double X_hat(int i) const { return X_hat_(i); } |
| 31 | const ::Eigen::Matrix<double, 6, 6> &P() const { return P_; } |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 32 | const ::Eigen::Matrix<double, 6, 6> &P_reset() const { return P_reset_; } |
| 33 | const ::Eigen::Matrix<double, 6, 6> &P_half_converged() const { |
| 34 | return P_half_converged_; |
| 35 | } |
| 36 | const ::Eigen::Matrix<double, 6, 6> &P_converged() const { |
| 37 | return P_converged_; |
| 38 | } |
Austin Schuh | 54e5bb5 | 2018-02-19 01:09:18 -0800 | [diff] [blame] | 39 | |
| 40 | private: |
| 41 | ::Eigen::Matrix<double, 6, 1> X_hat_; |
| 42 | ::Eigen::Matrix<double, 6, 6> P_; |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 43 | ::Eigen::Matrix<double, 6, 6> P_half_converged_; |
| 44 | ::Eigen::Matrix<double, 6, 6> P_converged_; |
Austin Schuh | 54e5bb5 | 2018-02-19 01:09:18 -0800 | [diff] [blame] | 45 | ::Eigen::Matrix<double, 6, 6> P_reset_; |
| 46 | }; |
| 47 | |
| 48 | } // namespace arm |
| 49 | } // namespace superstructure |
| 50 | } // namespace control_loops |
| 51 | } // namespace y2018 |
| 52 | |
| 53 | #endif // Y2018_CONTROL_LOOPS_SUPERSTRUCTURE_ARM_EKF_H_ |