35 #include "generated/airframe.h"
42 #if AHRS_PROPAGATE_RMAT && AHRS_PROPAGATE_QUAT
43 #error "You can only define either AHRS_PROPAGATE_RMAT or AHRS_PROPAGATE_QUAT, not both!"
45 #if !AHRS_PROPAGATE_RMAT && !AHRS_PROPAGATE_QUAT
46 #error "You have to define either AHRS_PROPAGATE_RMAT or AHRS_PROPAGATE_QUAT"
49 #ifdef AHRS_MAG_UPDATE_YAW_ONLY
50 #warning "AHRS_MAG_UPDATE_YAW_ONLY is deprecated, please remove it. This is the default behaviour. Define AHRS_MAG_UPDATE_ALL_AXES to use mag for all axes and not only yaw."
53 #if USE_MAGNETOMETER && AHRS_USE_GPS_HEADING
54 #warning "Using magnetometer _and_ GPS course to update heading. Probably better to <configure name="USE_MAGNETOMETER" value="0"/> if you want to use GPS course."
60 #ifndef AHRS_ACCEL_OMEGA
61 #define AHRS_ACCEL_OMEGA 0.063
63 #ifndef AHRS_ACCEL_ZETA
64 #define AHRS_ACCEL_ZETA 0.9
67 #ifndef AHRS_MAG_OMEGA
68 #define AHRS_MAG_OMEGA 0.04
71 #define AHRS_MAG_ZETA 0.9
75 #ifndef AHRS_GRAVITY_HEURISTIC_FACTOR
76 #define AHRS_GRAVITY_HEURISTIC_FACTOR 30
108 #if AHRS_GRAVITY_UPDATE_COORDINATED_TURN
160 #ifdef AHRS_PROPAGATE_LOW_PASS_RATES
161 const float alpha = 0.1;
173 #if AHRS_PROPAGATE_RMAT
178 #if AHRS_PROPAGATE_QUAT
229 VECT3_DIFF(pseudo_gravity_measurement, imu_accel_float, acc_c_imu);
232 VECT3_COPY(pseudo_gravity_measurement, imu_accel_float);
238 #define FIR_FILTER_SIZE 8
239 static struct FloatVect3 filtered_gravity_measurement = {0., 0., 0.};
241 VECT3_ADD(filtered_gravity_measurement, pseudo_gravity_measurement);
251 const float g_meas_norm =
float_vect3_norm(&filtered_gravity_measurement) / 9.81;
288 #if AHRS_MAG_UPDATE_ALL_AXES
343 struct FloatVect2 measured_ltp_2d = {measured_ltp.
x, measured_ltp.
y};
351 measured_ltp_2d.
x *expected_ltp.
y - measured_ltp_2d.
y * expected_ltp.
x
384 const float cphi = cosf(ltp_to_imu_euler.
phi);
385 const float sphi = sinf(ltp_to_imu_euler.
phi);
386 const float ctheta = cosf(ltp_to_imu_euler.
theta);
387 const float stheta = sinf(ltp_to_imu_euler.
theta);
388 const float mn = ctheta * magf.
x + sphi * stheta * magf.
y + cphi * stheta * magf.
z;
389 const float me = 0. * magf.
x + cphi * magf.
y - sphi * magf.
z;
397 const float mag_rate_update_gain = 2.5;
399 const float mag_bias_update_gain = -2.5e-4;
406 #if AHRS_GRAVITY_UPDATE_COORDINATED_TURN && USE_GPS
415 #if AHRS_USE_GPS_HEADING && USE_GPS
417 if (gps_s->fix >=
GPS_FIX_3D && gps_s->gspeed >= 500 &&
418 gps_s->cacc <= RadOfDeg(10 * 1e7)) {
421 float course = gps_s->course / 1e7;
454 expected_ltp.
x * sinf(heading) - expected_ltp.
y * cosf(heading)
460 const float heading_rate_update_gain = 2.5;
463 float heading_bias_update_gain;
470 if (fabs(residual_ltp.
z) < sinf(RadOfDeg(5.))) {
471 heading_bias_update_gain = -2.5e-4;
473 heading_bias_update_gain = 0.0;
487 q_h_new.
qz = sinf(heading / 2.0);
488 q_h_new.
qi = cosf(heading / 2.0);
494 struct FloatQuat q_h = *ltp_to_body_quat;
#define VECT3_CROSS_PRODUCT(_vo, _v1, _v2)
void ahrs_fc_set_body_to_imu(struct OrientationReps *body_to_imu)
#define FLOAT_ANGLE_NORMALIZE(_a)
void float_quat_comp_inv(struct FloatQuat *a2b, struct FloatQuat *a2c, struct FloatQuat *b2c)
Composition (multiplication) of two quaternions.
static void orientationSetQuat_f(struct OrientationReps *orientation, struct FloatQuat *quat)
Set vehicle body attitude from quaternion (float).
#define VECT3_ADD(_a, _b)
uint16_t mag_cnt
number of propagations since last mag update
float accel_omega
filter cut-off frequency for correcting the attitude from accels (pseudo-gravity measurement) ...
bool_t ltp_vel_norm_valid
Simple matrix helper macros.
struct FloatRates gyro_bias
static void orientationSetIdentity(struct OrientationReps *orientation)
Set to identity orientation.
void ahrs_fc_update_mag_2d_dumb(struct Int32Vect3 *mag)
struct FloatRMat ltp_to_imu_rmat
void float_quat_comp(struct FloatQuat *a2c, struct FloatQuat *a2b, struct FloatQuat *b2c)
Composition (multiplication) of two quaternions.
void float_eulers_of_rmat(struct FloatEulers *e, struct FloatRMat *rm)
static void float_quat_identity(struct FloatQuat *q)
initialises a quaternion to identity
#define VECT3_COPY(_a, _b)
static struct FloatRMat * orientationGetRMat_f(struct OrientationReps *orientation)
Get vehicle body attitude rotation matrix (float).
#define VECT3_DIFF(_c, _a, _b)
#define VECT3_ASSIGN(_a, _x, _y, _z)
static void float_vect2_normalize(struct FloatVect2 *v)
normalize 2D vector in place
Utility functions for floating point AHRS implementations.
#define FLOAT_RATES_ZERO(_r)
#define VECT2_COPY(_a, _b)
void ahrs_fc_update_heading(float heading)
Update yaw based on a heading measurement.
#define RATES_SUB(_a, _b)
#define GPS_FIX_3D
3D GPS fix
#define AHRS_GRAVITY_HEURISTIC_FACTOR
by default use the gravity heuristic to reduce gain
struct FloatQuat ltp_to_imu_quat
void float_rmat_integrate_fi(struct FloatRMat *rm, struct FloatRates *omega, float dt)
in place first order integration of a rotation matrix
static float float_vect3_norm(struct FloatVect3 *v)
uint8_t gravity_heuristic_factor
sets how strongly the gravity heuristic reduces accel correction.
void float_rmat_vmult(struct FloatVect3 *vb, struct FloatRMat *m_a2b, struct FloatVect3 *va)
rotate 3D vector by rotation matrix.
bool_t ahrs_fc_align(struct Int32Rates *lp_gyro, struct Int32Vect3 *lp_accel, struct Int32Vect3 *lp_mag)
void float_rmat_transp_vmult(struct FloatVect3 *vb, struct FloatRMat *m_b2a, struct FloatVect3 *va)
rotate 3D vector by transposed rotation matrix.
#define FLOAT_RATES_LIN_CMB(_ro, _r1, _s1, _r2, _s2)
#define RATES_FLOAT_OF_BFP(_rf, _ri)
Paparazzi floating point algebra.
data structure for GPS information
void float_rmat_of_quat(struct FloatRMat *rm, struct FloatQuat *q)
Device independent GPS code (interface)
void float_quat_integrate(struct FloatQuat *q, struct FloatRates *omega, float dt)
in place quaternion integration with constant rotational velocity
#define RATES_SUM(_c, _a, _b)
#define VECT3_SDIV(_vo, _vi, _s)
#define RATES_ADD_SCALED_VECT(_ro, _v, _s)
static void ahrs_float_get_quat_from_accel_mag(struct FloatQuat *q, struct Int32Vect3 *accel, struct Int32Vect3 *mag)
static void float_quat_normalize(struct FloatQuat *q)
float mag_omega
filter cut-off frequency for correcting the attitude (heading) from magnetometer
void float_quat_of_rmat(struct FloatQuat *q, struct FloatRMat *rm)
Quaternion from rotation matrix.
bool_t correct_gravity
enable gravity correction during coordinated turns
void ahrs_fc_update_mag(struct Int32Vect3 *mag, float dt)
float accel_zeta
filter damping for correcting the gyro-bias from accels (pseudo-gravity measurement) ...
void ahrs_fc_set_body_to_imu_quat(struct FloatQuat *q_b2i)
#define ACCELS_FLOAT_OF_BFP(_ef, _ei)
void ahrs_fc_realign_heading(float heading)
Hard reset yaw to a heading.
float float_rmat_reorthogonalize(struct FloatRMat *rm)
void ahrs_fc_update_mag_full(struct Int32Vect3 *mag, float dt)
static void ahrs_float_get_quat_from_accel(struct FloatQuat *q, struct Int32Vect3 *accel)
Compute a quaternion representing roll and pitch from an accelerometer measurement.
#define VECT3_SMUL(_vo, _vi, _s)
void float_rmat_transp_ratemult(struct FloatRates *rb, struct FloatRMat *m_b2a, struct FloatRates *ra)
rotate anglular rates by transposed rotation matrix.
struct FloatRates imu_rate
#define RMAT_ELMT(_rm, _row, _col)
void float_quat_comp_norm_shortest(struct FloatQuat *a2c, struct FloatQuat *a2b, struct FloatQuat *b2c)
Composition (multiplication) of two quaternions with normalization.
void ahrs_fc_update_gps(struct GpsState *gps_s)
void float_quat_inv_comp_norm_shortest(struct FloatQuat *b2c, struct FloatQuat *a2b, struct FloatQuat *a2c)
Composition (multiplication) of two quaternions with normalization.
Complementary filter in float to estimate the attitude, heading and gyro bias.
struct OrientationReps body_to_imu
void ahrs_fc_recompute_ltp_to_body(void)
void ahrs_fc_update_accel(struct Int32Vect3 *accel, float dt)
void ahrs_fc_update_mag_2d(struct Int32Vect3 *mag, float dt)
#define MAGS_FLOAT_OF_BFP(_ef, _ei)
uint16_t accel_cnt
number of propagations since last accel update
float ltp_vel_norm
velocity norm for gravity correction during coordinated turns
static struct OrientationReps body_to_imu
#define RATES_COPY(_a, _b)
struct FloatRates rate_correction
void ahrs_fc_propagate(struct Int32Rates *gyro, float dt)
float mag_zeta
filter damping for correcting the gyro bias from magnetometer
struct AhrsFloatCmpl ahrs_fc
static struct FloatQuat * orientationGetQuat_f(struct OrientationReps *orientation)
Get vehicle body attitude quaternion (float).
Paparazzi fixed point algebra.
struct OrientationReps ltp_to_body
#define VECT3_RATES_CROSS_VECT3(_vo, _r1, _v2)