Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
ins_mekf_wind_wrapper.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2017 Gautier Hattenberger <gautier.hattenberger@enac.fr>
3 *
4 * This file is part of paparazzi.
5 *
6 * paparazzi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * paparazzi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with paparazzi; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
19 */
20
26
31#if USE_AHRS_ALIGNER
33#endif
34#include "modules/ins/ins.h"
35#include "modules/core/abi.h"
36#include "math/pprz_isa.h"
37#include "state.h"
38
39#include "generated/airframe.h"
40#include "generated/flight_plan.h"
41
42#if FIXEDWING_FIRMWARE
44#endif
45
46#ifndef INS_MEKF_WIND_FILTER_ID
47#define INS_MEKF_WIND_FILTER_ID 3
48#endif
49
51
55
57static void set_state_from_ins(void);
58
60#if LOG_MEKF_WIND
61#ifndef SITL
63#define PrintLog sdLogWriteLog
64#define LogFileIsOpen() (pprzLogFile != -1)
65#else // SITL: print in a file
66#include <stdio.h>
67#define PrintLog fprintf
68#define LogFileIsOpen() (pprzLogFile != NULL)
69static FILE* pprzLogFile = NULL;
70#endif
71#endif
72
74#if PERIODIC_TELEMETRY
76#include "mcu_periph/sys_time.h"
77
78static void send_euler(struct transport_tx *trans, struct link_device *dev)
79{
80 struct FloatEulers ltp_to_imu_euler;
81 struct FloatQuat quat = ins_mekf_wind_get_quat();
82 float_eulers_of_quat(&ltp_to_imu_euler, &quat);
84 pprz_msg_send_AHRS_EULER(trans, dev, AC_ID,
85 &ltp_to_imu_euler.phi,
86 &ltp_to_imu_euler.theta,
87 &ltp_to_imu_euler.psi,
88 &id);
89}
90
91static void send_wind(struct transport_tx *trans, struct link_device *dev)
92{
93 struct NedCoor_f wind_ned = ins_mekf_wind_get_wind_ned();
94 struct EnuCoor_f wind_enu;
95 ENU_OF_TO_NED(wind_enu, wind_ned);
97 uint8_t flags = 7; // 3D wind + airspeed
98 pprz_msg_send_WIND_INFO_RET(trans, dev, AC_ID, &flags,
99 &wind_enu.x, &wind_enu.y, &wind_enu.z, &va);
100}
101
102static void send_filter_status(struct transport_tx *trans, struct link_device *dev)
103{
104 uint8_t mde = 3; // OK
105 uint16_t val = 0;
106 if (!ins_mekf_wind.is_aligned) {
107 mde = 2; // ALIGN
108 } else if (!ins_mekf_wind.baro_initialized || !ins_mekf_wind.gps_initialized) {
109 mde = 1; // INIT
110 }
112 /* set lost if no new gyro measurements for 50ms */
113 if (t_diff > 50000) {
114 mde = 5; // IMU_LOST
115 }
117 pprz_msg_send_STATE_FILTER_STATUS(trans, dev, AC_ID, &id, &mde, &val);
118}
119
120static void send_inv_filter(struct transport_tx *trans, struct link_device *dev)
121{
122 struct FloatEulers eulers;
123 struct FloatQuat quat = ins_mekf_wind_get_quat();
124 float_eulers_of_quat(&eulers, &quat);
125 //struct FloatRates rates = ins_mekf_wind_get_body_rates();
127 struct NedCoor_f speed = ins_mekf_wind_get_speed_ned();
128 //struct NedCoor_f accel = ins_mekf_wind_get_accel_ned();
131 float airspeed = ins_mekf_wind_get_airspeed_norm();
132 pprz_msg_send_INV_FILTER(trans, dev,
133 AC_ID,
134 &quat.qi,
135 &eulers.phi,
136 &eulers.theta,
137 &eulers.psi,
138 &speed.x,
139 &speed.y,
140 &speed.z,
141 &pos.x,
142 &pos.y,
143 &pos.z,
144 &rb.p,
145 &rb.q,
146 &rb.r,
147 &ab.x,
148 &ab.y,
149 &ab.z,
150 &airspeed);
151}
152#endif
153
154/*
155 * ABI bindings
156 */
157
159#ifndef INS_MEKF_WIND_AIRSPEED_ID
160#define INS_MEKF_WIND_AIRSPEED_ID AIR_DATA_SENDER_ID
161#endif
163
164
165#ifndef INS_MEKF_WIND_INCIDENCE_ID
166#define INS_MEKF_WIND_INCIDENCE_ID ABI_BROADCAST
167#endif
169
170
171#ifndef INS_MEKF_WIND_BARO_ID
172#define INS_MEKF_WIND_BARO_ID AIR_DATA_SENDER_ID
173#endif
175
176
177#ifndef INS_MEKF_WIND_IMU_ID
178#define INS_MEKF_WIND_IMU_ID ABI_BROADCAST
179#endif
181
182
183#ifndef INS_MEKF_WIND_MAG_ID
184#define INS_MEKF_WIND_MAG_ID ABI_BROADCAST
185#endif
187
188
191#ifndef INS_MEKF_WIND_GPS_ID
192#define INS_MEKF_WIND_GPS_ID GPS_MULTI_ID
193#endif
195
207
208static void reset_cb(uint8_t sender_id, uint8_t flag);
209
210static void baro_cb(uint8_t __attribute__((unused)) sender_id, __attribute__((unused)) uint32_t stamp, float pressure)
211{
212 static float ins_qfe = PPRZ_ISA_SEA_LEVEL_PRESSURE;
213 static float alpha = 10.0f;
214 static int32_t i = 1;
215 static float baro_moy = 0.0f;
216 static float baro_prev = 0.0f;
217
218 if (!ins_mekf_wind.baro_initialized) {
219 // try to find a stable qfe
220 // TODO generic function in pprz_isa ?
221 if (i == 1) {
222 baro_moy = pressure;
223 baro_prev = pressure;
224 }
225 baro_moy = (baro_moy * (i - 1) + pressure) / i;
226 alpha = (10.*alpha + (baro_moy - baro_prev)) / (11.0f);
227 baro_prev = baro_moy;
228 // test stop condition
229 if (fabs(alpha) < 0.1f) {
230 ins_qfe = baro_moy;
231 ins_mekf_wind.baro_initialized = true;
232 }
233 if (i == 250) {
234 ins_qfe = pressure;
235 ins_mekf_wind.baro_initialized = true;
236 }
237 i++;
238 } else { /* normal update with baro measurement */
239 if (ins_mekf_wind.is_aligned && ins_mekf_wind.gps_initialized) {
240 float baro_alt = -pprz_isa_height_of_pressure(pressure, ins_qfe); // Z down
242
243#if LOG_MEKF_WIND
244 if (LogFileIsOpen()) {
245 PrintLog(pprzLogFile, "%.3f baro %.3f \n", get_sys_time_float(), baro_alt);
246 }
247#endif
248 }
249 }
250}
251
252static void pressure_diff_cb(uint8_t __attribute__((unused)) sender_id, float pdyn)
253{
254 if (ins_mekf_wind.is_aligned) {
255 float airspeed = tas_from_dynamic_pressure(pdyn);
257
258#if LOG_MEKF_WIND
259 if (LogFileIsOpen()) {
260 PrintLog(pprzLogFile, "%.3f airspeed %.3f\n", get_sys_time_float(), airspeed);
261 }
262#endif
263 }
264}
265
266static void airspeed_cb(uint8_t __attribute__((unused)) sender_id, float airspeed)
267{
268 if (ins_mekf_wind.is_aligned) {
270
271#if LOG_MEKF_WIND
272 if (LogFileIsOpen()) {
273 PrintLog(pprzLogFile, "%.3f airspeed %.3f\n", get_sys_time_float(), airspeed);
274 }
275#endif
276 }
277}
278
279static void incidence_cb(uint8_t __attribute__((unused)) sender_id, uint8_t flag, float aoa, float sideslip)
280{
281 if (ins_mekf_wind.is_aligned && bit_is_set(flag, 0) && bit_is_set(flag, 1)) {
282 ins_mekf_wind_update_incidence(aoa, sideslip);
283
284#if LOG_MEKF_WIND
285 if (LogFileIsOpen()) {
286 PrintLog(pprzLogFile, "%.3f incidence %.3f %.3f\n", get_sys_time_float(), aoa, sideslip);
287 }
288#endif
289 }
290}
291
297static void gyro_cb(uint8_t sender_id __attribute__((unused)),
298 uint32_t stamp, struct Int32Rates *gyro)
299{
300 if (ins_mekf_wind.is_aligned) {
301 struct FloatRates gyro_body;
302 RATES_FLOAT_OF_BFP(gyro_body, *gyro);
303
304#if USE_AUTO_INS_FREQ || !defined(INS_PROPAGATE_FREQUENCY)
305 PRINT_CONFIG_MSG("Calculating dt for INS MEKF_WIND propagation.")
306
307 if (last_imu_stamp > 0) {
308 float dt = (float)(stamp - last_imu_stamp) * 1e-6;
309 if (ins_mekf_wind.gps_initialized) {
311 } else {
313 }
314 }
315#else
316 PRINT_CONFIG_MSG("Using fixed INS_PROPAGATE_FREQUENCY for INS MEKF_WIND propagation.")
317 PRINT_CONFIG_VAR(INS_PROPAGATE_FREQUENCY)
318 const float dt = 1. / (INS_PROPAGATE_FREQUENCY);
319 if (ins_mekf_wind.gps_initialized) {
321 } else {
323 }
324#endif
325
326 // update state interface
328
329#if LOG_MEKF_WIND
330 if (LogFileIsOpen()) {
331 float time = get_sys_time_float();
332
333 PrintLog(pprzLogFile,
334 "%.3f gyro_accel %.3f %.3f %.3f %.3f %.3f %.3f \n",
335 time,
336 gyro_body.p, gyro_body.q, gyro_body.r,
340
341 struct FloatEulers eulers;
342 struct FloatQuat quat = ins_mekf_wind_get_quat();
343 float_eulers_of_quat(&eulers, &quat);
346 struct NedCoor_f speed = ins_mekf_wind_get_speed_ned();
347 struct NedCoor_f accel = ins_mekf_wind_get_accel_ned();
350 float bb = ins_mekf_wind_get_baro_bias();
352 float airspeed = ins_mekf_wind_get_airspeed_norm();
353 PrintLog(pprzLogFile,
354 "%.3f output %.4f %.4f %.4f %.3f %.3f %.3f ",
355 time,
356 eulers.phi, eulers.theta, eulers.psi,
357 rates.p, rates.q, rates.r);
358 PrintLog(pprzLogFile,
359 "%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f ",
360 pos.x, pos.y, pos.z,
361 speed.x, speed.y, speed.z,
362 accel.x, accel.y, accel.z);
363 PrintLog(pprzLogFile,
364 "%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f\n",
365 ab.x, ab.y, ab.z, rb.p, rb.q, rb.r, bb,
366 wind.x, wind.y, wind.z, airspeed);
367 }
368#endif
369 }
370
371 /* timestamp in usec when last callback was received */
372 last_imu_stamp = stamp;
373}
374
375static void accel_cb(uint8_t sender_id __attribute__((unused)),
376 uint32_t stamp __attribute__((unused)),
377 struct Int32Vect3 *accel)
378{
380}
381
382static void mag_cb(uint8_t sender_id __attribute__((unused)),
383 uint32_t stamp __attribute__((unused)),
384 struct Int32Vect3 *mag)
385{
386 if (ins_mekf_wind.is_aligned) {
387 struct FloatVect3 mag_body;
388 MAGS_FLOAT_OF_BFP(mag_body, *mag);
389
390 // only correct attitude if GPS is not initialized
391 ins_mekf_wind_update_mag(&mag_body, !ins_mekf_wind.gps_initialized);
392
393#if LOG_MEKF_WIND
394 if (LogFileIsOpen()) {
395 PrintLog(pprzLogFile,
396 "%.3f magneto %.3f %.3f %.3f\n",
398 mag_body.x, mag_body.y, mag_body.z);
399 }
400#endif
401 }
402}
403
404static void aligner_cb(uint8_t __attribute__((unused)) sender_id,
405 uint32_t stamp __attribute__((unused)),
406 struct Int32Rates *lp_gyro, struct Int32Vect3 *lp_accel,
407 struct Int32Vect3 *lp_mag)
408{
409 if (!ins_mekf_wind.is_aligned) {
410 struct FloatRates gyro_body;
411 RATES_FLOAT_OF_BFP(gyro_body, *lp_gyro);
412
413 struct FloatVect3 accel_body;
414 ACCELS_FLOAT_OF_BFP(accel_body, *lp_accel);
415
416 struct FloatVect3 mag_body;
417 MAGS_FLOAT_OF_BFP(mag_body, *lp_mag);
418
419 struct FloatQuat quat;
420 ahrs_float_get_quat_from_accel_mag(&quat, &accel_body, &mag_body);
421 ins_mekf_wind_align(&gyro_body, &quat);
422 // udate state interface
424
425 // ins and ahrs are now running
426 ins_mekf_wind.is_aligned = true;
427 }
428}
429
430static void geo_mag_cb(uint8_t sender_id __attribute__((unused)), struct FloatVect3 *h)
431{
433}
434
435static void gps_cb(uint8_t sender_id __attribute__((unused)),
436 uint32_t stamp __attribute__((unused)),
437 struct GpsState *gps_s)
438{
439 if (ins_mekf_wind.is_aligned && gps_s->fix >= GPS_FIX_3D) {
440
441#if FIXEDWING_FIRMWARE
442 if (state.utm_initialized_f) {
443 struct UtmCoor_f utm = utm_float_from_gps(gps_s, nav_utm_zone0);
444 struct NedCoor_f pos, speed;
445 // position (local ned)
446 pos.x = utm.north - stateGetUtmOrigin_f()->north;
447 pos.y = utm.east - stateGetUtmOrigin_f()->east;
448 pos.z = stateGetHmslOrigin_f() - utm.alt;
449 // speed
450 speed = ned_vel_float_from_gps(gps_s);
451 if (!ins_mekf_wind.gps_initialized) {
454 ins_mekf_wind.gps_initialized = true;
455 }
456 ins_mekf_wind_update_pos_speed((struct FloatVect3*)(&pos), (struct FloatVect3*)(&speed));
457
458#if LOG_MEKFW_FILTER
459 if (LogFileIsOpen()) {
460 PrintLog(pprzLogFile,
461 "%.3f gps %.3f %.3f %.3f %.3f %.3f %.3f \n",
463 pos.x, pos.y, pos.z, speed.x, speed.y, speed.z);
464 }
465#endif
466 }
467
468#else
469 if (state.ned_initialized_f) {
470 struct NedCoor_f pos, speed;
471 struct NedCoor_i gps_pos_cm_ned, ned_pos;
472 struct EcefCoor_i ecef_pos_i = ecef_int_from_gps(gps_s);
473 ned_of_ecef_point_i(&gps_pos_cm_ned, stateGetNedOrigin_i(), &ecef_pos_i);
475 NED_FLOAT_OF_BFP(pos, ned_pos);
476 struct EcefCoor_f ecef_vel = ecef_vel_float_from_gps(gps_s);
477 ned_of_ecef_vect_f(&speed, stateGetNedOrigin_f(), &ecef_vel);
478 ins_mekf_wind_update_pos_speed((struct FloatVect3*)(&pos), (struct FloatVect3*)(&speed));
479
480#if LOG_MEKFW_FILTER
481 if (LogFileIsOpen()) {
482 PrintLog(pprzLogFile,
483 "%.3f gps %.3f %.3f %.3f %.3f %.3f %.3f \n",
485 pos.x, pos.y, pos.z, speed.x, speed.y, speed.z);
486 }
487#endif
488 }
489#endif
490 }
491}
492
496static void set_state_from_ins(void)
497{
498 struct FloatQuat quat = ins_mekf_wind_get_quat();
499 stateSetNedToBodyQuat_f(MODULE_INS_MEKF_WIND_ID, &quat);
500
502 stateSetBodyRates_f(MODULE_INS_MEKF_WIND_ID, &rates);
503
505 stateSetPositionNed_f(MODULE_INS_MEKF_WIND_ID, &pos);
506
507 struct NedCoor_f speed = ins_mekf_wind_get_speed_ned();
508 stateSetSpeedNed_f(MODULE_INS_MEKF_WIND_ID, &speed);
509
510 struct NedCoor_f accel = ins_mekf_wind_get_accel_ned();
511 stateSetAccelNed_f(MODULE_INS_MEKF_WIND_ID, &accel);
512}
513
518{
519 // init position
520#if FIXEDWING_FIRMWARE
521 struct UtmCoor_f utm0;
522 utm0.north = (float)nav_utm_north0;
523 utm0.east = (float)nav_utm_east0;
524 utm0.alt = GROUND_ALT;
525 utm0.zone = nav_utm_zone0;
526 stateSetLocalUtmOrigin_f(MODULE_INS_MEKF_WIND_ID, &utm0);
527 stateSetPositionUtm_f(MODULE_INS_MEKF_WIND_ID, &utm0);
528#else
529 struct LlaCoor_i llh_nav0;
530 llh_nav0.lat = NAV_LAT0;
531 llh_nav0.lon = NAV_LON0;
532 llh_nav0.alt = NAV_ALT0 + NAV_MSL0;
533 struct EcefCoor_i ecef_nav0;
534 ecef_of_lla_i(&ecef_nav0, &llh_nav0);
535 struct LtpDef_i ltp_def;
536 ltp_def_from_ecef_i(&ltp_def, &ecef_nav0);
537 ltp_def.hmsl = NAV_ALT0;
538 stateSetLocalOrigin_i(MODULE_INS_MEKF_WIND_ID, &ltp_def);
539#endif
540
541 // reset flags
542 ins_mekf_wind.is_aligned = false;
543 ins_mekf_wind.reset = false;
544 ins_mekf_wind.baro_initialized = false;
545 ins_mekf_wind.gps_initialized = false;
546
547 // aligner
548#if USE_AHRS_ALIGNER
550#endif
551
552 // init filter
554 const struct FloatVect3 mag_h = { INS_H_X, INS_H_Y, INS_H_Z };
556
557 // Bind to ABI messages
558 AbiBindMsgBARO_ABS(INS_MEKF_WIND_BARO_ID, &baro_ev, baro_cb);
562 AbiBindMsgIMU_MAG(INS_MEKF_WIND_MAG_ID, &mag_ev, mag_cb);
563 AbiBindMsgIMU_GYRO(INS_MEKF_WIND_IMU_ID, &gyro_ev, gyro_cb);
564 AbiBindMsgIMU_ACCEL(INS_MEKF_WIND_IMU_ID, &accel_ev, accel_cb);
565 AbiBindMsgIMU_LOWPASSED(ABI_BROADCAST, &aligner_ev, aligner_cb);
566 AbiBindMsgGEO_MAG(ABI_BROADCAST, &geo_mag_ev, geo_mag_cb);
567 AbiBindMsgGPS(INS_MEKF_WIND_GPS_ID, &gps_ev, gps_cb);
568 AbiBindMsgINS_RESET(ABI_BROADCAST, &reset_ev, reset_cb);
569
570#if PERIODIC_TELEMETRY
572 register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_WIND_INFO_RET, send_wind);
573 register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_STATE_FILTER_STATUS, send_filter_status);
575#endif
576
577 // init log
578#if LOG_MEKF_WIND && SITL
579 // open log file for writing
580 // path should be specified in airframe file
581 uint32_t counter = 0;
582 char filename[512];
583 snprintf(filename, 512, "%s/mekf_wind_%05d.csv", STRINGIFY(MEKF_WIND_LOG_PATH), counter);
584 // check availale name
585 while ((pprzLogFile = fopen(filename, "r"))) {
586 fclose(pprzLogFile);
587 snprintf(filename, 512, "%s/mekf_wind_%05d.csv", STRINGIFY(MEKF_WIND_LOG_PATH), ++counter);
588 }
589 pprzLogFile = fopen(filename, "w");
590 if (pprzLogFile == NULL) {
591 printf("Failed to open WE log file '%s'\n",filename);
592 } else {
593 printf("Opening WE log file '%s'\n",filename);
594 }
595#endif
596
597}
598
599
600static void reset_ref(void)
601{
602#if FIXEDWING_FIRMWARE
603 struct UtmCoor_f utm = utm_float_from_gps(&gps, 0);
604 // reset state UTM ref
605 stateSetLocalUtmOrigin_f(MODULE_INS_MEKF_WIND_ID, &utm);
606#else
607 struct EcefCoor_i ecef_pos = ecef_int_from_gps(&gps);
608 struct LlaCoor_i lla_pos = lla_int_from_gps(&gps);
609 struct LtpDef_i ltp_def;
610 ltp_def_from_ecef_i(&ltp_def, &ecef_pos);
611 ltp_def.lla.alt = lla_pos.alt;
612 ltp_def.hmsl = gps.hmsl;
613 stateSetLocalOrigin_i(MODULE_INS_MEKF_WIND_ID, &ltp_def);
614#endif
616 //ins_mekf_wind.gps_initialized = false;
617}
618
619static void reset_vertical_ref(void)
620{
621#if FIXEDWING_FIRMWARE
622 struct UtmCoor_f utm = *stateGetUtmOrigin_f();
623 utm.alt = gps.hmsl / 1000.0f;
624 stateSetLocalUtmOrigin_f(MODULE_INS_MEKF_WIND_ID, &utm);
625#else
626 struct LlaCoor_i lla = {
627 .lat = stateGetNedOrigin_i()->lla.lat,
628 .lon = stateGetNedOrigin_i()->lla.lon,
629 .alt = gps.lla_pos.alt
630 };
631 struct LtpDef_i ltp_def;
633 ltp_def.hmsl = gps.hmsl;
634 stateSetLocalOrigin_i(MODULE_INS_MEKF_WIND_ID, &ltp_def);
635#endif
636}
637
638static void reset_cb(uint8_t sender_id UNUSED, uint8_t flag)
639{
640 switch (flag) {
641 case INS_RESET_REF:
642 reset_ref();
643 break;
646 break;
647 default:
648 // unsupported cases
649 break;
650 }
651}
652
static void h(const real32_T x[7], const real32_T q[4], real32_T y[6])
Main include for ABI (AirBorneInterface).
struct abi_struct abi_event
Definition abi_common.h:101
#define ABI_BROADCAST
Broadcast address.
Definition abi_common.h:80
void ahrs_aligner_init(void)
static void gyro_cb(uint8_t sender_id, uint32_t stamp, struct Int32Rates *gyro)
static abi_event gyro_ev
Interface to align the AHRS via low-passed measurements at startup.
static void gps_cb(uint8_t sender_id, uint32_t stamp, struct GpsState *gps_s)
static abi_event mag_ev
static void mag_cb(uint8_t sender_id, uint32_t stamp, struct Int32Vect3 *mag)
static abi_event aligner_ev
static abi_event geo_mag_ev
static void send_filter_status(struct transport_tx *trans, struct link_device *dev)
static void geo_mag_cb(uint8_t sender_id, struct FloatVect3 *h)
static void aligner_cb(uint8_t sender_id, uint32_t stamp, struct Int32Rates *lp_gyro, struct Int32Vect3 *lp_accel, struct Int32Vect3 *lp_mag)
static void send_euler(struct transport_tx *trans, struct link_device *dev)
static abi_event gps_ev
Utility functions for floating point AHRS implementations.
static void ahrs_float_get_quat_from_accel_mag(struct FloatQuat *q, struct FloatVect3 *accel, struct FloatVect3 *mag)
float tas_from_dynamic_pressure(float q)
Calculate true airspeed from dynamic pressure.
Definition air_data.c:981
static void incidence_cb(uint8_t sender_id, uint8_t flag, float aoa, float sideslip)
Definition air_data.c:486
static abi_event incidence_ev
Definition air_data.c:166
float tas_from_eas(float eas)
Calculate true airspeed from equivalent airspeed.
Definition air_data.c:952
Air Data interface.
float baro_alt
Definition baro_bmp280.c:53
#define UNUSED(x)
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
int32_t nav_utm_east0
Definition common_nav.c:48
uint8_t nav_utm_zone0
Definition common_nav.c:50
int32_t nav_utm_north0
Definition common_nav.c:49
if(GpsFixValid() &&e_identification_started)
static struct uart_periph * dev
static abi_event accel_ev
static void accel_cb(uint8_t sender_id, uint32_t stamp, struct Int32Vect3 *accel)
struct UtmCoor_f utm_float_from_gps(struct GpsState *gps_s, uint8_t zone)
Convenience functions to get utm position from GPS state.
Definition gps.c:591
struct NedCoor_f ned_vel_float_from_gps(struct GpsState *gps_s)
Get GPS ned velocity (float) Converted on the fly if not available.
Definition gps.c:558
struct EcefCoor_f ecef_vel_float_from_gps(struct GpsState *gps_s)
Get GPS ecef velocity (float) Converted on the fly if not available.
Definition gps.c:523
struct GpsState gps
global GPS state
Definition gps.c:74
struct LlaCoor_i lla_int_from_gps(struct GpsState *gps_s)
Get GPS lla (integer) Converted on the fly if not available.
Definition gps.c:478
struct EcefCoor_i ecef_int_from_gps(struct GpsState *gps_s)
Get GPS ecef pos (integer) Converted on the fly if not available.
Definition gps.c:507
#define GPS_FIX_3D
3D GPS fix
Definition gps.h:44
uint8_t fix
status of fix
Definition gps.h:110
data structure for GPS information
Definition gps.h:90
float q
in rad/s
float phi
in radians
float p
in rad/s
float r
in rad/s
float theta
in radians
float psi
in radians
void float_eulers_of_quat(struct FloatEulers *e, const struct FloatQuat *q)
euler rotation 'ZYX'
euler angles
Roation quaternion.
angular rates
#define MAGS_FLOAT_OF_BFP(_ef, _ei)
#define RATES_FLOAT_OF_BFP(_rf, _ri)
#define ACCELS_FLOAT_OF_BFP(_ef, _ei)
#define INT32_POS_OF_CM_DEN
#define INT32_POS_OF_CM_NUM
#define INT32_VECT3_SCALE_2(_a, _b, _num, _den)
angular rates
#define ENU_OF_TO_NED(_po, _pi)
int32_t lat
in degrees*1e7
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).
Definition pprz_isa.h:102
#define PPRZ_ISA_SEA_LEVEL_PRESSURE
ISA sea level standard atmospheric pressure in Pascal.
Definition pprz_isa.h:50
static void stateSetAccelNed_f(uint16_t id, struct NedCoor_f *ned_accel)
Set acceleration in NED coordinates (float).
Definition state.h:1166
static void stateSetNedToBodyQuat_f(uint16_t id, struct FloatQuat *ned_to_body_quat)
Set vehicle body attitude from quaternion (float).
Definition state.h:1272
struct State state
Definition state.c:36
static struct LtpDef_f * stateGetNedOrigin_f(void)
Get the coordinate NED frame origin (float).
Definition state.h:577
static void stateSetPositionNed_f(uint16_t id, struct NedCoor_f *ned_pos)
Set position from local NED coordinates (float).
Definition state.h:729
static void stateSetLocalOrigin_i(uint16_t id, struct LtpDef_i *ltp_def)
Set the local (flat earth) coordinate frame origin (int).
Definition state.h:530
static void stateSetPositionUtm_f(uint16_t id, struct UtmCoor_f *utm_pos)
Set position from UTM coordinates (float).
Definition state.h:709
static struct UtmCoor_f * stateGetUtmOrigin_f(void)
Get the coordinate UTM frame origin (int).
Definition state.h:587
static void stateSetLocalUtmOrigin_f(uint16_t id, struct UtmCoor_f *utm_def)
Set the local (flat earth) coordinate frame origin from UTM (float).
Definition state.h:552
float stateGetHmslOrigin_f(void)
Get the HMSL of the frame origin (float).
Definition state.c:210
static struct LtpDef_i * stateGetNedOrigin_i(void)
Get the coordinate NED frame origin (int).
Definition state.h:567
static void stateSetBodyRates_f(uint16_t id, struct FloatRates *body_rate)
Set vehicle body angular rate (float).
Definition state.h:1371
static void stateSetSpeedNed_f(uint16_t id, struct NedCoor_f *ned_speed)
Set ground speed in local NED coordinates (float).
Definition state.h:958
Integrated Navigation System interface.
#define INS_RESET_VERTICAL_REF
Definition ins.h:37
#define INS_RESET_REF
flags for INS reset
Definition ins.h:36
static void reset_cb(uint8_t sender_id, uint8_t flag)
static abi_event reset_ev
abi_event baro_ev
static void baro_cb(uint8_t sender_id, uint32_t stamp, float pressure)
static abi_event airspeed_ev
Definition ins_ekf2.cpp:356
static void airspeed_cb(uint8_t sender_id, float eas)
static void send_inv_filter(struct transport_tx *trans, struct link_device *dev)
uint32_t counter
Definition ins_flow.c:187
float ins_mekf_wind_get_baro_bias(void)
struct NedCoor_f ins_mekf_wind_get_wind_ned(void)
void ins_mekf_wind_update_incidence(float aoa, float aos)
void ins_mekf_wind_set_pos_ned(struct NedCoor_f *p)
float ins_mekf_wind_get_airspeed_norm(void)
void ins_mekf_wind_update_baro(float baro_alt)
struct NedCoor_f ins_mekf_wind_get_accel_ned(void)
void ins_mekf_wind_init(void)
Init function.
void ins_mekf_wind_set_mag_h(const struct FloatVect3 *mag_h)
struct NedCoor_f ins_mekf_wind_get_pos_ned(void)
Getter/Setter functions.
struct FloatRates ins_mekf_wind_get_body_rates(void)
void ins_mekf_wind_set_speed_ned(struct NedCoor_f *s)
void ins_mekf_wind_update_mag(struct FloatVect3 *mag, bool attitude_only)
struct FloatVect3 ins_mekf_wind_get_accel_bias(void)
struct FloatQuat ins_mekf_wind_get_quat(void)
void ins_mekf_wind_propagate(struct FloatRates *gyro, struct FloatVect3 *acc, float dt)
Full INS propagation.
void ins_mekf_wind_align(struct FloatRates *gyro_bias, struct FloatQuat *quat)
void ins_mekf_wind_propagate_ahrs(struct FloatRates *gyro, struct FloatVect3 *acc, float dt)
AHRS-only propagation + accel correction.
struct FloatRates ins_mekf_wind_get_rates_bias(void)
struct NedCoor_f ins_mekf_wind_get_speed_ned(void)
void ins_mekf_wind_update_airspeed(float airspeed)
void ins_mekf_wind_update_pos_speed(struct FloatVect3 *pos, struct FloatVect3 *speed)
Multiplicative Extended Kalman Filter in rotation matrix formulation.
static void airspeed_cb(uint8_t sender_id, float airspeed)
static void reset_vertical_ref(void)
static void send_inv_filter(struct transport_tx *trans, struct link_device *dev)
static void gps_cb(uint8_t sender_id, uint32_t stamp, struct GpsState *gps_s)
#define INS_MEKF_WIND_IMU_ID
IMU (gyro, accel).
static void reset_cb(uint8_t sender_id, uint8_t flag)
static void send_wind(struct transport_tx *trans, struct link_device *dev)
static void reset_ref(void)
static void gyro_cb(uint8_t sender_id, uint32_t stamp, struct Int32Rates *gyro)
Call ins_mekf_wind_propagate on new gyro measurements.
static void mag_cb(uint8_t sender_id, uint32_t stamp, struct Int32Vect3 *mag)
#define INS_MEKF_WIND_INCIDENCE_ID
incidence angles
static abi_event pressure_diff_ev
#define INS_MEKF_WIND_FILTER_ID
#define INS_MEKF_WIND_AIRSPEED_ID
airspeed (Pitot tube)
static uint32_t last_imu_stamp
void ins_mekf_wind_wrapper_init(void)
Init function.
static void set_state_from_ins(void)
update state interface
static void send_filter_status(struct transport_tx *trans, struct link_device *dev)
static void incidence_cb(uint8_t sender_id, uint8_t flag, float aoa, float sideslip)
static struct FloatVect3 ins_mekf_wind_accel
last accel measurement
#define INS_MEKF_WIND_BARO_ID
baro
static void accel_cb(uint8_t sender_id, uint32_t stamp, struct Int32Vect3 *accel)
struct InsMekfWind ins_mekf_wind
static void geo_mag_cb(uint8_t sender_id, struct FloatVect3 *h)
static void aligner_cb(uint8_t sender_id, uint32_t stamp, struct Int32Rates *lp_gyro, struct Int32Vect3 *lp_accel, struct Int32Vect3 *lp_mag)
static void send_euler(struct transport_tx *trans, struct link_device *dev)
logging functions
#define INS_MEKF_WIND_GPS_ID
ABI binding for gps data.
static void pressure_diff_cb(uint8_t sender_id, float pdyn)
#define INS_MEKF_WIND_MAG_ID
magnetometer
Paparazzi specific wrapper to run MEKF-Wind INS filter.
#define ins_mekf_wind_wrapper_Reset(_v)
filter structure
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
static FILE * pprzLogFile
#define LogFileIsOpen(_file)
Fixedwing Navigation library.
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
void ned_of_ecef_vect_f(struct NedCoor_f *ned, struct LtpDef_f *def, struct EcefCoor_f *ecef)
float y
in meters
float x
in meters
float alt
in meters (above WGS84 reference ellipsoid or above MSL)
uint8_t zone
UTM zone number.
float z
in meters
float x
in meters
float east
in meters
float north
in meters
float z
in meters
float y
in meters
vector in EarthCenteredEarthFixed coordinates
vector in East North Up coordinates Units: meters
vector in North East Down coordinates Units: meters
position in UTM coordinates Units: meters
Paparazzi atmospheric pressure conversion utilities.
API to get/set the generic vehicle states.
Architecture independent timing functions.
static float get_sys_time_float(void)
Get the time in seconds since startup.
Definition sys_time.h:241
int16_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint16_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition telemetry.c:51
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
Definition telemetry.h:66
uint16_t val[TCOUPLE_NB]
float alpha
Definition textons.c:133
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.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.