Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
ins_ekf2.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 Freek van Tienen <freek.v.tienen@gmail.com>
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, write to
18 * the Free Software Foundation, 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 */
21
31#include "modules/core/abi.h"
32#include "stabilization/stabilization_attitude.h"
33#include "generated/airframe.h"
34#include "generated/flight_plan.h"
35#include "EKF/ekf.h"
36#include "math/pprz_isa.h"
38#include "mcu_periph/sys_time.h"
39#include "autopilot.h"
40
42#if defined SITL && USE_NPS
43#include "nps_autopilot.h"
44#include <stdio.h>
45#endif
46
48#ifndef USE_INS_NAV_INIT
49#define USE_INS_NAV_INIT TRUE
50#endif
51
53#ifndef INS_EKF2_MAX_REL_LENGTH_ERROR
54#define INS_EKF2_MAX_REL_LENGTH_ERROR 0.2 // Factor which gets multiplied by the reference distance
55#endif
56
58#if INS_EKF2_OPTITRACK
59#ifndef INS_EKF2_FUSION_MODE
60#define INS_EKF2_FUSION_MODE (MASK_USE_EVPOS | MASK_USE_EVVEL | MASK_USE_EVYAW)
61#endif
62#ifndef INS_EKF2_MAG_FUSION_TYPE
63#define INS_EKF2_MAG_FUSION_TYPE MAG_FUSE_TYPE_INDOOR
64#endif
65#ifndef INS_EKF2_VDIST_SENSOR_TYPE
66#define INS_EKF2_VDIST_SENSOR_TYPE VDIST_SENSOR_EV
67#endif
68#endif
69
71#ifndef INS_EKF2_FUSION_MODE
72#define INS_EKF2_FUSION_MODE (MASK_USE_GPS)
73#endif
75
76
77#ifndef INS_EKF2_MAG_FUSION_TYPE
78#define INS_EKF2_MAG_FUSION_TYPE MAG_FUSE_TYPE_AUTO
79#endif
81
82
83#ifndef INS_EKF2_VDIST_SENSOR_TYPE
84#define INS_EKF2_VDIST_SENSOR_TYPE VDIST_SENSOR_BARO
85#endif
87
88
89#ifndef INS_EKF2_GPS_CHECK_MASK
90#define INS_EKF2_GPS_CHECK_MASK 21 // (MASK_GPS_NSATS | MASK_GPS_HACC | MASK_GPS_SACC)
91#endif
93
94
95#ifndef INS_EKF2_SONAR_MIN_RANGE
96#define INS_EKF2_SONAR_MIN_RANGE 0.001
97#endif
99
100
101#ifndef INS_EKF2_SONAR_MAX_RANGE
102#define INS_EKF2_SONAR_MAX_RANGE 4
103#endif
105
106
107#ifndef INS_EKF2_RANGE_MAIN_AGL
108#define INS_EKF2_RANGE_MAIN_AGL 1
109#endif
111
112
113#ifndef INS_EKF2_BARO_ID
114#if USE_BARO_BOARD
115#define INS_EKF2_BARO_ID BARO_BOARD_SENDER_ID
116#else
117#define INS_EKF2_BARO_ID ABI_BROADCAST
118#endif
119#endif
121
122
123#ifndef INS_EKF2_TEMPERATURE_ID
124#define INS_EKF2_TEMPERATURE_ID ABI_BROADCAST
125#endif
127
128
129#ifndef INS_EKF2_AGL_ID
130#define INS_EKF2_AGL_ID ABI_BROADCAST
131#endif
133
134/* default Gyro to use in INS */
135#ifndef INS_EKF2_GYRO_ID
136#define INS_EKF2_GYRO_ID ABI_BROADCAST
137#endif
139
140/* default Accelerometer to use in INS */
141#ifndef INS_EKF2_ACCEL_ID
142#define INS_EKF2_ACCEL_ID ABI_BROADCAST
143#endif
145
146/* default Magnetometer to use in INS */
147#ifndef INS_EKF2_MAG_ID
148#define INS_EKF2_MAG_ID ABI_BROADCAST
149#endif
151
152/* default GPS to use in INS */
153#ifndef INS_EKF2_GPS_ID
154#define INS_EKF2_GPS_ID GPS_MULTI_ID
155#endif
157
158/* default RELPOS to use for heading in INS */
159#ifndef INS_EKF2_RELPOS_ID
160#define INS_EKF2_RELPOS_ID ABI_BROADCAST
161#endif
163
164/* default Optical Flow to use in INS */
165#ifndef INS_EKF2_OF_ID
166#define INS_EKF2_OF_ID ABI_BROADCAST
167#endif
169
170/* IMU X offset from CoG position in meters */
171#ifndef INS_EKF2_IMU_POS_X
172#define INS_EKF2_IMU_POS_X 0
173#endif
175
176/* IMU Y offset from CoG position in meters */
177#ifndef INS_EKF2_IMU_POS_Y
178#define INS_EKF2_IMU_POS_Y 0
179#endif
181
182/* IMU Z offset from CoG position in meters */
183#ifndef INS_EKF2_IMU_POS_Z
184#define INS_EKF2_IMU_POS_Z 0
185#endif
187
188/* GPS X offset from CoG position in meters */
189#ifndef INS_EKF2_GPS_POS_X
190#define INS_EKF2_GPS_POS_X 0
191#endif
193
194/* GPS Y offset from CoG position in meters */
195#ifndef INS_EKF2_GPS_POS_Y
196#define INS_EKF2_GPS_POS_Y 0
197#endif
199
200/* GPS Z offset from CoG position in meters */
201#ifndef INS_EKF2_GPS_POS_Z
202#define INS_EKF2_GPS_POS_Z 0
203#endif
205
206/* Default flow/radar message delay (in ms) */
207#ifndef INS_EKF2_FLOW_SENSOR_DELAY
208#define INS_EKF2_FLOW_SENSOR_DELAY 15
209#endif
211
212/* Default minimum accepted quality (1 to 255) */
213#ifndef INS_EKF2_MIN_FLOW_QUALITY
214#define INS_EKF2_MIN_FLOW_QUALITY 100
215#endif
217
218/* Max flow rate that the sensor can measure (rad/sec) */
219#ifndef INS_EKF2_MAX_FLOW_RATE
220#define INS_EKF2_MAX_FLOW_RATE 200
221#endif
223
224/* Flow sensor X offset from CoG position in meters */
225#ifndef INS_EKF2_FLOW_POS_X
226#define INS_EKF2_FLOW_POS_X 0
227#endif
229
230/* Flow sensor Y offset from CoG position in meters */
231#ifndef INS_EKF2_FLOW_POS_Y
232#define INS_EKF2_FLOW_POS_Y 0
233#endif
235
236/* Flow sensor Z offset from CoG position in meters */
237#ifndef INS_EKF2_FLOW_POS_Z
238#define INS_EKF2_FLOW_POS_Z 0
239#endif
241
242/* Flow sensor noise in rad/sec */
243#ifndef INS_EKF2_FLOW_NOISE
244#define INS_EKF2_FLOW_NOISE 0.03
245#endif
247
248/* Flow sensor noise at qmin in rad/sec */
249#ifndef INS_EKF2_FLOW_NOISE_QMIN
250#define INS_EKF2_FLOW_NOISE_QMIN 0.05
251#endif
253
254/* Flow sensor innovation gate */
255#ifndef INS_EKF2_FLOW_INNOV_GATE
256#define INS_EKF2_FLOW_INNOV_GATE 4
257#endif
259
260/* External vision position noise (m) */
261#ifndef INS_EKF2_EVP_NOISE
262#define INS_EKF2_EVP_NOISE 0.02f
263#endif
265
266/* External vision velocity noise (m/s) */
267#ifndef INS_EKF2_EVV_NOISE
268#define INS_EKF2_EVV_NOISE 0.1f
269#endif
271
272/* External vision angle noise (rad) */
273#ifndef INS_EKF2_EVA_NOISE
274#define INS_EKF2_EVA_NOISE 0.05f
275#endif
277
278/* GPS measurement noise for horizontal velocity (m/s) */
279#ifndef INS_EKF2_GPS_V_NOISE
280#define INS_EKF2_GPS_V_NOISE 0.3f
281#endif
283
284/* GPS measurement position noise (m) */
285#ifndef INS_EKF2_GPS_P_NOISE
286#define INS_EKF2_GPS_P_NOISE 0.5f
287#endif
289
290/* Barometric measurement noise for altitude (m) */
291#ifndef INS_EKF2_BARO_NOISE
292#define INS_EKF2_BARO_NOISE 3.5f
293#endif
295
296/* Maximum allowed distance error for the RTK relative heading measurement (m) */
297#ifndef INS_EKF2_RELHEADING_ERR
298#define INS_EKF2_RELHEADING_ERR 0.2
299#endif
300
301#ifdef INS_EXT_VISION_ROTATION
303#endif
304
305/* All registered ABI events */
316
317/* All ABI callbacks */
318static void baro_cb(uint8_t sender_id, uint32_t stamp, float pressure);
319static void temperature_cb(uint8_t sender_id, float temp);
320static void agl_cb(uint8_t sender_id, uint32_t stamp, float distance);
321static void gyro_int_cb(uint8_t sender_id, uint32_t stamp, struct FloatRates *delta_gyro, uint16_t dt);
322static void accel_int_cb(uint8_t sender_id, uint32_t stamp, struct FloatVect3 *delta_accel, uint16_t dt);
323static void mag_cb(uint8_t sender_id, uint32_t stamp, struct Int32Vect3 *mag);
324static void gps_cb(uint8_t sender_id, uint32_t stamp, struct GpsState *gps_s);
326static void optical_flow_cb(uint8_t sender_id, uint32_t stamp, int32_t flow_x, int32_t flow_y, int32_t flow_der_x, int32_t flow_der_y, float quality, float size_divergence);
328
329/* Static local functions */
331
332/* Static local variables */
333static Ekf ekf;
335struct ekf2_t ekf2;
337#if PERIODIC_TELEMETRY
339
340static void send_ins(struct transport_tx *trans, struct link_device *dev)
341{
342 struct NedCoor_i pos, speed, accel;
343
344 // Get it from the EKF
345 const Vector3f pos_f{ekf.getPosition()};
346 const Vector3f speed_f{ekf.getVelocity()};
347 const Vector3f accel_f{ekf.getVelocityDerivative()};
348
349 // Convert to integer
350 pos.x = POS_BFP_OF_REAL(pos_f(0));
351 pos.y = POS_BFP_OF_REAL(pos_f(1));
352 pos.z = POS_BFP_OF_REAL(pos_f(2));
353 speed.x = SPEED_BFP_OF_REAL(speed_f(0));
354 speed.y = SPEED_BFP_OF_REAL(speed_f(1));
355 speed.z = SPEED_BFP_OF_REAL(speed_f(2));
356 accel.x = ACCEL_BFP_OF_REAL(accel_f(0));
357 accel.y = ACCEL_BFP_OF_REAL(accel_f(1));
358 accel.z = ACCEL_BFP_OF_REAL(accel_f(2));
359
360 // Send the message
362 &pos.x, &pos.y, &pos.z,
363 &speed.x, &speed.y, &speed.z,
364 &accel.x, &accel.y, &accel.z);
365}
366
367static void send_ins_z(struct transport_tx *trans, struct link_device *dev)
368{
369 float baro_z = 0.0f;
370 int32_t pos_z, speed_z, accel_z;
371
372 // Get it from the EKF
373 const Vector3f pos_f{ekf.getPosition()};
374 const Vector3f speed_f{ekf.getVelocity()};
375 const Vector3f accel_f{ekf.getVelocityDerivative()};
376
377 // Convert to integer
380 accel_z = ACCEL_BFP_OF_REAL(accel_f(2));
381
382 // Send the message
384 &baro_z, &pos_z, &speed_z, &accel_z);
385}
386
387static void send_ins_ref(struct transport_tx *trans, struct link_device *dev)
388{
389 float qfe = 101325.0; //TODO: this is qnh not qfe?
390 if (ekf2.ltp_stamp > 0)
394 &ekf2.ltp_def.hmsl, &qfe);
395}
396
397static void send_ins_ekf2(struct transport_tx *trans, struct link_device *dev)
398{
400 uint16_t filter_fault_status = ekf.fault_status().value; // FIXME: 32bit instead of 16bit
401 uint32_t control_mode = ekf.control_status().value;
402 ekf.get_gps_check_status(&gps_check_status);
403 ekf.get_ekf_soln_status(&soln_status);
404
406 float mag, vel, pos, hgt, tas, hagl, flow, beta, mag_decl = 0.0f;
408 ekf.get_innovation_test_status(innov_test_status, mag, vel, pos, hgt, tas, hagl, beta);
409 //ekf.get_flow_innov(&flow);
410 ekf.get_mag_decl_deg(&mag_decl);
411
412 if (ekf.isTerrainEstimateValid()) {
413 terrain_valid = 1;
414 } else {
415 terrain_valid = 0;
416 }
417
418 if (ekf.inertial_dead_reckoning()) {
419 dead_reckoning = 1;
420 } else {
421 dead_reckoning = 0;
422 }
423
426 &innov_test_status, &mag, &vel, &pos, &hgt, &tas, &hagl, &flow, &beta,
428}
429
430static void send_ins_ekf2_ext(struct transport_tx *trans, struct link_device *dev)
431{
432 float gps_drift[3];
433 Vector3f vibe = ekf.getImuVibrationMetrics();
434 bool gps_blocked;
436 ekf.get_gps_drift_metrics(gps_drift, &gps_blocked);
438
441 &vibe(0), &vibe(1), &vibe(2));
442}
443
444static void send_filter_status(struct transport_tx *trans, struct link_device *dev)
445{
447 filter_control_status_u control_mode = ekf.control_status();
448 uint32_t filter_fault_status = ekf.fault_status().value;
450 uint8_t mde = 0;
451
452 // Check the alignment and if GPS is fused
453 if (control_mode.flags.tilt_align && control_mode.flags.yaw_align && (control_mode.flags.gps || control_mode.flags.ev_pos)) {
454 mde = 3;
455 } else if (control_mode.flags.tilt_align && control_mode.flags.yaw_align) {
456 mde = 4;
457 } else {
458 mde = 2;
459 }
460
461 // Check if there is a covariance error
463 mde = 6;
464 }
465
467}
468
469static void send_wind_info_ret(struct transport_tx *trans, struct link_device *dev)
470{
471 float tas;
472 Vector2f wind = ekf.getWindVelocity();
473 uint8_t flags = 0x5;
474 float f_zero = 0;
475
476 ekf.get_true_airspeed(&tas);
477
478 pprz_msg_send_WIND_INFO_RET(trans, dev, AC_ID, &flags, &wind(1), &wind(0), &f_zero, &tas);
479}
480
481static void send_ahrs_bias(struct transport_tx *trans, struct link_device *dev)
482{
483 Vector3f accel_bias = ekf.getAccelBias();
484 Vector3f gyro_bias = ekf.getGyroBias();
485 Vector3f mag_bias = ekf.getMagBias();
486
487 pprz_msg_send_AHRS_BIAS(trans, dev, AC_ID, &accel_bias(0), &accel_bias(1), &accel_bias(2),
488 &gyro_bias(0), &gyro_bias(1), &gyro_bias(2), &mag_bias(0), &mag_bias(1), &mag_bias(2));
489}
490
491static void send_ahrs_quat(struct transport_tx *trans, struct link_device *dev)
492{
493 struct Int32Quat ltp_to_body_quat;
494 const Quatf att_q{ekf.calculate_quaternion()};
495 ltp_to_body_quat.qi = QUAT1_BFP_OF_REAL(att_q(0));
496 ltp_to_body_quat.qx = QUAT1_BFP_OF_REAL(att_q(1));
497 ltp_to_body_quat.qy = QUAT1_BFP_OF_REAL(att_q(2));
498 ltp_to_body_quat.qz = QUAT1_BFP_OF_REAL(att_q(3));
499 struct Int32Quat *quat = stateGetNedToBodyQuat_i();
500 float foo = 0.f;
501 uint8_t ahrs_id = 1; // generic
503 &foo,
504 &ltp_to_body_quat.qi,
505 &ltp_to_body_quat.qx,
506 &ltp_to_body_quat.qy,
507 &ltp_to_body_quat.qz,
508 &(quat->qi),
509 &(quat->qx),
510 &(quat->qy),
511 &(quat->qz),
512 &ahrs_id);
513}
514
515
516static void send_external_pose_down(struct transport_tx *trans, struct link_device *dev)
517{
518 if(sample_ev.time_us == 0){
519 return;
520 }
521 float sample_temp_ev[11];
522 sample_temp_ev[0] = (float) sample_ev.time_us;
523 sample_temp_ev[1] = sample_ev.pos(0) ;
524 sample_temp_ev[2] = sample_ev.pos(1) ;
525 sample_temp_ev[3] = sample_ev.pos(2) ;
526 sample_temp_ev[4] = sample_ev.vel(0) ;
527 sample_temp_ev[5] = sample_ev.vel(1) ;
528 sample_temp_ev[6] = sample_ev.vel(2) ;
529 sample_temp_ev[7] = sample_ev.quat(0);
530 sample_temp_ev[8] = sample_ev.quat(1);
531 sample_temp_ev[9] = sample_ev.quat(2);
532 sample_temp_ev[10] = sample_ev.quat(3);
534 &sample_temp_ev[0],
535 &sample_temp_ev[1],
536 &sample_temp_ev[2],
537 &sample_temp_ev[3],
538 &sample_temp_ev[4],
539 &sample_temp_ev[5],
540 &sample_temp_ev[6],
541 &sample_temp_ev[7],
542 &sample_temp_ev[8],
543 &sample_temp_ev[9],
544 &sample_temp_ev[10] );
545}
546#endif
547
548/* Initialize the EKF */
550{
551 /* Get the ekf parameters */
552 ekf_params = ekf.getParamHandle();
553 ekf_params->fusion_mode = INS_EKF2_FUSION_MODE;
554 ekf_params->mag_fusion_type = INS_EKF2_MAG_FUSION_TYPE;
555 ekf_params->vdist_sensor_type = INS_EKF2_VDIST_SENSOR_TYPE;
556 ekf_params->gps_check_mask = INS_EKF2_GPS_CHECK_MASK;
557
558 /* Set specific noise levels */
559 ekf_params->accel_bias_p_noise = 3.0e-3f;
560 ekf_params->gps_vel_noise = INS_EKF2_GPS_V_NOISE;
561 ekf_params->gps_pos_noise = INS_EKF2_GPS_P_NOISE;
562 ekf_params->baro_noise = INS_EKF2_BARO_NOISE;
563
564 /* Set optical flow parameters */
565 ekf_params->flow_qual_min = INS_EKF2_MIN_FLOW_QUALITY;
566 ekf_params->flow_delay_ms = INS_EKF2_FLOW_SENSOR_DELAY;
567 ekf_params->range_delay_ms = INS_EKF2_FLOW_SENSOR_DELAY;
568 ekf_params->flow_noise = INS_EKF2_FLOW_NOISE;
569 ekf_params->flow_noise_qual_min = INS_EKF2_FLOW_NOISE_QMIN;
570 ekf_params->flow_innov_gate = INS_EKF2_FLOW_INNOV_GATE;
571
572 /* Set the IMU position relative from the CoG in xyz (m) */
573 ekf_params->imu_pos_body = {
577 };
578
579 /* Set the GPS position relative from the CoG in xyz (m) */
580 ekf_params->gps_pos_body = {
584 };
585
586 /* Set flow sensor offset from CoG position in xyz (m) */
587 ekf_params->flow_pos_body = {
591 };
592
593 /* Set range as default AGL measurement if possible */
595
596 /* Initialize struct */
597 ekf2.ltp_stamp = 0;
598 ekf2.flow_stamp = 0;
599 ekf2.gyro_valid = false;
600 ekf2.accel_valid = false;
601 ekf2.got_imu_data = false;
603 ekf2.temp = 20.0f; // Default temperature of 20 degrees celcius
604 ekf2.qnh = 1013.25f; // Default atmosphere
605
606 /* Initialize the range sensor limits */
608
609 /* Initialize the flow sensor limits */
611
612 // Don't send external vision data by default
613 sample_ev.time_us = 0;
614
615 /* Initialize the origin from flight plan */
616#if USE_INS_NAV_INIT
617 if(ekf.setEkfGlobalOrigin(NAV_LAT0*1e-7, NAV_LON0*1e-7, (NAV_ALT0)*1e-3)) // EKF2 works HMSL
618 {
619 struct LlaCoor_i llh_nav0; /* Height above the ellipsoid */
621 llh_nav0.lon = NAV_LON0;
622 /* NAV_ALT0 = ground alt above msl, NAV_MSL0 = geoid-height (msl) over ellipsoid */
623 llh_nav0.alt = NAV_ALT0 + NAV_MSL0; // in millimeters above WGS84 reference ellipsoid
624
628
629 /* update local ENU coordinates of global waypoints */
631
632 ekf2.ltp_stamp = 1;
633 }
634#endif
635
636#if PERIODIC_TELEMETRY
647#endif
648
649 /*
650 * Subscribe to scaled IMU measurements and attach callbacks
651 */
662}
663
664static void reset_ref(void)
665{
666#if USE_GPS
667 if (GpsFixValid()) {
668 struct LlaCoor_i lla_pos = lla_int_from_gps(&gps);
669 if (ekf.setEkfGlobalOrigin(lla_pos.lat*1e-7, lla_pos.lon*1e-7, gps.hmsl*1e-3)) {
670 ltp_def_from_lla_i(&ekf2.ltp_def, &lla_pos);
673 }
674 }
675#endif
676}
677
678static void reset_vertical_ref(void)
679{
680#if USE_GPS
681 if (GpsFixValid()) {
682 struct LlaCoor_i lla_pos = lla_int_from_gps(&gps);
683 struct LlaCoor_i lla = {
685 .lon = stateGetLlaOrigin_i().lon,
686 .alt = lla_pos.alt
687 };
688 if (ekf.setEkfGlobalOrigin(lla.lat*1e-7, lla.lon*1e-7, gps.hmsl*1e-3)) {
692 }
693 }
694#endif
695}
696
698{
699 switch (flag) {
700 case INS_RESET_REF:
701 reset_ref();
702 break;
705 break;
706 default:
707 // unsupported cases
708 break;
709 }
710}
711/* Update the INS state */
713{
714 /* Set EKF settings */
715 ekf.set_in_air_status(autopilot_in_flight());
716
717 /* Update the EKF */
718 if (ekf2.got_imu_data) {
719 // Update the EKF but ignore the response and also copy the faster intermediate filter
720 ekf.update();
721 filter_control_status_u control_status = ekf.control_status();
722
723 // Only publish position after successful alignment
724 if (control_status.flags.tilt_align) {
725 /* Get the position */
726 const Vector3f pos_f{ekf.getPosition()};
727 struct NedCoor_f pos;
728 pos.x = pos_f(0);
729 pos.y = pos_f(1);
730 pos.z = pos_f(2);
731
732 // Publish to the state
734
735 /* Get the velocity in NED frame */
736 const Vector3f vel_f{ekf.getVelocity()};
737 struct NedCoor_f speed;
738 speed.x = vel_f(0);
739 speed.y = vel_f(1);
740 speed.z = vel_f(2);
741
742 // Publish to state
744
745 /* Get the accelerations in NED frame */
746 const Vector3f vel_deriv_f{ekf.getVelocityDerivative()};
747 struct NedCoor_f accel;
748 accel.x = vel_deriv_f(0);
749 accel.y = vel_deriv_f(1);
750 accel.z = vel_deriv_f(2);
751
752 // Publish to state
754
755 /* Get local origin */
756 // Position of local NED origin in GPS / WGS84 frame
758 float ref_alt;
759 struct LlaCoor_i lla_ref;
761
762 // Only update the origin when the state estimator has updated the origin
765 lla_ref.lat = ekf_origin_lat * 1e7; // WGS-84 lat
766 lla_ref.lon = ekf_origin_lon * 1e7; // WGS-84 lon
767 lla_ref.alt = ref_alt * 1e3 + wgs84_ellipsoid_to_geoid_i(lla_ref.lat, lla_ref.lon); // in millimeters above WGS84 reference ellipsoid (ref_alt is in HMSL)
771
772 /* update local ENU coordinates of global waypoints */
774
776 }
777 }
778 }
779
780#if defined SITL && USE_NPS
781 if (nps_bypass_ins) {
783 }
784#endif
785
786 ekf2.got_imu_data = false;
787}
788
790{
791 if (mode) {
793 } else {
795 }
796}
797
799 if (DL_EXTERNAL_POSE_ac_id(buf) != AC_ID) { return; } // not for this aircraft
800
801 sample_ev.time_us = get_sys_time_usec(); //FIXME
802 sample_ev.pos(0) = DL_EXTERNAL_POSE_enu_y(buf);
803 sample_ev.pos(1) = DL_EXTERNAL_POSE_enu_x(buf);
804 sample_ev.pos(2) = -DL_EXTERNAL_POSE_enu_z(buf);
806 sample_ev.vel(1) = DL_EXTERNAL_POSE_enu_xd(buf);
807 sample_ev.vel(2) = -DL_EXTERNAL_POSE_enu_zd(buf);
808 sample_ev.quat(0) = DL_EXTERNAL_POSE_body_qi(buf);
809 sample_ev.quat(1) = DL_EXTERNAL_POSE_body_qy(buf);
810 sample_ev.quat(2) = DL_EXTERNAL_POSE_body_qx(buf);
811 sample_ev.quat(3) = -DL_EXTERNAL_POSE_body_qz(buf);
812
813#ifdef INS_EXT_VISION_ROTATION
814 // Rotate the quaternion
815 struct FloatQuat body_q = {sample_ev.quat(0), sample_ev.quat(1), sample_ev.quat(2), sample_ev.quat(3)};
816 struct FloatQuat rot_q;
818 sample_ev.quat(0) = rot_q.qi;
819 sample_ev.quat(1) = rot_q.qx;
820 sample_ev.quat(2) = rot_q.qy;
821 sample_ev.quat(3) = rot_q.qz;
822#endif
823
824 sample_ev.posVar.setAll(INS_EKF2_EVP_NOISE);
825 sample_ev.velCov = matrix::eye<float, 3>() * INS_EKF2_EVV_NOISE;
827 sample_ev.vel_frame = velocity_frame_t::LOCAL_FRAME_FRD;
828
829 ekf.setExtVisionData(sample_ev);
830}
831
835
840{
842 imu_sample.time_us = stamp;
843 imu_sample.delta_ang_dt = ekf2.gyro_dt * 1.e-6f;
845 imu_sample.delta_vel_dt = ekf2.accel_dt * 1.e-6f;
847 ekf.setIMUData(imu_sample);
848
849 if (ekf.attitude_valid()) {
850 // Calculate the quaternion
851 struct FloatQuat ltp_to_body_quat;
852 const Quatf att_q{ekf.calculate_quaternion()};
853 ltp_to_body_quat.qi = att_q(0);
854 ltp_to_body_quat.qx = att_q(1);
855 ltp_to_body_quat.qy = att_q(2);
856 ltp_to_body_quat.qz = att_q(3);
857
858 // Publish it to the state
860
861 /* Check the quaternion reset state */
862 float delta_q_reset[4];
863 uint8_t quat_reset_counter;
864 ekf.get_quat_reset(delta_q_reset, &quat_reset_counter);
865
866#ifndef NO_RESET_UPDATE_SETPOINT_HEADING
867 // FIXME is this hard reset of control setpoint really needed ? is it the right place ?
868 if (ekf2.quat_reset_counter < quat_reset_counter) {
869 float psi = matrix::Eulerf(matrix::Quatf(delta_q_reset)).psi();
870 guidance_h.sp.heading += psi;
871 guidance_h.rc_sp.heading += psi;
872 nav.heading += psi;
873 //guidance_h_read_rc(autopilot_in_flight());
875 ekf2.quat_reset_counter = quat_reset_counter;
876 }
877#endif
878
879 /* Get in-run gyro bias */
880 struct FloatRates body_rates;
881 Vector3f gyro_bias{ekf.getGyroBias()};
882 body_rates.p = (ekf2.delta_gyro.p / (ekf2.gyro_dt * 1.e-6f)) - gyro_bias(0);
883 body_rates.q = (ekf2.delta_gyro.q / (ekf2.gyro_dt * 1.e-6f)) - gyro_bias(1);
884 body_rates.r = (ekf2.delta_gyro.r / (ekf2.gyro_dt * 1.e-6f)) - gyro_bias(2);
885
886 // Publish it to the state
888
889 /* Get the in-run acceleration bias */
890 struct Int32Vect3 accel;
891 Vector3f accel_bias{ekf.getAccelBias()};
892 accel.x = ACCEL_BFP_OF_REAL((ekf2.delta_accel.x / (ekf2.accel_dt * 1e-6f)) - accel_bias(0));
893 accel.y = ACCEL_BFP_OF_REAL((ekf2.delta_accel.y / (ekf2.accel_dt * 1e-6f)) - accel_bias(1));
894 accel.z = ACCEL_BFP_OF_REAL((ekf2.delta_accel.z / (ekf2.accel_dt * 1e-6f)) - accel_bias(2));
895
896 // Publish it to the state
898 }
899
900 ekf2.gyro_valid = false;
901 ekf2.accel_valid = false;
902 ekf2.got_imu_data = true;
903}
904
905/* Update INS based on Baro information */
906static void baro_cb(uint8_t __attribute__((unused)) sender_id, uint32_t stamp, float pressure)
907{
909 sample.time_us = stamp;
910
911 // Calculate the air density
912 float rho = pprz_isa_density_of_pressure(pressure, ekf2.temp);
913 ekf.set_air_density(rho);
914
915 // Calculate the height above mean sea level based on pressure
916 sample.hgt = pprz_isa_height_of_pressure_full(pressure, ekf2.qnh * 100.0f);
917 ekf.setBaroData(sample);
918}
919
920/* Save the latest temperature measurement for air density calculations */
921static void temperature_cb(uint8_t __attribute__((unused)) sender_id, float temp)
922{
923 ekf2.temp = temp;
924}
925
926/* Update INS based on AGL information */
927static void agl_cb(uint8_t __attribute__((unused)) sender_id, uint32_t stamp, float distance)
928{
930 sample.time_us = stamp;
931 sample.rng = distance;
932 sample.quality = -1;
933
934 ekf.setRangeData(sample);
935}
936
937/* Update INS based on Gyro information */
939 uint32_t stamp, struct FloatRates *delta_gyro, uint16_t dt)
940{
941 // Copy and save the gyro data
942 RATES_COPY(ekf2.delta_gyro, *delta_gyro);
943 ekf2.gyro_dt = dt;
944 ekf2.gyro_valid = true;
945
946 /* When Gyro and accelerometer are valid enter it into the EKF */
949 }
950}
951
952/* Update INS based on Accelerometer information */
954 uint32_t stamp, struct FloatVect3 *delta_accel, uint16_t dt)
955{
956 // Copy and save the gyro data
957 VECT3_COPY(ekf2.delta_accel, *delta_accel);
958 ekf2.accel_dt = dt;
959 ekf2.accel_valid = true;
960
961 /* When Gyro and accelerometer are valid enter it into the EKF */
964 }
965}
966
967/* Update INS based on Magnetometer information */
968static void mag_cb(uint8_t __attribute__((unused)) sender_id,
970 struct Int32Vect3 *mag)
971{
972 struct FloatVect3 mag_gauss;
974 sample.time_us = stamp;
975
976 // Convert Magnetometer information to float and to radius 0.2f
978 mag_gauss.x *= 0.4f;
979 mag_gauss.y *= 0.4f;
980 mag_gauss.z *= 0.4f;
981
982 // Publish information to the EKF
983 sample.mag(0) = mag_gauss.x;
984 sample.mag(1) = mag_gauss.y;
985 sample.mag(2) = mag_gauss.z;
986
987 ekf.setMagData(sample);
988 ekf2.got_imu_data = true;
989}
990
991/* Update INS based on GPS information */
992static void gps_cb(uint8_t sender_id __attribute__((unused)),
994 struct GpsState *gps_s)
995{
996 gps_message gps_msg = {};
997 gps_msg.time_usec = stamp;
998 struct LlaCoor_i lla_pos = lla_int_from_gps(gps_s);
999 gps_msg.lat = lla_pos.lat;
1000 gps_msg.lon = lla_pos.lon;
1001 gps_msg.alt = gps_s->hmsl; // EKF2 works with HMSL
1002#if INS_EKF2_GPS_COURSE_YAW
1003 gps_msg.yaw = wrap_pi((float)gps_s->course / 1e7);
1004 gps_msg.yaw_offset = 0;
1005#elif defined(INS_EKF2_GPS_YAW_OFFSET)
1008 ekf2.rel_heading_valid = false;
1009 } else {
1010 gps_msg.yaw = NAN;
1011 }
1012
1013 // Offset also needs to be substracted from the heading (this is for roll/pitch angle limits)
1015#else
1016 gps_msg.yaw = NAN;
1017 gps_msg.yaw_offset = NAN;
1018#endif
1019 gps_msg.fix_type = gps_s->fix;
1020 gps_msg.eph = gps_s->hacc / 100.0;
1021 gps_msg.epv = gps_s->vacc / 100.0;
1022 gps_msg.sacc = gps_s->sacc / 100.0;
1023 gps_msg.vel_m_s = gps_s->gspeed / 100.0;
1024 struct NedCoor_f ned_vel = ned_vel_float_from_gps(gps_s);
1025 gps_msg.vel_ned(0) = ned_vel.x;
1026 gps_msg.vel_ned(1) = ned_vel.y;
1027 gps_msg.vel_ned(2) = ned_vel.z;
1028 gps_msg.vel_ned_valid = bit_is_set(gps_s->valid_fields, GPS_VALID_VEL_NED_BIT);
1029 gps_msg.nsats = gps_s->num_sv;
1030 gps_msg.pdop = gps_s->pdop;
1031
1032 ekf.setGpsData(gps_msg);
1033}
1034
1035/* Update the local relative position information */
1037{
1038 // Verify if we received a valid heading
1039 if(
1041 relpos->reference_id != INS_EKF2_RELHEADING_REF_ID ||
1042#endif
1045#endif
1046 !ISFINITE(relpos->heading)
1047 ) {
1048 return;
1049 }
1050
1051 ekf2.rel_heading = relpos->heading;
1052 ekf2.rel_heading_valid = true;
1053}
1054
1055/* Update INS based on Optical Flow information */
1058 int32_t flow_x,
1059 int32_t flow_y,
1060 int32_t flow_der_x __attribute__((unused)),
1061 int32_t flow_der_y __attribute__((unused)),
1062 float quality,
1063 float size_divergence __attribute__((unused)))
1064{
1066 sample.time_us = stamp;
1067
1068 // Wait for two measurements in order to integrate
1069 if (ekf2.flow_stamp <= 0) {
1071 return;
1072 }
1073
1074 // Calculate the timestamp
1075 sample.dt = (stamp - ekf2.flow_stamp);
1077
1078 /* Build integrated flow and gyro messages for filter
1079 NOTE: pure rotations should result in same flow_x and
1080 gyro_roll and same flow_y and gyro_pitch */
1082 flowdata(0) = RadOfDeg(flow_y) * (1e-6 *
1083 sample.dt); // INTEGRATED FLOW AROUND Y AXIS (RIGHT -X, LEFT +X)
1084 flowdata(1) = - RadOfDeg(flow_x) * (1e-6 *
1085 sample.dt); // INTEGRATED FLOW AROUND X AXIS (FORWARD +Y, BACKWARD -Y)
1086
1087 sample.quality = quality; // quality indicator between 0 and 255
1088 sample.flow_xy_rad =
1089 flowdata; // measured delta angle of the image about the X and Y body axes (rad), RH rotaton is positive
1090 sample.gyro_xyz = Vector3f{NAN, NAN, NAN}; // measured delta angle of the inertial frame about the body axes obtained from rate gyro measurements (rad), RH rotation is positive
1091
1092 // Update the optical flow data based on the callback
1093 ekf.setOpticalFlowData(sample);
1094}
Main include for ABI (AirBorneInterface).
#define ABI_BROADCAST
Broadcast address.
Definition abi_common.h:59
Event structure to store callbacks in a linked list.
Definition abi_common.h:68
#define AHRS_COMP_ID_EKF2
Definition ahrs.h:47
bool autopilot_in_flight(void)
get in_flight flag
Definition autopilot.c:340
Core autopilot interface common to all firmwares.
#define UNUSED(x)
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
static const float pos_z[]
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:570
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:490
int32_t hmsl
height above mean sea level (MSL) in mm
Definition gps.h:97
#define GPS_VALID_VEL_NED_BIT
Definition gps.h:52
#define GpsFixValid()
Definition gps.h:171
data structure for GPS information
Definition gps.h:90
float q
in rad/s
float p
in rad/s
float r
in rad/s
void float_quat_comp(struct FloatQuat *a2c, struct FloatQuat *a2b, struct FloatQuat *b2c)
Composition (multiplication) of two quaternions.
Roation quaternion.
angular rates
#define MAGS_FLOAT_OF_BFP(_ef, _ei)
#define RATES_COPY(_a, _b)
#define VECT3_COPY(_a, _b)
#define QUAT1_BFP_OF_REAL(_qf)
#define ACCEL_BFP_OF_REAL(_af)
#define POS_BFP_OF_REAL(_af)
#define SPEED_BFP_OF_REAL(_af)
Rotation quaternion.
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
int32_t z
Down.
int32_t z
in centimeters
struct LlaCoor_i lla
Reference point in lla.
int32_t x
in centimeters
int32_t y
East.
struct EcefCoor_i ecef
Reference point in ecef.
int32_t y
in centimeters
int32_t lon
in degrees*1e7
int32_t x
North.
void ltp_def_from_lla_i(struct LtpDef_i *def, struct LlaCoor_i *lla)
vector in Latitude, Longitude and Altitude
vector in North East Down coordinates
static int32_t wgs84_ellipsoid_to_geoid_i(int32_t lat, int32_t lon)
Get WGS84 ellipsoid/geoid separation.
static float pprz_isa_density_of_pressure(float pressure, float temp)
Get the air density (rho) from a given pressure and temperature.
Definition pprz_isa.h:193
static float pprz_isa_height_of_pressure_full(float pressure, float ref_p)
Get relative altitude from pressure (using full equation).
Definition pprz_isa.h:146
static void stateSetAccelNed_f(uint16_t id, struct NedCoor_f *ned_accel)
Set acceleration in NED coordinates (float).
Definition state.h:1147
static void stateSetAccelBody_i(uint16_t id, struct Int32Vect3 *body_accel)
Set acceleration in Body coordinates (int).
Definition state.h:1167
static struct Int32Quat * stateGetNedToBodyQuat_i(void)
Get vehicle body attitude quaternion (int).
Definition state.h:1276
static void stateSetNedToBodyQuat_f(uint16_t id, struct FloatQuat *ned_to_body_quat)
Set vehicle body attitude from quaternion (float).
Definition state.h:1253
static void stateSetPositionNed_f(uint16_t id, struct NedCoor_f *ned_pos)
Set position from local NED coordinates (float).
Definition state.h:718
static void stateSetLocalOrigin_i(uint16_t id, struct LtpDef_i *ltp_def)
Set the local (flat earth) coordinate frame origin (int).
Definition state.h:519
struct LlaCoor_i stateGetLlaOrigin_i(void)
Get the LLA position of the frame origin (int)
Definition state.c:124
static void stateSetBodyRates_f(uint16_t id, struct FloatRates *body_rate)
Set vehicle body angular rate (float).
Definition state.h:1346
static void stateSetSpeedNed_f(uint16_t id, struct NedCoor_f *ned_speed)
Set ground speed in local NED coordinates (float).
Definition state.h:947
#define INS_RESET_VERTICAL_REF
Definition ins.h:37
#define INS_RESET_REF
flags for INS reset
Definition ins.h:36
static void reset_vertical_ref(void)
Definition ins_ekf2.cpp:678
static void relpos_cb(uint8_t sender_id, uint32_t stamp, struct RelPosNED *relpos)
static abi_event optical_flow_ev
Definition ins_ekf2.cpp:314
static void gps_cb(uint8_t sender_id, uint32_t stamp, struct GpsState *gps_s)
Definition ins_ekf2.cpp:992
#define INS_EKF2_EVV_NOISE
Definition ins_ekf2.cpp:268
void ins_ekf2_update(void)
Definition ins_ekf2.cpp:712
#define INS_EKF2_IMU_POS_Z
Definition ins_ekf2.cpp:184
#define INS_EKF2_GPS_ID
Definition ins_ekf2.cpp:154
static void reset_cb(uint8_t sender_id, uint8_t flag)
Definition ins_ekf2.cpp:697
static void send_ins(struct transport_tx *trans, struct link_device *dev)
Definition ins_ekf2.cpp:340
#define INS_EKF2_GPS_POS_Y
Definition ins_ekf2.cpp:196
static void send_ins_ekf2(struct transport_tx *trans, struct link_device *dev)
Definition ins_ekf2.cpp:397
void ins_ekf2_remove_gps(int32_t mode)
Definition ins_ekf2.cpp:789
static void send_ins_ekf2_ext(struct transport_tx *trans, struct link_device *dev)
Definition ins_ekf2.cpp:430
static abi_event temperature_ev
Definition ins_ekf2.cpp:307
static void optical_flow_cb(uint8_t sender_id, uint32_t stamp, int32_t flow_x, int32_t flow_y, int32_t flow_der_x, int32_t flow_der_y, float quality, float size_divergence)
#define INS_EKF2_TEMPERATURE_ID
default temperature sensor to use in INS
Definition ins_ekf2.cpp:124
#define INS_EKF2_RELHEADING_ERR
Definition ins_ekf2.cpp:298
#define INS_EKF2_VDIST_SENSOR_TYPE
The EKF2 primary vertical distance sensor type.
Definition ins_ekf2.cpp:84
static abi_event mag_ev
Definition ins_ekf2.cpp:311
static void reset_ref(void)
Definition ins_ekf2.cpp:664
#define INS_EKF2_RELPOS_ID
Definition ins_ekf2.cpp:160
static void mag_cb(uint8_t sender_id, uint32_t stamp, struct Int32Vect3 *mag)
Definition ins_ekf2.cpp:968
static void accel_int_cb(uint8_t sender_id, uint32_t stamp, struct FloatVect3 *delta_accel, uint16_t dt)
Definition ins_ekf2.cpp:953
#define INS_EKF2_FUSION_MODE
Special configuration for Optitrack.
Definition ins_ekf2.cpp:72
static abi_event reset_ev
Definition ins_ekf2.cpp:315
#define INS_EKF2_GPS_CHECK_MASK
The EKF2 GPS checks before initialization.
Definition ins_ekf2.cpp:90
#define INS_EKF2_RANGE_MAIN_AGL
If enabled uses radar sensor as primary AGL source, if possible.
Definition ins_ekf2.cpp:108
#define INS_EKF2_MAX_FLOW_RATE
Definition ins_ekf2.cpp:220
#define INS_EKF2_GPS_POS_Z
Definition ins_ekf2.cpp:202
static abi_event gyro_int_ev
Definition ins_ekf2.cpp:309
static abi_event relpos_ev
Definition ins_ekf2.cpp:313
#define INS_EKF2_EVA_NOISE
Definition ins_ekf2.cpp:274
#define INS_EKF2_BARO_NOISE
Definition ins_ekf2.cpp:292
#define INS_EKF2_ACCEL_ID
Definition ins_ekf2.cpp:142
#define INS_EKF2_GYRO_ID
Definition ins_ekf2.cpp:136
static void send_ins_ref(struct transport_tx *trans, struct link_device *dev)
Definition ins_ekf2.cpp:387
static void temperature_cb(uint8_t sender_id, float temp)
Definition ins_ekf2.cpp:921
#define INS_EKF2_FLOW_POS_Y
Definition ins_ekf2.cpp:232
static void agl_cb(uint8_t sender_id, uint32_t stamp, float distance)
Definition ins_ekf2.cpp:927
static void send_ins_z(struct transport_tx *trans, struct link_device *dev)
Definition ins_ekf2.cpp:367
static abi_event baro_ev
Definition ins_ekf2.cpp:306
static parameters * ekf_params
The EKF parameters.
Definition ins_ekf2.cpp:334
void ins_ekf2_init(void)
Definition ins_ekf2.cpp:549
static void send_filter_status(struct transport_tx *trans, struct link_device *dev)
Definition ins_ekf2.cpp:444
#define INS_EKF2_FLOW_INNOV_GATE
Definition ins_ekf2.cpp:256
#define INS_EKF2_FLOW_NOISE
Definition ins_ekf2.cpp:244
#define INS_EKF2_EVP_NOISE
Definition ins_ekf2.cpp:262
static void baro_cb(uint8_t sender_id, uint32_t stamp, float pressure)
Definition ins_ekf2.cpp:906
static void send_wind_info_ret(struct transport_tx *trans, struct link_device *dev)
Definition ins_ekf2.cpp:469
#define INS_EKF2_MIN_FLOW_QUALITY
Definition ins_ekf2.cpp:214
#define INS_EKF2_GPS_V_NOISE
Definition ins_ekf2.cpp:280
static Ekf ekf
EKF class itself.
Definition ins_ekf2.cpp:333
struct ekf2_t ekf2
Local EKF2 status structure.
Definition ins_ekf2.cpp:335
#define INS_EKF2_FLOW_SENSOR_DELAY
Definition ins_ekf2.cpp:208
void ins_ekf2_parse_EXTERNAL_POSE(uint8_t *buf)
Definition ins_ekf2.cpp:798
void ins_ekf2_parse_EXTERNAL_POSE_SMALL(uint8_t *buf)
Definition ins_ekf2.cpp:832
#define INS_EKF2_MAG_ID
Definition ins_ekf2.cpp:148
#define INS_EKF2_IMU_POS_X
Definition ins_ekf2.cpp:172
#define INS_EKF2_GPS_P_NOISE
Definition ins_ekf2.cpp:286
static void send_ahrs_quat(struct transport_tx *trans, struct link_device *dev)
Definition ins_ekf2.cpp:491
#define INS_EKF2_AGL_ID
default AGL sensor to use in INS
Definition ins_ekf2.cpp:130
#define INS_EKF2_OF_ID
Definition ins_ekf2.cpp:166
static void ins_ekf2_publish_attitude(uint32_t stamp)
Publish the attitude and get the new state Directly called after a succeslfull gyro+accel reading.
Definition ins_ekf2.cpp:839
static void gyro_int_cb(uint8_t sender_id, uint32_t stamp, struct FloatRates *delta_gyro, uint16_t dt)
Definition ins_ekf2.cpp:938
#define INS_EKF2_SONAR_MIN_RANGE
Default AGL sensor minimum range.
Definition ins_ekf2.cpp:96
#define INS_EKF2_FLOW_NOISE_QMIN
Definition ins_ekf2.cpp:250
#define INS_EKF2_IMU_POS_Y
Definition ins_ekf2.cpp:178
static abi_event accel_int_ev
Definition ins_ekf2.cpp:310
#define INS_EKF2_FLOW_POS_Z
Definition ins_ekf2.cpp:238
static struct extVisionSample sample_ev
External vision sample.
Definition ins_ekf2.cpp:336
#define INS_EKF2_BARO_ID
default barometer to use in INS
Definition ins_ekf2.cpp:117
static void send_external_pose_down(struct transport_tx *trans, struct link_device *dev)
Definition ins_ekf2.cpp:516
#define INS_EKF2_MAG_FUSION_TYPE
The EKF2 magnetometer fusion type.
Definition ins_ekf2.cpp:78
#define INS_EKF2_SONAR_MAX_RANGE
Default AGL sensor maximum range.
Definition ins_ekf2.cpp:102
#define INS_EKF2_GPS_POS_X
Definition ins_ekf2.cpp:190
#define INS_EKF2_FLOW_POS_X
Definition ins_ekf2.cpp:226
static abi_event gps_ev
Definition ins_ekf2.cpp:312
static abi_event agl_ev
Definition ins_ekf2.cpp:308
static void send_ahrs_bias(struct transport_tx *trans, struct link_device *dev)
Definition ins_ekf2.cpp:481
INS based in the EKF2 of PX4.
bool accel_valid
If we received a acceleration measurement.
Definition ins_ekf2.h:46
bool rel_heading_valid
If we received a valid relative heading.
Definition ins_ekf2.h:49
bool got_imu_data
If we received valid IMU data (any sensor)
Definition ins_ekf2.h:56
int32_t fusion_mode
Definition ins_ekf2.h:58
bool gyro_valid
If we received a gyroscope measurement.
Definition ins_ekf2.h:45
uint32_t accel_dt
Accelerometer delta timestamp between abi messages (us)
Definition ins_ekf2.h:44
uint32_t gyro_dt
Gyroscope delta timestamp between abi messages (us)
Definition ins_ekf2.h:43
struct LtpDef_i ltp_def
Latest LTP definition from the quat_reset_counter EKF2.
Definition ins_ekf2.h:55
uint32_t flow_stamp
Optic flow last abi message timestamp.
Definition ins_ekf2.h:47
float rel_heading
Relative heading from RTK gps (rad)
Definition ins_ekf2.h:48
float temp
Latest temperature measurement in degrees celcius.
Definition ins_ekf2.h:51
struct FloatVect3 delta_accel
Last accelerometer measurements.
Definition ins_ekf2.h:42
uint64_t ltp_stamp
Last LTP change timestamp from the EKF2.
Definition ins_ekf2.h:54
float qnh
QNH value in hPa.
Definition ins_ekf2.h:52
uint8_t quat_reset_counter
Amount of quaternion resets from the EKF2.
Definition ins_ekf2.h:53
struct FloatRates delta_gyro
Last gyroscope measurements.
Definition ins_ekf2.h:41
float parameters[22]
Definition ins_flow.c:249
uint16_t foo
Definition main_demo5.c:58
void waypoints_localize_all(void)
update local ENU coordinates of global waypoints
Definition waypoints.c:362
bool nps_bypass_ins
void sim_overwrite_ins(void)
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
float z
in meters
float x
in meters
float y
in meters
vector in North East Down coordinates Units: meters
WGS-84 Geoid Heights.
Paparazzi atmospheric pressure conversion utilities.
struct HorizontalGuidance guidance_h
Definition guidance_h.c:45
struct HorizontalGuidanceRCInput rc_sp
remote control setpoint
Definition guidance_h.h:111
struct HorizontalGuidanceSetpoint sp
setpoints
Definition guidance_h.h:109
struct RotorcraftNavigation nav
Definition navigation.c:51
float heading
heading setpoint (in radians)
Definition navigation.h:133
void stabilization_attitude_enter(void)
Attitude control enter function.
static uint8_t mode
mode holds the current sonar mode mode = 0 used at high altitude, uses 16 wave patterns mode = 1 used...
Definition sonar_bebop.c:65
static const struct usb_device_descriptor dev
Definition usb_ser_hw.c:74
Architecture independent timing functions.
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
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 long long uint64_t
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.