31#include "generated/airframe.h"
42#ifdef AHRS_PROPAGATE_LOW_PASS_RATES
46#ifdef AHRS_FLOATING_HEADING
50#if USE_MAGNETOMETER && AHRS_USE_GPS_HEADING
51#warning "Using both magnetometer and GPS course to update heading. Probably better to configure USE_MAGNETOMETER=0 if you want to use GPS course."
54#if !USE_MAGNETOMETER && !AHRS_USE_GPS_HEADING &&!AHRS_FLOATING_HEADING
55#warning "Please use either USE_MAGNETOMETER, AHRS_USE_GPS_HEADING or accept AHRS_FLOATING_HEADING."
58#if AHRS_USE_GPS_HEADING && !USE_GPS
59#error "AHRS_USE_GPS_HEADING needs USE_GPS to be TRUE"
65#ifndef AHRS_ACCEL_OMEGA
66#define AHRS_ACCEL_OMEGA 0.063
68#ifndef AHRS_ACCEL_ZETA
69#define AHRS_ACCEL_ZETA 0.9
76#define AHRS_MAG_OMEGA 0.04
79#define AHRS_MAG_ZETA 0.9
87#ifndef AHRS_GRAVITY_HEURISTIC_FACTOR
88#define AHRS_GRAVITY_HEURISTIC_FACTOR 30
92#ifndef AHRS_BIAS_UPDATE_HEADING_THRESHOLD
93#define AHRS_BIAS_UPDATE_HEADING_THRESHOLD 5.0
99#ifndef AHRS_HEADING_UPDATE_GPS_MIN_SPEED
100#define AHRS_HEADING_UPDATE_GPS_MIN_SPEED 5.0
104#ifdef AHRS_PROPAGATE_LOW_PASS_RATES
105#ifndef AHRS_PROPAGATE_LOW_PASS_RATES_MUL
106#define AHRS_PROPAGATE_LOW_PASS_RATES_MUL 2
109#ifndef AHRS_PROPAGATE_LOW_PASS_RATES_DIV
110#define AHRS_PROPAGATE_LOW_PASS_RATES_DIV 3
147#if AHRS_GRAVITY_UPDATE_COORDINATED_TURN
199#ifdef AHRS_PROPAGATE_LOW_PASS_RATES
272#define COMPUTATION_FRAC 16
273#define ACC_FROM_CROSS_FRAC INT32_RATE_FRAC + INT32_SPEED_FRAC - INT32_ACCEL_FRAC - COMPUTATION_FRAC
276#if AHRS_GPS_SPEED_IN_NEGATIVE_Z_DIRECTION
301#define FIR_FILTER_SIZE 8
387#if AHRS_MAG_UPDATE_ALL_AXES
527#if AHRS_GRAVITY_UPDATE_COORDINATED_TURN && USE_GPS
536#if AHRS_USE_GPS_HEADING && USE_GPS
bool ahrs_icq_align(struct Int32Rates *lp_gyro, struct Int32Vect3 *lp_accel, struct Int32Vect3 *lp_mag)
void ahrs_icq_update_accel(struct Int32Vect3 *accel, float dt)
#define ACC_FROM_CROSS_FRAC
struct AhrsIntCmplQuat ahrs_icq
Default Rate filter Low pass.
#define AHRS_BIAS_UPDATE_HEADING_THRESHOLD
don't update gyro bias if heading deviation is above this threshold in degrees
void ahrs_icq_update_gps(struct GpsState *gps_s)
void ahrs_icq_update_heading(int32_t heading)
Update yaw based on a heading measurement.
static void ahrs_icq_update_mag_2d(struct Int32Vect3 *mag, float dt)
#define AHRS_GRAVITY_HEURISTIC_FACTOR
by default use the gravity heuristic to reduce gain
void ahrs_icq_realign_heading(int32_t heading)
Hard reset yaw to a heading.
void ahrs_icq_update_mag(struct Int32Vect3 *mag, float dt)
void ahrs_icq_set_accel_gains(void)
update pre-computed inv_kp and inv_ki gains from acc_omega and acc_zeta
void ahrs_icq_set_mag_gains(void)
update pre-computed kp and ki gains from mag_omega and mag_zeta
static void UNUSED ahrs_icq_update_mag_full(struct Int32Vect3 *mag, float dt)
void ahrs_icq_propagate(struct Int32Rates *gyro, float dt)
#define AHRS_HEADING_UPDATE_GPS_MIN_SPEED
Minimum speed in m/s for heading update via GPS.
Quaternion complementary filter (fixed-point).
uint16_t accel_cnt
number of propagations since last accel update
struct Int32Rates gyro_bias
uint16_t mag_cnt
number of propagations since last mag update
float mag_omega
filter cut-off frequency for correcting the attitude (heading) from magnetometer.
uint8_t gravity_heuristic_factor
sets how strongly the gravity heuristic reduces accel correction.
struct Int32Rates rate_correction
float mag_zeta
filter damping for correcting the gyro bias from magnetometer.
struct Int64Rates high_rez_bias
float accel_omega
filter cut-off frequency for correcting the attitude from accels.
struct Int32Rates body_rate
struct Int32Quat ltp_to_body_quat
struct Int64Quat high_rez_quat
enum AhrsICQStatus status
status of the AHRS, AHRS_ICQ_UNINIT or AHRS_ICQ_RUNNING
bool correct_gravity
enable gravity vector correction by removing centrifugal acceleration
float accel_zeta
filter damping for correcting the gyro-bias from accels.
Ahrs implementation specifc values.
Utility functions for fixed point AHRS implementations.
static void ahrs_int_get_quat_from_accel(struct Int32Quat *q, struct Int32Vect3 *accel)
static void ahrs_int_get_quat_from_accel_mag(struct Int32Quat *q, struct Int32Vect3 *accel, struct Int32Vect3 *mag)
Device independent GPS code (interface)
#define GPS_FIX_3D
3D GPS fix
data structure for GPS information
#define FLOAT_VECT3_NORM(_v)
#define VECT3_SDIV(_vo, _vi, _s)
#define VECT3_RATES_CROSS_VECT3(_vo, _r1, _v2)
#define RATES_COPY(_a, _b)
#define VECT3_CROSS_PRODUCT(_vo, _v1, _v2)
#define RATES_SMUL(_ro, _ri, _s)
#define VECT3_SMUL(_vo, _vi, _s)
#define VECT3_ASSIGN(_a, _x, _y, _z)
#define QUAT_COPY(_qo, _qi)
#define RMAT_ELMT(_rm, _row, _col)
#define RATES_ADD(_a, _b)
#define VECT3_COPY(_a, _b)
#define RATES_DIFF(_c, _a, _b)
#define VECT3_DIFF(_c, _a, _b)
#define VECT3_ADD(_a, _b)
#define RATES_SDIV(_ro, _ri, _s)
#define ACCELS_FLOAT_OF_BFP(_ef, _ei)
int32_t p
in rad/s with INT32_RATE_FRAC
int32_t r
in rad/s with INT32_RATE_FRAC
int32_t q
in rad/s with INT32_RATE_FRAC
static void int32_quat_normalize(struct Int32Quat *q)
normalize a quaternion inplace
#define INT_RATES_ZERO(_e)
void int32_quat_comp_norm_shortest(struct Int32Quat *a2c, struct Int32Quat *a2b, struct Int32Quat *b2c)
Composition (multiplication) of two quaternions with normalization.
void int32_rmat_of_quat(struct Int32RMat *rm, struct Int32Quat *q)
Convert unit quaternion to rotation matrix.
#define INT_RATES_LSHIFT(_o, _i, _r)
void int32_quat_inv_comp_norm_shortest(struct Int32Quat *b2c, struct Int32Quat *a2b, struct Int32Quat *a2c)
Composition (multiplication) of two quaternions with normalization.
static void int32_vect2_normalize(struct Int32Vect2 *v, uint8_t frac)
normalize 2D vector inplace
void int32_rmat_vmult(struct Int32Vect3 *vb, struct Int32RMat *m_a2b, struct Int32Vect3 *va)
rotate 3D vector by rotation matrix.
static void int32_quat_identity(struct Int32Quat *q)
initialises a quaternion to identity
#define INT_RATES_RSHIFT(_o, _i, _r)
#define MAG_BFP_OF_REAL(_af)
#define INT32_VECT3_RSHIFT(_o, _i, _r)
void int32_quat_integrate_fi(struct Int32Quat *q, struct Int64Quat *hr, struct Int32Rates *omega, int freq)
in place quaternion first order integration with constant rotational velocity.
void int32_rmat_transp_vmult(struct Int32Vect3 *vb, struct Int32RMat *m_b2a, struct Int32Vect3 *va)
rotate 3D vector by transposed rotation matrix.
#define TRIG_BFP_OF_REAL(_tf)
#define SPEED_BFP_OF_REAL(_af)
#define INT32_ANGLE_NORMALIZE(_a)
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
Paparazzi fixed point algebra.
Paparazzi fixed point trig functions.
#define PPRZ_ITRIG_SIN(_s, _a)
#define PPRZ_ITRIG_COS(_c, _a)
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.