36 #include "generated/airframe.h"
37 #include "generated/flight_plan.h"
38 #if FIXEDWING_FIRMWARE
50 #if SEND_INVARIANT_FILTER || PERIODIC_TELEMETRY
54 #if LOG_INVARIANT_FILTER
85 #define INS_INV_LV 2.f
89 #define INS_INV_LB 6.f
93 #define INS_INV_MV 8.f
97 #define INS_INV_MVZ 15.f
101 #define INS_INV_MH 0.2f
105 #define INS_INV_NX 0.8f
109 #define INS_INV_NXZ 0.5f
113 #define INS_INV_NH 1.2f
117 #define INS_INV_OV 1.2f
121 #define INS_INV_OB 1.f
125 #define INS_INV_RV 4.f
129 #define INS_INV_RH 8.f
133 #define INS_INV_SH 0.01f
140 static const struct FloatVect3 A = { 0.f, 0.f, 9.81f };
144 #define B ins_float_inv.mag_h
153 #ifndef INS_INV_HEADING_UPDATE_GPS_MIN_SPEED
154 #define INS_INV_HEADING_UPDATE_GPS_MIN_SPEED 5.f
161 static inline void invariant_model(
float *o,
const float *
x,
const int n,
const float *u,
const int m);
192 #if SEND_INVARIANT_FILTER || PERIODIC_TELEMETRY
197 pprz_msg_send_INV_FILTER(trans,
dev,
223 #if FIXEDWING_FIRMWARE
227 utm0.
alt = GROUND_ALT;
233 llh_nav0.
lat = NAV_LAT0;
234 llh_nav0.
lon = NAV_LON0;
236 llh_nav0.
alt = NAV_ALT0 + NAV_MSL0;
276 #if PERIODIC_TELEMETRY
283 #if FIXEDWING_FIRMWARE
303 #if FIXEDWING_FIRMWARE
325 struct FloatVect3 *lp_mag __attribute__((unused)))
396 #if SEND_INVARIANT_FILTER
400 #if LOG_INVARIANT_FILTER
405 "p q r ax ay az gx gy gz gvx gvy gvz mx my mz b qi qx qy qz bp bq br vx vy vz px py pz hb as\n");
409 "%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f\n",
450 #if FIXEDWING_FIRMWARE
463 struct NedCoor_i gps_pos_cm_ned, ned_pos;
481 #if !USE_MAGNETOMETER
482 struct FloatVect3 pseudo_mag = { 0.f, 0.f, 0.f };
483 bool update_mag =
false;
484 #if INS_INV_USE_GPS_HEADING
488 static const uint32_t max_cacc = RadOfDeg(10 * 1e7);
490 gps_s->
gspeed >= gps_min_speed &&
491 gps_s->
cacc <= max_cacc) {
503 pseudo_mag.
x = vel.
x / vel_norm;
504 pseudo_mag.
y = -vel.
y / vel_norm;
513 struct FloatQuat quat_psi = { cosf(angles.
psi / 2.f), 0.f, 0.f, sinf(angles.
psi / 2.f) };
533 static float alpha = 10.0f;
535 static float baro_moy = 0.0f;
536 static float baro_prev = 0.0f;
543 baro_prev = pressure;
545 baro_moy = (baro_moy * (i - 1) + pressure) / i;
546 alpha = (10.f*
alpha + (baro_moy - baro_prev)) / (11.0f);
547 baro_prev = baro_moy;
549 if (fabs(
alpha) < 0.1f) {
564 #define MAG_FROZEN_COUNT 30
571 if (last_mx == mag->
x) {
573 if (mag_frozen_count == 0) {
593 const int m __attribute__((unused)))
596 #pragma GCC diagnostic push
597 #pragma GCC diagnostic ignored "-Wcast-qual"
600 #pragma GCC diagnostic pop
636 if ( ((
s->as < 0.5f) && (s_dot.
as < 0.f)) || ((
s->as > 1.5f) && (s_dot.
as > 0.f)) ) {
644 memcpy(o, &s_dot, n *
sizeof(
float));
673 #
if FIXEDWING_FIRMWARE
698 temp = (_ins->
gains.
lb / 100.f) * temp;
720 temp = (-_ins->
gains.
ob / 1000.f) * temp;
#define INV_STATE_DIM
Invariant filter state dimension.
#define INV_COMMAND_DIM
Invariant filter command vector dimension.
static void ahrs_float_get_quat_from_accel_mag(struct FloatQuat *q, struct FloatVect3 *accel, struct FloatVect3 *mag)
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.
Utility functions for fixed point AHRS implementations.
struct UtmCoor_f utm_float_from_gps(struct GpsState *gps_s, uint8_t zone)
Convenience functions to get utm position from GPS state.
struct NedCoor_f ned_vel_float_from_gps(struct GpsState *gps_s)
Get GPS ned velocity (float) Converted on the fly if not available.
struct EcefCoor_f ecef_vel_float_from_gps(struct GpsState *gps_s)
Get GPS ecef velocity (float) Converted on the fly if not available.
struct GpsState gps
global GPS state
struct LlaCoor_i lla_int_from_gps(struct GpsState *gps_s)
Get GPS lla (integer) Converted on the fly if not available.
struct EcefCoor_i ecef_int_from_gps(struct GpsState *gps_s)
Get GPS ecef pos (integer) Converted on the fly if not available.
Device independent GPS code (interface)
int32_t hmsl
height above mean sea level (MSL) in mm
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
uint32_t cacc
course accuracy in rad*1e7
int32_t course
GPS course over ground in rad*1e7, [0, 2*Pi]*1e7 (CW/north)
uint16_t gspeed
norm of 2d ground speed in cm/s
#define GPS_FIX_3D
3D GPS fix
data structure for GPS information
static struct LtpDef_i ltp_def
static void float_quat_normalize(struct FloatQuat *q)
static void float_quat_identity(struct FloatQuat *q)
initialises a quaternion to identity
void float_quat_inv_comp_norm_shortest(struct FloatQuat *b2c, struct FloatQuat *a2b, struct FloatQuat *a2c)
Composition (multiplication) of two quaternions with normalization.
#define FLOAT_QUAT_EXTRACT(_vo, _qi)
#define FLOAT_VECT3_ZERO(_v)
static float float_vect2_norm(struct FloatVect2 *v)
void float_quat_vmult(struct FloatVect3 *v_out, struct FloatQuat *q, const struct FloatVect3 *v_in)
rotate 3D vector by quaternion.
#define FLOAT_QUAT_NORM2(_q)
void float_eulers_of_quat(struct FloatEulers *e, struct FloatQuat *q)
euler rotation 'ZYX'
static void float_quat_invert(struct FloatQuat *qo, struct FloatQuat *qi)
#define FLOAT_RATES_ZERO(_r)
void float_quat_derivative(struct FloatQuat *qd, struct FloatRates *r, struct FloatQuat *q)
Quaternion derivative from rotational velocity.
#define VECT3_SUM(_c, _a, _b)
#define RATES_COPY(_a, _b)
#define RATES_ASSIGN(_ra, _p, _q, _r)
#define VECT3_CROSS_PRODUCT(_vo, _v1, _v2)
#define VECT3_SMUL(_vo, _vi, _s)
#define VECT3_COPY(_a, _b)
#define ACCELS_BFP_OF_REAL(_ef, _ei)
#define QUAT_ASSIGN(_q, _i, _x, _y, _z)
#define RATES_DIFF(_c, _a, _b)
#define VECT3_DIFF(_c, _a, _b)
#define VECT3_ADD(_a, _b)
#define QUAT_SMUL(_qo, _qi, _s)
#define QUAT_ADD(_qo, _qi)
#define VECT3_DOT_PRODUCT(_v1, _v2)
#define INT32_POS_OF_CM_DEN
#define INT32_POS_OF_CM_NUM
#define INT32_VECT3_SCALE_2(_a, _b, _num, _den)
int32_t lat
in degrees*1e7
int32_t hmsl
Height above mean sea level in mm.
int32_t alt
in millimeters above WGS84 reference ellipsoid
struct LlaCoor_i lla
Reference point in lla.
int32_t lon
in degrees*1e7
void ecef_of_lla_i(struct EcefCoor_i *out, struct LlaCoor_i *in)
Convert a LLA to ECEF.
void ltp_def_from_ecef_i(struct LtpDef_i *def, struct EcefCoor_i *ecef)
#define NED_FLOAT_OF_BFP(_o, _i)
void ned_of_ecef_point_i(struct NedCoor_i *ned, struct LtpDef_i *def, struct EcefCoor_i *ecef)
Convert a point from ECEF to local NED.
void ltp_def_from_lla_i(struct LtpDef_i *def, struct LlaCoor_i *lla)
vector in EarthCenteredEarthFixed coordinates
vector in Latitude, Longitude and Altitude
definition of the local (flat earth) coordinate system
vector in North East Down coordinates
static float pprz_isa_height_of_pressure(float pressure, float ref_p)
Get relative altitude from pressure (using simplified equation).
#define PPRZ_ISA_SEA_LEVEL_PRESSURE
ISA sea level standard atmospheric pressure in Pascal.
static void stateSetAccelNed_f(uint16_t id, struct NedCoor_f *ned_accel)
Set acceleration in NED coordinates (float).
static void stateSetAccelBody_i(uint16_t id, struct Int32Vect3 *body_accel)
Set acceleration in Body coordinates (int).
static void stateSetNedToBodyQuat_f(uint16_t id, struct FloatQuat *ned_to_body_quat)
Set vehicle body attitude from quaternion (float).
static struct UtmCoor_f * stateGetUtmOrigin_f(void)
Get the coordinate UTM frame origin (int)
static void stateSetPositionNed_f(uint16_t id, struct NedCoor_f *ned_pos)
Set position from local NED coordinates (float).
static void stateSetLocalOrigin_i(uint16_t id, struct LtpDef_i *ltp_def)
Set the local (flat earth) coordinate frame origin (int).
static struct LtpDef_f * stateGetNedOrigin_f(void)
Get the coordinate NED frame origin (float)
bool ned_initialized_f
True if local float coordinate frame is initialsed.
static void stateSetPositionUtm_f(uint16_t id, struct UtmCoor_f *utm_pos)
Set position from UTM coordinates (float).
bool utm_initialized_f
True if utm origin (float) coordinate frame is initialsed.
static struct LtpDef_i * stateGetNedOrigin_i(void)
Get the coordinate NED frame origin (int)
static void stateSetLocalUtmOrigin_f(uint16_t id, struct UtmCoor_f *utm_def)
Set the local (flat earth) coordinate frame origin from UTM (float).
float stateGetHmslOrigin_f(void)
Get the HMSL of the frame origin (float)
struct LlaCoor_i stateGetLlaOrigin_i(void)
Get the LLA position of the frame origin (int)
static void stateSetBodyRates_f(uint16_t id, struct FloatRates *body_rate)
Set vehicle body angular rate (float).
static void stateSetSpeedNed_f(uint16_t id, struct NedCoor_f *ned_speed)
Set ground speed in local NED coordinates (float).
Integrated Navigation System interface.
void ins_float_invariant_reset_ref(void)
static void send_inv_filter(struct transport_tx *trans, struct link_device *dev)
void float_quat_vmul_right(struct FloatQuat *mright, const struct FloatQuat *q, struct FloatVect3 *vi)
Right multiplication by a quaternion.
void ins_float_invariant_align(struct FloatRates *lp_gyro, struct FloatVect3 *lp_accel, struct FloatVect3 *lp_mag)
void ins_float_invariant_propagate(struct FloatRates *gyro, struct FloatVect3 *accel, float dt)
void ins_float_invariant_init(void)
static void init_invariant_state(void)
bool ins_baro_initialized
void ins_float_invariant_update_gps(struct GpsState *gps_s)
static const struct FloatVect3 A
void ins_float_invariant_update_mag(struct FloatVect3 *mag)
static void invariant_model(float *o, const float *x, const int n, const float *u, const int m)
Compute dynamic mode.
#define INS_INV_HEADING_UPDATE_GPS_MIN_SPEED
struct InsFloatInv ins_float_inv
void ins_float_invariant_update_baro(float pressure)
static void error_output(struct InsFloatInv *_ins)
Compute correction vectors E = ( ลท - y ) LE, ME, NE, OE : ( gain matrix * error )
void ins_float_invariant_reset_vertical_ref(void)
INS using invariant filter.
float rv
Tuning parameter of speed error on accel biases.
float mvz
Tuning parameter of vertical speed error on speed.
struct FloatVect3 accel
Input accelerometers.
float nxz
Tuning parameter of vertical position error on position.
float lv
Tuning parameter of speed error on attitude.
struct NedCoor_f speed
Estimates speed.
float mh
Tuning parameter of baro error on vertical speed.
float hb
Estimates barometers bias.
struct FloatRates bias
Estimated gyro biases.
float ob
Tuning parameter of mag error on gyro biases.
float rh
Tuning parameter of baro error on accel biases (vertical projection)
struct inv_gains gains
tuning gains
float OE
Correction gains on magnetometer sensitivity.
float mv
Tuning parameter of horizontal speed error on speed.
struct inv_state state
state vector
struct FloatVect3 LE
Correction gains on attitude.
struct FloatVect3 ME
Correction gains on gyro biases.
struct inv_command cmd
command vector
float as
Estimated accelerometer sensitivity.
struct FloatVect3 mag
Measured magnetic field.
struct NedCoor_f pos
Estimates position.
struct inv_measures meas
measurement vector
struct FloatQuat quat
Estimated attitude (quaternion)
float lb
Tuning parameter of mag error on attitude.
float SE
Correction gains on barometer bias.
float nx
Tuning parameter of horizontal position error on position.
bool reset
flag to request reset/reinit the filter
float NE
Correction gains on accel bias.
struct FloatRates rates
Input gyro rates.
float RE
Correction gains on accel bias.
struct NedCoor_f pos_gps
Measured gps position.
float baro_alt
Measured barometric altitude.
float ov
Tuning parameter of speed error on gyro biases.
struct NedCoor_f speed_gps
Measured gps speed.
struct inv_correction_gains corr
correction gains
float nh
Tuning parameter of baro error on vertical position.
float sh
Tuning parameter of baro error on baro bias.
Invariant filter structure.
Invariant filter command vector.
Fixedwing Navigation library.
Paparazzi floating point algebra.
Paparazzi fixed point algebra.
void ned_of_ecef_vect_f(struct NedCoor_f *ned, struct LtpDef_f *def, struct EcefCoor_f *ecef)
float alt
in meters (above WGS84 reference ellipsoid or above MSL)
uint8_t zone
UTM zone number.
vector in EarthCenteredEarthFixed coordinates
vector in North East Down coordinates Units: meters
position in UTM coordinates Units: meters
Paparazzi atmospheric pressure conversion utilities.
Runge-Kutta library (float version)
static void runge_kutta_4_float(float *xo, const float *x, const int n, const float *u, const int m, void(*f)(float *o, const float *x, const int n, const float *u, const int m), const float dt)
Fourth-Order Runge-Kutta.
API to get/set the generic vehicle states.
static const struct usb_device_descriptor dev
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
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.