blob: 9ae8b4760fae4835ca690572de8f5707c3e2ef61 [file] [log] [blame]
Austin Schuh54e5bb52018-02-19 01:09:18 -08001#ifndef Y2018_CONTROL_LOOPS_SUPERSTRUCTURE_ARM_EKF_H_
2#define Y2018_CONTROL_LOOPS_SUPERSTRUCTURE_ARM_EKF_H_
3
4#include "Eigen/Dense"
5
6namespace y2018 {
7namespace control_loops {
8namespace superstructure {
9namespace arm {
10
11// An extended kalman filter for the Arm.
12// Our states are:
13// [theta0, omega0, theta1, omega1, voltage error0, voltage error1]
14class 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 Schuhcb091712018-02-21 20:01:55 -080032 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 Schuh54e5bb52018-02-19 01:09:18 -080039
40 private:
41 ::Eigen::Matrix<double, 6, 1> X_hat_;
42 ::Eigen::Matrix<double, 6, 6> P_;
Austin Schuhcb091712018-02-21 20:01:55 -080043 ::Eigen::Matrix<double, 6, 6> P_half_converged_;
44 ::Eigen::Matrix<double, 6, 6> P_converged_;
Austin Schuh54e5bb52018-02-19 01:09:18 -080045 ::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_