|
| 1 | +/** |
| 2 | + * "THE BEER-WARE LICENSE" (Revision 42): |
| 3 | + * <[email protected]> wrote this file. As long as you retain this notice you |
| 4 | + * can do whatever you want with this stuff. If we meet some day, and you think |
| 5 | + * this stuff is worth it, you can buy me a beer in return. - Robin Lilja |
| 6 | + * |
| 7 | + * @file altitude_kf.h |
| 8 | + * @author Robin Lilja |
| 9 | + * @date 23 Jul 2015 |
| 10 | + */ |
| 11 | + |
| 12 | +#ifndef _ALTITUDE_KF_H_ |
| 13 | +#define _ALTITUDE_KF_H_ |
| 14 | + |
| 15 | +/** |
| 16 | + * A linear Kalman filter estimator of altitude and vertical velocity. |
| 17 | + */ |
| 18 | +class Altitude_KF { |
| 19 | + |
| 20 | +public: |
| 21 | + |
| 22 | + /** |
| 23 | + * Constructor. |
| 24 | + * @param Q_accel covariance of acceleration input signal (σ^2). |
| 25 | + * @param R_altitude covariance of the altitude measurement (σ^2). |
| 26 | + */ |
| 27 | + Altitude_KF(float Q_accel, float R_altitude) { |
| 28 | + |
| 29 | + this->Q_accel = Q_accel; |
| 30 | + this->R_altitude = R_altitude; |
| 31 | + |
| 32 | + h = 0.0f; |
| 33 | + v = 0.0f; |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * Propagate the state. |
| 38 | + * @param acceleration vertical acceleration in Earth frame (positive in the zenith direction) [m/s^2]. |
| 39 | + * @param dt update/sampling period [s]. |
| 40 | + */ |
| 41 | + void propagate(float acceleration, const float dt); |
| 42 | + |
| 43 | + /** |
| 44 | + * State correction update. Use this method if you use multiple sensors measuring the altitude. |
| 45 | + * @param altitude measurement of altitude in Earth frame (positive in the zenith direction) [m]. |
| 46 | + * @param R_altitude covariance of the altitude measurement (σ^2). |
| 47 | + */ |
| 48 | + void update(float altitude, float R_altitude); |
| 49 | + |
| 50 | + /** |
| 51 | + * State correction update. |
| 52 | + * @param altitude measurement of altitude in Earth frame (positive in the zenith direction) [m]. |
| 53 | + */ |
| 54 | + void update(float altitude) { update(altitude, this->R_altitude); }; |
| 55 | + |
| 56 | + /** |
| 57 | + * Estimated vertical height or altitude in Earth frame (positive in the zenith direction) [m]. |
| 58 | + */ |
| 59 | + float h; |
| 60 | + |
| 61 | + /** |
| 62 | + * Estimated vertical velocity (positive in the zenith direction) [m/s]. |
| 63 | + */ |
| 64 | + float v; |
| 65 | + |
| 66 | + /** |
| 67 | + * Accelerometer covariance. |
| 68 | + */ |
| 69 | + float Q_accel; |
| 70 | + |
| 71 | + /** |
| 72 | + * Altitude measurement covariance. |
| 73 | + */ |
| 74 | + float R_altitude; |
| 75 | + |
| 76 | +private: |
| 77 | + |
| 78 | + /** |
| 79 | + * Predicted covariance matrix 'P'. |
| 80 | + */ |
| 81 | + float P[2][2] = |
| 82 | + { |
| 83 | + { 1.0f, 0.0f }, |
| 84 | + { 0.0f, 1.0f } |
| 85 | + }; |
| 86 | + |
| 87 | +}; |
| 88 | + |
| 89 | +#endif /* _ALTITUDE_KF_H_ */ |
0 commit comments