blob: 9f453035965a676f3a2edc10ba7895aa8b35e560 [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_; }
32
33 private:
34 ::Eigen::Matrix<double, 6, 1> X_hat_;
35 ::Eigen::Matrix<double, 6, 6> P_;
36 ::Eigen::Matrix<double, 6, 6> P_reset_;
37};
38
39} // namespace arm
40} // namespace superstructure
41} // namespace control_loops
42} // namespace y2018
43
44#endif // Y2018_CONTROL_LOOPS_SUPERSTRUCTURE_ARM_EKF_H_