30 #include "generated/airframe.h"
34 #ifndef AHRS_MADGWICK_BETA
35 #define AHRS_MADGWICK_BETA 0.1f // 2 * proportional gain
119 const float s0 = _4q0 * q2q2 + _2q2 * a.
x + _4q0 * q1q1 - _2q1 * a.
y;
120 const float s1 = _4q1 * q3q3 - _2q3 * a.
x + 4.0f * q0q0 * q1 - _2q0 * a.
y - _4q1 + _8q1 * q1q1 + _8q1 * q2q2 + _4q1 * a.
z;
121 const float s2 = 4.0f * q0q0 * q2 + _2q0 * a.
x + _4q2 * q3q3 - _2q3 * a.
y - _4q2 + _8q2 * q1q1 + _8q2 * q2q2 + _4q2 * a.
z;
122 const float s3 = 4.0f * q1q1 * q3 - _2q1 * a.
x + 4.0f * q2q2 * q3 - _2q2 * a.
y;
123 const float beta_inv_grad_norm =
AHRS_MADGWICK_BETA / sqrtf(s0 * s0 + s1 * s1 + s2 * s2 + s3 * s3);
126 qdot.
qi -= s0 * beta_inv_grad_norm;
127 qdot.
qx -= s1 * beta_inv_grad_norm;
128 qdot.
qy -= s2 * beta_inv_grad_norm;
129 qdot.
qz -= s3 * beta_inv_grad_norm;
void ahrs_madgwick_align(struct FloatRates *lp_gyro, struct FloatVect3 *lp_accel)
static void orientationSetQuat_f(struct OrientationReps *orientation, struct FloatQuat *quat)
Set vehicle body attitude from quaternion (float).
void ahrs_madgwick_propagate(struct FloatRates *gyro, float dt)
static void init_state(void)
struct FloatRates bias
Gyro bias (from alignment)
void ahrs_madgwick_update_accel(struct FloatVect3 *accel)
static void float_quat_identity(struct FloatQuat *q)
initialises a quaternion to identity
static struct FloatRMat * orientationGetRMat_f(struct OrientationReps *orientation)
Get vehicle body attitude rotation matrix (float).
Utility functions for floating point AHRS implementations.
#define FLOAT_RATES_ZERO(_r)
struct AhrsMadgwick ahrs_madgwick
bool is_aligned
aligned flag
#define RATES_DIFF(_c, _a, _b)
static void ahrs_float_get_quat_from_accel(struct FloatQuat *q, struct FloatVect3 *accel)
Compute a quaternion representing roll and pitch from an accelerometer measurement.
struct FloatQuat quat
Estimated attitude (quaternion)
static float float_vect3_norm(struct FloatVect3 *v)
#define FLOAT_VECT3_ZERO(_v)
Paparazzi floating point algebra.
struct FloatRates rates
Measured gyro rates.
#define AHRS_MADGWICK_BETA
#define VECT3_SDIV(_vo, _vi, _s)
static void float_quat_normalize(struct FloatQuat *q)
void ahrs_madgwick_set_body_to_imu_quat(struct FloatQuat *q_b2i)
void float_quat_derivative(struct FloatQuat *qd, struct FloatRates *r, struct FloatQuat *q)
Quaternion derivative from rotational velocity.
bool reset
flag to request reset/reinit the filter
void float_rmat_transp_ratemult(struct FloatRates *rb, struct FloatRMat *m_b2a, struct FloatRates *ra)
rotate anglular rates by transposed rotation matrix.
struct FloatVect3 accel
Measured accelerometers.
AHRS using Madgwick implementation.
void ahrs_madgwick_init(void)
Madgwick filter structure.
struct OrientationReps body_to_imu
body_to_imu rotation