39 #include "generated/airframe.h"
43 #ifndef AHRS_MAG_NOISE_X
44 #define AHRS_MAG_NOISE_X 0.2
45 #define AHRS_MAG_NOISE_Y 0.2
46 #define AHRS_MAG_NOISE_Z 0.2
77 const float P0_a = 1.;
78 const float P0_b = 1e-4;
79 float P0[6][6] = {{ P0_a, 0., 0., 0., 0., 0. },
80 { 0., P0_a, 0., 0., 0., 0. },
81 { 0., 0., P0_a, 0., 0., 0. },
82 { 0., 0., 0., P0_b, 0., 0. },
83 { 0., 0., 0., 0., P0_b, 0. },
84 { 0., 0., 0., 0., 0., P0_b}
131 const float alpha = 0.92;
134 const struct FloatVect3 earth_g = {0., 0., -9.81 };
143 #if AHRS_MAG_UPDATE_ALL_AXES
170 #ifdef AHRS_PROPAGATE_LOW_PASS_RATES
172 const float alpha = 0.1;
174 (1. - alpha), rates, alpha);
196 float F[6][6] = {{ 1., dr, -dq, -
dt, 0., 0. },
197 { -dr, 1., dp, 0., -
dt, 0. },
198 { dq, -dp, 1., 0., 0., -dt },
199 { 0., 0., 0., 1., 0., 0. },
200 { 0., 0., 0., 0., 1., 0. },
201 { 0., 0., 0., 0., 0., 1. }
207 const float dt2 = dt *
dt;
208 const float GQG[6] = {dt2 * 10e-3, dt2 * 10e-3, dt2 * 10e-3, dt2 * 9e-6, dt2 * 9e-6, dt2 * 9e-6 };
209 for (
int i = 0; i < 6; i++) {
231 float H[3][6] = {{ 0., -b_expected.
z, b_expected.
y, 0., 0., 0.},
232 { b_expected.
z, 0., -b_expected.
x, 0., 0., 0.},
233 { -b_expected.
y, b_expected.
x, 0., 0., 0., 0.}
252 MAT_MUL(6, 3, 3, K, tmp2, invS);
257 float I6[6][6] = {{ 1., 0., 0., 0., 0., 0. },
258 { 0., 1., 0., 0., 0., 0. },
259 { 0., 0., 1., 0., 0., 0. },
260 { 0., 0., 0., 1., 0., 0. },
261 { 0., 0., 0., 0., 1., 0. },
262 { 0., 0., 0., 0., 0., 1. }
300 struct FloatVect3 i_h_2d = {i_expected->
y, -i_expected->
x, 0.f};
304 float H[3][6] = {{ 0., 0., b_yaw.
x, 0., 0., 0.},
305 { 0., 0., b_yaw.
y, 0., 0., 0.},
306 { 0., 0., b_yaw.
z, 0., 0., 0.}
325 MAT_MUL(6, 3, 3, K, tmp2, invS);
330 float I6[6][6] = {{ 1., 0., 0., 0., 0., 0. },
331 { 0., 1., 0., 0., 0., 0. },
332 { 0., 0., 1., 0., 0., 0. },
333 { 0., 0., 0., 1., 0., 0. },
334 { 0., 0., 0., 0., 1., 0. },
335 { 0., 0., 0., 0., 0., 1. }
void ahrs_mlkf_propagate(struct FloatRates *gyro, float dt)
struct FloatQuat gibbs_cor
static void propagate_ref(struct FloatRates *gyro, float dt)
static void orientationSetQuat_f(struct OrientationReps *orientation, struct FloatQuat *quat)
Set vehicle body attitude from quaternion (float).
void ahrs_mlkf_update_mag_full(struct FloatVect3 *mag)
Simple matrix helper macros.
void float_quat_comp(struct FloatQuat *a2c, struct FloatQuat *a2b, struct FloatQuat *b2c)
Composition (multiplication) of two quaternions.
struct FloatVect3 mag_noise
static void float_quat_identity(struct FloatQuat *q)
initialises a quaternion to identity
struct FloatRates imu_rate
Rotational velocity in IMU frame.
#define VECT3_DIFF(_c, _a, _b)
#define VECT3_ASSIGN(_a, _x, _y, _z)
Utility functions for floating point AHRS implementations.
#define FLOAT_RATES_ZERO(_r)
void ahrs_mlkf_update_accel(struct FloatVect3 *accel)
void ahrs_mlkf_set_body_to_imu(struct OrientationReps *body_to_imu)
struct FloatRates gyro_bias
#define RATES_SUB(_a, _b)
#define MAT_MUL_T(_i, _k, _j, C, A, B)
Multiplicative linearized Kalman Filter in quaternion formulation.
bool ahrs_mlkf_align(struct FloatRates *lp_gyro, struct FloatVect3 *lp_accel, struct FloatVect3 *lp_mag)
static float float_vect3_norm(struct FloatVect3 *v)
static void update_state_heading(const struct FloatVect3 *i_expected, struct FloatVect3 *b_measured, struct FloatVect3 *noise)
Incorporate one 3D vector measurement, only correcting heading.
static void update_state(const struct FloatVect3 *i_expected, struct FloatVect3 *b_measured, struct FloatVect3 *noise)
Incorporate one 3D vector measurement.
#define FLOAT_RATES_LIN_CMB(_ro, _r1, _s1, _r2, _s2)
void ahrs_mlkf_update_mag(struct FloatVect3 *mag)
Paparazzi floating point algebra.
void ahrs_mlkf_set_body_to_imu_quat(struct FloatQuat *q_b2i)
void float_quat_integrate(struct FloatQuat *q, struct FloatRates *omega, float dt)
in place quaternion integration with constant rotational velocity
void float_quat_vmult(struct FloatVect3 *v_out, struct FloatQuat *q, const struct FloatVect3 *v_in)
rotate 3D vector by quaternion.
static void float_quat_normalize(struct FloatQuat *q)
void ahrs_mlkf_update_mag_2d(struct FloatVect3 *mag)
void ahrs_mlkf_init(void)
struct AhrsMlkf ahrs_mlkf
static void ahrs_float_get_quat_from_accel_mag(struct FloatQuat *q, struct FloatVect3 *accel, struct FloatVect3 *mag)
static void reset_state(void)
Incorporate errors to reference and zeros state.
#define MAT_INV33(_invS, _S)
struct OrientationReps body_to_imu
body_to_imu rotation
#define MAT_SUB(_i, _j, C, A, B)
struct FloatQuat ltp_to_imu_quat
Rotation from LocalTangentPlane to IMU frame as unit quaternion.
static void propagate_state(float dt)
Progagate filter's covariance We don't propagate state as we assume to have reseted.
static struct OrientationReps body_to_imu
#define RATES_COPY(_a, _b)
static struct FloatQuat * orientationGetQuat_f(struct OrientationReps *orientation)
Get vehicle body attitude quaternion (float).
Paparazzi fixed point algebra.
#define MAT_MUL(_i, _k, _j, C, A, B)