38 #include "generated/airframe.h"
39 #include "generated/flight_plan.h"
41 #define MEKF_WIND_USE_UTM TRUE
46 #ifndef INS_MEKF_WIND_FILTER_ID
47 #define INS_MEKF_WIND_FILTER_ID 3
63 #define PrintLog sdLogWriteLog
64 #define LogFileIsOpen() (pprzLogFile != -1)
65 #else // SITL: print in a file
67 #define PrintLog fprintf
68 #define LogFileIsOpen() (pprzLogFile != NULL)
74 #if PERIODIC_TELEMETRY
78 static void send_euler(
struct transport_tx *trans,
struct link_device *
dev)
84 pprz_msg_send_AHRS_EULER(trans, dev, AC_ID,
85 <p_to_imu_euler.
phi,
86 <p_to_imu_euler.
theta,
87 <p_to_imu_euler.
psi,
91 static void send_wind(
struct transport_tx *trans,
struct link_device *
dev)
98 pprz_msg_send_WIND_INFO_RET(trans, dev, AC_ID, &flags,
99 &wind_enu.
x, &wind_enu.
y, &wind_enu.
z, &va);
113 if (t_diff > 50000) {
117 pprz_msg_send_STATE_FILTER_STATUS(trans, dev, AC_ID, &
id, &mde, &val);
132 pprz_msg_send_INV_FILTER(trans, dev,
159 #ifndef INS_MEKF_WIND_AIRSPEED_ID
160 #define INS_MEKF_WIND_AIRSPEED_ID ABI_BROADCAST
165 #ifndef INS_MEKF_WIND_INCIDENCE_ID
166 #define INS_MEKF_WIND_INCIDENCE_ID ABI_BROADCAST
171 #ifndef INS_MEKF_WIND_BARO_ID
173 #define INS_MEKF_WIND_BARO_ID BARO_BOARD_SENDER_ID
175 #define INS_MEKF_WIND_BARO_ID ABI_BROADCAST
181 #ifndef INS_MEKF_WIND_IMU_ID
182 #define INS_MEKF_WIND_IMU_ID ABI_BROADCAST
187 #ifndef INS_MEKF_WIND_MAG_ID
188 #define INS_MEKF_WIND_MAG_ID ABI_BROADCAST
195 #ifndef INS_MEKF_WIND_GPS_ID
196 #define INS_MEKF_WIND_GPS_ID GPS_MULTI_ID
216 static float alpha = 10.0f;
218 static float baro_moy = 0.0f;
219 static float baro_prev = 0.0f;
226 baro_prev = pressure;
228 baro_moy = (baro_moy * (i - 1) + pressure) / i;
229 alpha = (10.*alpha + (baro_moy - baro_prev)) / (11.0f);
230 baro_prev = baro_moy;
232 if (fabs(alpha) < 0.1f) {
247 if (LogFileIsOpen()) {
262 if (LogFileIsOpen()) {
275 if (LogFileIsOpen()) {
288 if (LogFileIsOpen()) {
310 #if USE_AUTO_INS_FREQ || !defined(INS_PROPAGATE_FREQUENCY)
322 PRINT_CONFIG_MSG(
"Using fixed INS_PROPAGATE_FREQUENCY for INS MEKF_WIND propagation.")
323 PRINT_CONFIG_VAR(INS_PROPAGATE_FREQUENCY)
324 const float dt = 1. / (INS_PROPAGATE_FREQUENCY);
336 if (LogFileIsOpen()) {
340 "%.3f gyro_accel %.3f %.3f %.3f %.3f %.3f %.3f \n",
342 gyro_body.
p, gyro_body.
q, gyro_body.
r,
360 "%.3f output %.4f %.4f %.4f %.3f %.3f %.3f ",
363 rates.
p, rates.
q, rates.
r);
365 "%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f ",
367 speed.
x, speed.
y, speed.
z,
368 accel.
x, accel.
y, accel.
z);
370 "%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f\n",
371 ab.
x, ab.
y, ab.
z, rb.
p, rb.
q, rb.
r, bb,
372 wind.
x, wind.
y, wind.
z, airspeed);
382 uint32_t stamp __attribute__((unused)),
393 uint32_t stamp __attribute__((unused)),
406 if (LogFileIsOpen()) {
408 "%.3f magneto %.3f %.3f %.3f\n",
410 mag_body.
x, mag_body.
y, mag_body.
z);
417 uint32_t stamp __attribute__((unused)),
463 uint32_t stamp __attribute__((unused)),
468 #if MEKF_WIND_USE_UTM
488 if (LogFileIsOpen()) {
490 "%.3f gps %.3f %.3f %.3f %.3f %.3f %.3f \n",
492 pos.
x, pos.
y, pos.
z, speed.
x, speed.
y, speed.
z);
500 struct NedCoor_i gps_pos_cm_ned, ned_pos;
510 if (LogFileIsOpen()) {
512 "%.3f gps %.3f %.3f %.3f %.3f %.3f %.3f \n",
514 pos.
x, pos.
y, pos.
z, speed.
x, speed.
y, speed.
z);
549 #if MEKF_WIND_USE_UTM
553 utm0.
alt = GROUND_ALT;
559 llh_nav0.
lat = NAV_LAT0;
560 llh_nav0.
lon = NAV_LON0;
561 llh_nav0.
alt = NAV_ALT0 + NAV_MSL0;
566 ltp_def.
hmsl = NAV_ALT0;
583 const struct FloatVect3 mag_h = { INS_H_X, INS_H_Y, INS_H_Z };
599 #if PERIODIC_TELEMETRY
607 #if LOG_MEKF_WIND && SITL
612 snprintf(filename, 512,
"%s/mekf_wind_%05d.csv", STRINGIFY(MEKF_WIND_LOG_PATH), counter);
616 snprintf(filename, 512,
"%s/mekf_wind_%05d.csv", STRINGIFY(MEKF_WIND_LOG_PATH), ++counter);
620 printf(
"Failed to open WE log file '%s'\n",filename);
622 printf(
"Opening WE log file '%s'\n",filename);
634 #if MEKF_WIND_USE_UTM
650 #if MEKF_WIND_USE_UTM
static uint32_t last_imu_stamp
#define INT32_VECT3_SCALE_2(_a, _b, _num, _den)
Event structure to store callbacks in a linked list.
static void set_state_from_ins(void)
update state interface
Interface to align the AHRS via low-passed measurements at startup.
void ins_mekf_wind_init(void)
Init function.
bool utm_initialized_f
True if utm origin (float) coordinate frame is initialsed.
static void orientationSetQuat_f(struct OrientationReps *orientation, struct FloatQuat *quat)
Set vehicle body attitude from quaternion (float).
static void gyro_cb(uint8_t sender_id, uint32_t stamp, struct Int32Rates *gyro)
Call ins_mekf_wind_propagate on new gyro measurements.
definition of the local (flat earth) coordinate system
void ins_mekf_wind_set_speed_ned(struct NedCoor_f *s)
float alt
in meters (above WGS84 reference ellipsoid or above MSL)
void ins_mekf_wind_set_quat(struct FloatQuat *quat)
Periodic telemetry system header (includes downlink utility and generated code).
#define NED_FLOAT_OF_BFP(_o, _i)
void ins_reset_local_origin(void)
local implemetation of the ins_reset functions
vector in EarthCenteredEarthFixed coordinates
vector in EarthCenteredEarthFixed coordinates
void ned_of_ecef_vect_f(struct NedCoor_f *ned, struct LtpDef_f *def, struct EcefCoor_f *ecef)
#define ins_mekf_wind_wrapper_Reset(_v)
void ins_mekf_wind_update_baro(float baro_alt)
struct LtpDef_f ned_origin_f
Definition of the local (flat earth) coordinate system.
vector in East North Up coordinates Units: meters
static struct FloatRMat * orientationGetRMat_f(struct OrientationReps *orientation)
Get vehicle body attitude rotation matrix (float).
bool ned_initialized_f
True if local float coordinate frame is initialsed.
Main include for ABI (AirBorneInterface).
Utility functions for floating point AHRS implementations.
static void stateSetNedToBodyQuat_f(struct FloatQuat *ned_to_body_quat)
Set vehicle body attitude from quaternion (float).
static abi_event accel_ev
Integrated Navigation System interface.
#define INS_MEKF_WIND_IMU_ID
IMU (gyro, accel)
static void send_wind(struct transport_tx *trans, struct link_device *dev)
static void send_inv_filter(struct transport_tx *trans, struct link_device *dev)
position in UTM coordinates Units: meters
void ins_mekf_wind_align(struct FloatRates *gyro_bias, struct FloatQuat *quat)
static void airspeed_cb(uint8_t sender_id, float airspeed)
vector in Latitude, Longitude and Altitude
#define GPS_FIX_3D
3D GPS fix
void ltp_def_from_lla_i(struct LtpDef_i *def, struct LlaCoor_i *lla)
struct NedCoor_f ins_mekf_wind_get_speed_ned(void)
struct NedCoor_f ins_mekf_wind_get_wind_ned(void)
static float get_sys_time_float(void)
Get the time in seconds since startup.
static abi_event incidence_ev
static void body_to_imu_cb(uint8_t sender_id, struct FloatQuat *q_b2i)
int32_t hmsl
Height above mean sea level in mm.
Multiplicative Extended Kalman Filter in rotation matrix formulation.
int32_t alt
in millimeters above WGS84 reference ellipsoid
#define ENU_OF_TO_NED(_po, _pi)
void ins_mekf_wind_set_mag_h(const struct FloatVect3 *mag_h)
struct InsMekfWind ins_mekf_wind
float ins_mekf_wind_get_airspeed_norm(void)
float tas_from_eas(float eas)
Calculate true airspeed from equivalent airspeed.
float ins_mekf_wind_get_baro_bias(void)
static void stateSetPositionUtm_f(struct UtmCoor_f *utm_pos)
Set position from UTM coordinates (float).
static abi_event airspeed_ev
struct FloatQuat ins_mekf_wind_get_quat(void)
static void stateSetSpeedNed_f(struct NedCoor_f *ned_speed)
Set ground speed in local NED coordinates (float).
static abi_event pressure_diff_ev
#define INS_MEKF_WIND_AIRSPEED_ID
airspeed (Pitot tube)
void ins_mekf_wind_update_pos_speed(struct FloatVect3 *pos, struct FloatVect3 *speed)
Paparazzi specific wrapper to run MEKF-Wind INS filter.
int32_t hmsl
height above mean sea level (MSL) in mm
void float_rmat_transp_vmult(struct FloatVect3 *vb, struct FloatRMat *m_b2a, struct FloatVect3 *va)
rotate 3D vector by transposed rotation matrix.
#define RATES_FLOAT_OF_BFP(_rf, _ri)
vector in North East Down coordinates Units: meters
Architecture independent timing functions.
data structure for GPS information
#define INT32_POS_OF_CM_NUM
#define INS_MEKF_WIND_MAG_ID
magnetometer
static void stateSetLocalOrigin_i(struct LtpDef_i *ltp_def)
Set the local (flat earth) coordinate frame origin (int).
#define INS_MEKF_WIND_BARO_ID
baro
static struct FloatVect3 ins_mekf_wind_accel
last accel measurement
Paparazzi atmospheric pressure conversion utilities.
float tas_from_dynamic_pressure(float q)
Calculate true airspeed from dynamic pressure.
struct EcefCoor_i ecef_pos
position in ECEF in cm
static abi_event aligner_ev
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
struct LlaCoor_i lla
Reference point in lla.
#define DefaultPeriodic
Set default periodic telemetry.
struct OrientationReps body_to_imu
int32_t lon
in degrees*1e7
struct FloatRates ins_mekf_wind_get_rates_bias(void)
static void aligner_cb(uint8_t sender_id, uint32_t stamp, struct Int32Rates *lp_gyro, struct Int32Vect3 *lp_accel, struct Int32Vect3 *lp_mag)
void ins_mekf_wind_set_pos_ned(struct NedCoor_f *p)
uint8_t zone
UTM zone number.
static void stateSetPositionNed_f(struct NedCoor_f *ned_pos)
Set position from local NED coordinates (float).
struct UtmCoor_f utm_origin_f
Definition of the origin of Utm coordinate system.
#define ACCELS_FLOAT_OF_BFP(_ef, _ei)
#define INS_MEKF_WIND_FILTER_ID
void ins_mekf_wind_propagate(struct FloatRates *gyro, struct FloatVect3 *acc, float dt)
Full INS propagation.
struct NedCoor_f ins_mekf_wind_get_accel_ned(void)
static const struct usb_device_descriptor dev
struct LtpDef_i ned_origin_i
Definition of the local (flat earth) coordinate system.
static void gps_cb(uint8_t sender_id, uint32_t stamp, struct GpsState *gps_s)
static void ahrs_float_get_quat_from_accel_mag(struct FloatQuat *q, struct FloatVect3 *accel, struct FloatVect3 *mag)
#define PPRZ_ISA_SEA_LEVEL_PRESSURE
ISA sea level standard atmospheric pressure in Pascal.
void ins_mekf_wind_wrapper_init(void)
Init function.
static void h(const real32_T x[7], const real32_T q[4], real32_T y[6])
struct FloatRates ins_mekf_wind_get_body_rates(void)
#define INT32_POS_OF_CM_DEN
struct UtmCoor_f utm_float_from_gps(struct GpsState *gps_s, uint8_t zone)
Convenience functions to get utm position from GPS state.
API to get/set the generic vehicle states.
static void accel_cb(uint8_t sender_id, uint32_t stamp, struct Int32Vect3 *accel)
void float_rmat_transp_ratemult(struct FloatRates *rb, struct FloatRMat *m_b2a, struct FloatRates *ra)
rotate anglular rates by transposed rotation matrix.
static void send_euler(struct transport_tx *trans, struct link_device *dev)
logging functions
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.
vector in North East Down coordinates
static void baro_cb(uint8_t sender_id, uint32_t stamp, float pressure)
static abi_event geo_mag_ev
void ins_mekf_wind_update_airspeed(float airspeed)
static void geo_mag_cb(uint8_t sender_id, struct FloatVect3 *h)
#define ABI_BROADCAST
Broadcast address.
#define MAGS_FLOAT_OF_BFP(_ef, _ei)
static void mag_cb(uint8_t sender_id, uint32_t stamp, struct Int32Vect3 *mag)
static abi_event body_to_imu_ev
void ecef_of_lla_i(struct EcefCoor_i *out, struct LlaCoor_i *in)
Convert a LLA to ECEF.
struct EcefCoor_i ecef_vel
speed ECEF in cm/s
#define INS_MEKF_WIND_GPS_ID
ABI binding for gps data.
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
static float pprz_isa_height_of_pressure(float pressure, float ref_p)
Get relative altitude from pressure (using simplified equation).
#define ECEF_FLOAT_OF_BFP(_o, _i)
void ins_mekf_wind_propagate_ahrs(struct FloatRates *gyro, struct FloatVect3 *acc, float dt)
AHRS-only propagation + accel correction.
static void send_filter_status(struct transport_tx *trans, struct link_device *dev)
#define INS_MEKF_WIND_INCIDENCE_ID
incidence angles
void ins_mekf_wind_update_mag(struct FloatVect3 *mag, bool attitude_only)
Fixedwing Navigation library.
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
static void pressure_diff_cb(uint8_t sender_id, float pdyn)
int32_t lat
in degrees*1e7
static void incidence_cb(uint8_t sender_id, uint8_t flag, float aoa, float sideslip)
static void stateSetBodyRates_f(struct FloatRates *body_rate)
Set vehicle body angular rate (float).
void float_eulers_of_quat(struct FloatEulers *e, struct FloatQuat *q)
euler rotation 'ZYX'
void ins_reset_altitude_ref(void)
INS altitude reference reset.
void ahrs_aligner_init(void)
struct NedCoor_i ned_vel
speed NED in cm/s
struct FloatVect3 ins_mekf_wind_get_accel_bias(void)
static void stateSetAccelNed_f(struct NedCoor_f *ned_accel)
Set acceleration in NED coordinates (float).
void ins_mekf_wind_update_incidence(float aoa, float aos)
static void stateSetLocalUtmOrigin_f(struct UtmCoor_f *utm_def)
Set the local (flat earth) coordinate frame origin from UTM (float).
struct GpsState gps
global GPS state
void ltp_def_from_ecef_i(struct LtpDef_i *def, struct EcefCoor_i *ecef)
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
struct NedCoor_f ins_mekf_wind_get_pos_ned(void)
Getter/Setter functions.