|
Paparazzi UAS
v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
|
Go to the documentation of this file.
39 #include "generated/airframe.h"
40 #include "generated/flight_plan.h"
42 #define MEKF_WIND_USE_UTM TRUE
47 #ifndef INS_MEKF_WIND_FILTER_ID
48 #define INS_MEKF_WIND_FILTER_ID 3
64 #define PrintLog sdLogWriteLog
65 #define LogFileIsOpen() (pprzLogFile != -1)
66 #else // SITL: print in a file
68 #define PrintLog fprintf
69 #define LogFileIsOpen() (pprzLogFile != NULL)
75 #if PERIODIC_TELEMETRY
79 static void send_euler(
struct transport_tx *trans,
struct link_device *
dev)
85 pprz_msg_send_AHRS_EULER(trans,
dev, AC_ID,
86 <p_to_imu_euler.
phi,
87 <p_to_imu_euler.
theta,
88 <p_to_imu_euler.
psi,
92 static void send_wind(
struct transport_tx *trans,
struct link_device *
dev)
99 pprz_msg_send_WIND_INFO_RET(trans,
dev, AC_ID, &flags,
100 &wind_enu.
x, &wind_enu.
y, &wind_enu.
z, &va);
114 if (t_diff > 50000) {
118 pprz_msg_send_STATE_FILTER_STATUS(trans,
dev, AC_ID, &
id, &mde, &
val);
133 pprz_msg_send_INV_FILTER(trans,
dev,
160 #ifndef INS_MEKF_WIND_AIRSPEED_ID
161 #define INS_MEKF_WIND_AIRSPEED_ID ABI_BROADCAST
166 #ifndef INS_MEKF_WIND_INCIDENCE_ID
167 #define INS_MEKF_WIND_INCIDENCE_ID ABI_BROADCAST
172 #ifndef INS_MEKF_WIND_BARO_ID
174 #define INS_MEKF_WIND_BARO_ID BARO_BOARD_SENDER_ID
176 #define INS_MEKF_WIND_BARO_ID ABI_BROADCAST
182 #ifndef INS_MEKF_WIND_IMU_ID
183 #define INS_MEKF_WIND_IMU_ID ABI_BROADCAST
188 #ifndef INS_MEKF_WIND_MAG_ID
189 #define INS_MEKF_WIND_MAG_ID ABI_BROADCAST
196 #ifndef INS_MEKF_WIND_GPS_ID
197 #define INS_MEKF_WIND_GPS_ID GPS_MULTI_ID
217 static float alpha = 10.0f;
219 static float baro_moy = 0.0f;
220 static float baro_prev = 0.0f;
227 baro_prev = pressure;
229 baro_moy = (baro_moy * (i - 1) + pressure) / i;
230 alpha = (10.*
alpha + (baro_moy - baro_prev)) / (11.0f);
231 baro_prev = baro_moy;
233 if (fabs(
alpha) < 0.1f) {
248 if (LogFileIsOpen()) {
263 if (LogFileIsOpen()) {
276 if (LogFileIsOpen()) {
289 if (LogFileIsOpen()) {
311 #if USE_AUTO_INS_FREQ || !defined(INS_PROPAGATE_FREQUENCY)
323 PRINT_CONFIG_MSG(
"Using fixed INS_PROPAGATE_FREQUENCY for INS MEKF_WIND propagation.")
324 PRINT_CONFIG_VAR(INS_PROPAGATE_FREQUENCY)
325 const float dt = 1. / (INS_PROPAGATE_FREQUENCY);
337 if (LogFileIsOpen()) {
341 "%.3f gyro_accel %.3f %.3f %.3f %.3f %.3f %.3f \n",
343 gyro_body.
p, gyro_body.
q, gyro_body.
r,
361 "%.3f output %.4f %.4f %.4f %.3f %.3f %.3f ",
364 rates.
p, rates.
q, rates.
r);
366 "%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f ",
368 speed.
x, speed.
y, speed.
z,
369 accel.
x, accel.
y, accel.
z);
371 "%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f\n",
372 ab.
x, ab.
y, ab.
z, rb.
p, rb.
q, rb.
r, bb,
373 wind.
x, wind.
y, wind.
z, airspeed);
383 uint32_t stamp __attribute__((unused)),
394 uint32_t stamp __attribute__((unused)),
407 if (LogFileIsOpen()) {
409 "%.3f magneto %.3f %.3f %.3f\n",
411 mag_body.
x, mag_body.
y, mag_body.
z);
418 uint32_t stamp __attribute__((unused)),
464 uint32_t stamp __attribute__((unused)),
469 #if MEKF_WIND_USE_UTM
489 if (LogFileIsOpen()) {
491 "%.3f gps %.3f %.3f %.3f %.3f %.3f %.3f \n",
493 pos.
x, pos.
y, pos.
z, speed.
x, speed.
y, speed.
z);
501 struct NedCoor_i gps_pos_cm_ned, ned_pos;
511 if (LogFileIsOpen()) {
513 "%.3f gps %.3f %.3f %.3f %.3f %.3f %.3f \n",
515 pos.
x, pos.
y, pos.
z, speed.
x, speed.
y, speed.
z);
550 #if MEKF_WIND_USE_UTM
554 utm0.
alt = GROUND_ALT;
560 llh_nav0.
lat = NAV_LAT0;
561 llh_nav0.
lon = NAV_LON0;
562 llh_nav0.
alt = NAV_ALT0 + NAV_MSL0;
584 const struct FloatVect3 mag_h = { INS_H_X, INS_H_Y, INS_H_Z };
600 #if PERIODIC_TELEMETRY
608 #if LOG_MEKF_WIND && SITL
613 snprintf(filename, 512,
"%s/mekf_wind_%05d.csv", STRINGIFY(MEKF_WIND_LOG_PATH),
counter);
617 snprintf(filename, 512,
"%s/mekf_wind_%05d.csv", STRINGIFY(MEKF_WIND_LOG_PATH), ++
counter);
621 printf(
"Failed to open WE log file '%s'\n",filename);
623 printf(
"Opening WE log file '%s'\n",filename);
635 #if MEKF_WIND_USE_UTM
651 #if MEKF_WIND_USE_UTM
#define MAGS_FLOAT_OF_BFP(_ef, _ei)
int32_t lon
in degrees*1e7
vector in North East Down coordinates Units: meters
float tas_from_eas(float eas)
Calculate true airspeed from equivalent airspeed.
#define INS_MEKF_WIND_AIRSPEED_ID
airspeed (Pitot tube)
int32_t alt
in millimeters above WGS84 reference ellipsoid
void ins_mekf_wind_init(void)
Init function.
static abi_event body_to_imu_ev
void ins_mekf_wind_update_mag(struct FloatVect3 *mag, bool attitude_only)
static void send_inv_filter(struct transport_tx *trans, struct link_device *dev)
#define INT32_VECT3_SCALE_2(_a, _b, _num, _den)
static void stateSetSpeedNed_f(struct NedCoor_f *ned_speed)
Set ground speed in local NED coordinates (float).
void ltp_def_from_ecef_i(struct LtpDef_i *def, struct EcefCoor_i *ecef)
struct LtpDef_i ned_origin_i
Definition of the local (flat earth) coordinate system.
static void h(const real32_T x[7], const real32_T q[4], real32_T y[6])
static struct FloatVect3 ins_mekf_wind_accel
last accel measurement
static abi_event pressure_diff_ev
definition of the local (flat earth) coordinate system
static float get_sys_time_float(void)
Get the time in seconds since startup.
struct NedCoor_f ins_mekf_wind_get_accel_ned(void)
void ins_reset_altitude_ref(void)
INS altitude reference reset.
void ins_mekf_wind_set_speed_ned(struct NedCoor_f *s)
void ned_of_ecef_vect_f(struct NedCoor_f *ned, struct LtpDef_f *def, struct EcefCoor_f *ecef)
#define INS_MEKF_WIND_GPS_ID
ABI binding for gps data.
data structure for GPS information
struct OrientationReps body_to_imu
#define RATES_FLOAT_OF_BFP(_rf, _ri)
Event structure to store callbacks in a linked list.
static void gps_cb(uint8_t sender_id, uint32_t stamp, struct GpsState *gps_s)
static abi_event airspeed_ev
float ins_mekf_wind_get_baro_bias(void)
#define INS_MEKF_WIND_BARO_ID
baro
void ecef_of_lla_i(struct EcefCoor_i *out, struct LlaCoor_i *in)
Convert a LLA to ECEF.
static void send_euler(struct transport_tx *trans, struct link_device *dev)
logging functions
void ins_mekf_wind_update_incidence(float aoa, float aos)
static void stateSetPositionUtm_f(struct UtmCoor_f *utm_pos)
Set position from UTM coordinates (float).
static abi_event geo_mag_ev
void ins_mekf_wind_set_quat(struct FloatQuat *quat)
void ins_reset_local_origin(void)
local implemetation of the ins_reset functions
#define INT32_POS_OF_CM_NUM
static void gyro_cb(uint8_t sender_id, uint32_t stamp, struct Int32Rates *gyro)
Call ins_mekf_wind_propagate on new gyro measurements.
#define INS_MEKF_WIND_MAG_ID
magnetometer
struct NedCoor_i ned_vel
speed NED in cm/s
#define INT32_POS_OF_CM_DEN
static struct FloatRMat * orientationGetRMat_f(struct OrientationReps *orientation)
Get vehicle body attitude rotation matrix (float).
static void incidence_cb(uint8_t sender_id, uint8_t flag, float aoa, float sideslip)
static uint32_t last_imu_stamp
static abi_event aligner_ev
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
void float_rmat_transp_vmult(struct FloatVect3 *vb, struct FloatRMat *m_b2a, struct FloatVect3 *va)
rotate 3D vector by transposed rotation matrix.
int32_t lat
in degrees*1e7
#define NED_FLOAT_OF_BFP(_o, _i)
struct NedCoor_f ins_mekf_wind_get_wind_ned(void)
static void stateSetLocalUtmOrigin_f(struct UtmCoor_f *utm_def)
Set the local (flat earth) coordinate frame origin from UTM (float).
#define INS_MEKF_WIND_INCIDENCE_ID
incidence angles
float alt
in meters (above WGS84 reference ellipsoid or above MSL)
uint8_t zone
UTM zone number.
static void set_state_from_ins(void)
update state interface
static void orientationSetQuat_f(struct OrientationReps *orientation, struct FloatQuat *quat)
Set vehicle body attitude from quaternion (float).
static void mag_cb(uint8_t sender_id, uint32_t stamp, struct Int32Vect3 *mag)
vector in EarthCenteredEarthFixed coordinates
vector in North East Down coordinates
static const struct usb_device_descriptor dev
static void stateSetBodyRates_f(struct FloatRates *body_rate)
Set vehicle body angular rate (float).
#define ECEF_FLOAT_OF_BFP(_o, _i)
static void geo_mag_cb(uint8_t sender_id, struct FloatVect3 *h)
bool utm_initialized_f
True if utm origin (float) coordinate frame is initialsed.
void ins_mekf_wind_align(struct FloatRates *gyro_bias, struct FloatQuat *quat)
Architecture independent timing functions.
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
struct LtpDef_f ned_origin_f
Definition of the local (flat earth) coordinate system.
static void pressure_diff_cb(uint8_t sender_id, float pdyn)
static void stateSetLocalOrigin_i(struct LtpDef_i *ltp_def)
Set the local (flat earth) coordinate frame origin (int).
vector in East North Up coordinates Units: meters
void ins_mekf_wind_update_pos_speed(struct FloatVect3 *pos, struct FloatVect3 *speed)
static void baro_cb(uint8_t sender_id, uint32_t stamp, float pressure)
void ltp_def_from_lla_i(struct LtpDef_i *def, struct LlaCoor_i *lla)
struct FloatRates ins_mekf_wind_get_rates_bias(void)
static void send_filter_status(struct transport_tx *trans, struct link_device *dev)
void ins_mekf_wind_propagate_ahrs(struct FloatRates *gyro, struct FloatVect3 *acc, float dt)
AHRS-only propagation + accel correction.
static float pprz_isa_height_of_pressure(float pressure, float ref_p)
Get relative altitude from pressure (using simplified equation).
float tas_from_dynamic_pressure(float q)
Calculate true airspeed from dynamic pressure.
static void stateSetAccelNed_f(struct NedCoor_f *ned_accel)
Set acceleration in NED coordinates (float).
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
struct EcefCoor_i ecef_pos
position in ECEF in cm
struct UtmCoor_f utm_float_from_gps(struct GpsState *gps_s, uint8_t zone)
Convenience functions to get utm position from GPS state.
static void body_to_imu_cb(uint8_t sender_id, struct FloatQuat *q_b2i)
#define INS_MEKF_WIND_IMU_ID
IMU (gyro, accel)
#define ins_mekf_wind_wrapper_Reset(_v)
struct InsMekfWind ins_mekf_wind
vector in Latitude, Longitude and Altitude
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
int32_t hmsl
Height above mean sea level in mm.
struct FloatQuat ins_mekf_wind_get_quat(void)
vector in EarthCenteredEarthFixed coordinates
static void stateSetPositionNed_f(struct NedCoor_f *ned_pos)
Set position from local NED coordinates (float).
position in UTM coordinates Units: meters
int32_t hmsl
height above mean sea level (MSL) in mm
void float_rmat_transp_ratemult(struct FloatRates *rb, struct FloatRMat *m_b2a, struct FloatRates *ra)
rotate anglular rates by transposed rotation matrix.
#define ACCELS_FLOAT_OF_BFP(_ef, _ei)
struct UtmCoor_f utm_origin_f
Definition of the origin of Utm coordinate system.
struct FloatRates ins_mekf_wind_get_body_rates(void)
bool ned_initialized_f
True if local float coordinate frame is initialsed.
static void ahrs_float_get_quat_from_accel_mag(struct FloatQuat *q, struct FloatVect3 *accel, struct FloatVect3 *mag)
void ins_mekf_wind_set_pos_ned(struct NedCoor_f *p)
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.
#define ENU_OF_TO_NED(_po, _pi)
static void accel_cb(uint8_t sender_id, uint32_t stamp, struct Int32Vect3 *accel)
void ins_mekf_wind_propagate(struct FloatRates *gyro, struct FloatVect3 *acc, float dt)
Full INS propagation.
struct NedCoor_f ins_mekf_wind_get_speed_ned(void)
void float_eulers_of_quat(struct FloatEulers *e, struct FloatQuat *q)
euler rotation 'ZYX'
struct EcefCoor_i ecef_vel
speed ECEF in cm/s
void ins_mekf_wind_set_mag_h(const struct FloatVect3 *mag_h)
float ins_mekf_wind_get_airspeed_norm(void)
static void send_wind(struct transport_tx *trans, struct link_device *dev)
struct NedCoor_f ins_mekf_wind_get_pos_ned(void)
Getter/Setter functions.
void ins_mekf_wind_update_baro(float baro_alt)
#define ABI_BROADCAST
Broadcast address.
struct GpsState gps
global GPS state
static void airspeed_cb(uint8_t sender_id, float airspeed)
#define GPS_FIX_3D
3D GPS fix
struct LlaCoor_i lla
Reference point in lla.
static void aligner_cb(uint8_t sender_id, uint32_t stamp, struct Int32Rates *lp_gyro, struct Int32Vect3 *lp_accel, struct Int32Vect3 *lp_mag)
#define DefaultPeriodic
Set default periodic telemetry.
void ins_mekf_wind_wrapper_init(void)
Init function.
static abi_event incidence_ev
static void stateSetNedToBodyQuat_f(struct FloatQuat *ned_to_body_quat)
Set vehicle body attitude from quaternion (float).
#define PPRZ_ISA_SEA_LEVEL_PRESSURE
ISA sea level standard atmospheric pressure in Pascal.
struct FloatVect3 ins_mekf_wind_get_accel_bias(void)
static abi_event accel_ev
void ahrs_aligner_init(void)
#define INS_MEKF_WIND_FILTER_ID
Paparazzi atmospheric pressure conversion utilities.
void ins_mekf_wind_update_airspeed(float airspeed)