32#include "stabilization/stabilization_attitude.h"
33#include "generated/airframe.h"
34#include "generated/flight_plan.h"
42#if defined SITL && USE_NPS
48#ifndef USE_INS_NAV_INIT
49#define USE_INS_NAV_INIT TRUE
53#ifndef INS_EKF2_MAX_REL_LENGTH_ERROR
54#define INS_EKF2_MAX_REL_LENGTH_ERROR 0.2
59#ifndef INS_EKF2_FUSION_MODE
60#define INS_EKF2_FUSION_MODE (MASK_USE_EVPOS | MASK_USE_EVVEL | MASK_USE_EVYAW)
62#ifndef INS_EKF2_VDIST_SENSOR_TYPE
63#define INS_EKF2_VDIST_SENSOR_TYPE VDIST_SENSOR_EV
68#ifndef INS_EKF2_FUSION_MODE
69#define INS_EKF2_FUSION_MODE (MASK_USE_GPS)
74#ifndef INS_EKF2_VDIST_SENSOR_TYPE
75#define INS_EKF2_VDIST_SENSOR_TYPE VDIST_SENSOR_BARO
80#ifndef INS_EKF2_GPS_CHECK_MASK
81#define INS_EKF2_GPS_CHECK_MASK 21
86#ifndef INS_EKF2_SONAR_MIN_RANGE
87#define INS_EKF2_SONAR_MIN_RANGE 0.001
92#ifndef INS_EKF2_SONAR_MAX_RANGE
93#define INS_EKF2_SONAR_MAX_RANGE 4
98#ifndef INS_EKF2_RANGE_MAIN_AGL
99#define INS_EKF2_RANGE_MAIN_AGL 1
104#ifndef INS_EKF2_BARO_ID
106#define INS_EKF2_BARO_ID BARO_BOARD_SENDER_ID
108#define INS_EKF2_BARO_ID ABI_BROADCAST
114#ifndef INS_EKF2_TEMPERATURE_ID
115#define INS_EKF2_TEMPERATURE_ID ABI_BROADCAST
120#ifndef INS_EKF2_AGL_ID
121#define INS_EKF2_AGL_ID ABI_BROADCAST
126#ifndef INS_EKF2_GYRO_ID
127#define INS_EKF2_GYRO_ID ABI_BROADCAST
132#ifndef INS_EKF2_ACCEL_ID
133#define INS_EKF2_ACCEL_ID ABI_BROADCAST
138#ifndef INS_EKF2_MAG_ID
139#define INS_EKF2_MAG_ID ABI_BROADCAST
144#ifndef INS_EKF2_GPS_ID
145#define INS_EKF2_GPS_ID GPS_MULTI_ID
150#ifndef INS_EKF2_RELPOS_ID
151#define INS_EKF2_RELPOS_ID ABI_BROADCAST
156#ifndef INS_EKF2_OF_ID
157#define INS_EKF2_OF_ID ABI_BROADCAST
162#ifndef INS_EKF2_IMU_POS_X
163#define INS_EKF2_IMU_POS_X 0
168#ifndef INS_EKF2_IMU_POS_Y
169#define INS_EKF2_IMU_POS_Y 0
174#ifndef INS_EKF2_IMU_POS_Z
175#define INS_EKF2_IMU_POS_Z 0
180#ifndef INS_EKF2_GPS_POS_X
181#define INS_EKF2_GPS_POS_X 0
186#ifndef INS_EKF2_GPS_POS_Y
187#define INS_EKF2_GPS_POS_Y 0
192#ifndef INS_EKF2_GPS_POS_Z
193#define INS_EKF2_GPS_POS_Z 0
198#ifndef INS_EKF2_FLOW_SENSOR_DELAY
199#define INS_EKF2_FLOW_SENSOR_DELAY 15
204#ifndef INS_EKF2_MIN_FLOW_QUALITY
205#define INS_EKF2_MIN_FLOW_QUALITY 100
210#ifndef INS_EKF2_MAX_FLOW_RATE
211#define INS_EKF2_MAX_FLOW_RATE 200
216#ifndef INS_EKF2_FLOW_POS_X
217#define INS_EKF2_FLOW_POS_X 0
222#ifndef INS_EKF2_FLOW_POS_Y
223#define INS_EKF2_FLOW_POS_Y 0
228#ifndef INS_EKF2_FLOW_POS_Z
229#define INS_EKF2_FLOW_POS_Z 0
234#ifndef INS_EKF2_FLOW_NOISE
235#define INS_EKF2_FLOW_NOISE 0.03
240#ifndef INS_EKF2_FLOW_NOISE_QMIN
241#define INS_EKF2_FLOW_NOISE_QMIN 0.05
246#ifndef INS_EKF2_FLOW_INNOV_GATE
247#define INS_EKF2_FLOW_INNOV_GATE 4
252#ifndef INS_EKF2_EVP_NOISE
253#define INS_EKF2_EVP_NOISE 0.02f
258#ifndef INS_EKF2_EVV_NOISE
259#define INS_EKF2_EVV_NOISE 0.1f
264#ifndef INS_EKF2_EVA_NOISE
265#define INS_EKF2_EVA_NOISE 0.05f
270#ifndef INS_EKF2_GPS_V_NOISE
271#define INS_EKF2_GPS_V_NOISE 0.3f
276#ifndef INS_EKF2_GPS_P_NOISE
277#define INS_EKF2_GPS_P_NOISE 0.5f
282#ifndef INS_EKF2_BARO_NOISE
283#define INS_EKF2_BARO_NOISE 3.5f
288#ifndef INS_EKF2_RELHEADING_ERR
289#define INS_EKF2_RELHEADING_ERR 0.2
292#ifdef INS_EXT_VISION_ROTATION
328#if PERIODIC_TELEMETRY
353 &pos.
x, &pos.
y, &pos.
z,
354 &speed.
x, &speed.
y, &speed.
z,
355 &accel.
x, &accel.
y, &accel.
z);
380 float qfe = 101325.0;
403 if (
ekf.isTerrainEstimateValid()) {
409 if (
ekf.inertial_dead_reckoning()) {
467 ekf.get_true_airspeed(&tas);
495 <p_to_body_quat.
qi,
496 <p_to_body_quat.
qx,
497 <p_to_body_quat.
qy,
498 <p_to_body_quat.
qz,
626#if PERIODIC_TELEMETRY
659 if (
ekf.setEkfGlobalOrigin(lla_pos.
lat*1e-7, lla_pos.
lon*1e-7,
gps.
hmsl*1e-3)) {
770#if defined SITL && USE_NPS
808#ifdef INS_EXT_VISION_ROTATION
822 sample_ev.vel_frame = velocity_frame_t::LOCAL_FRAME_FRD;
844 if (
ekf.attitude_valid()) {
848 ltp_to_body_quat.
qi =
att_q(0);
849 ltp_to_body_quat.
qx =
att_q(1);
850 ltp_to_body_quat.
qy =
att_q(2);
851 ltp_to_body_quat.
qz =
att_q(3);
861#ifndef NO_RESET_UPDATE_SETPOINT_HEADING
864 float psi = matrix::Eulerf(matrix::Quatf(
delta_q_reset)).psi();
997#if INS_EKF2_GPS_COURSE_YAW
1000#elif defined(INS_EKF2_GPS_YAW_OFFSET)
1082 sample.quality = quality;
Main include for ABI (AirBorneInterface).
#define ABI_BROADCAST
Broadcast address.
Event structure to store callbacks in a linked list.
#define AHRS_COMP_ID_EKF2
bool autopilot_in_flight(void)
get in_flight flag
Core autopilot interface common to all firmwares.
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.
struct GpsState gps
global GPS state
struct LlaCoor_i lla_int_from_gps(struct GpsState *gps_s)
Get GPS lla (integer) Converted on the fly if not available.
int32_t hmsl
height above mean sea level (MSL) in mm
#define GPS_VALID_VEL_NED_BIT
data structure for GPS information
void float_quat_comp(struct FloatQuat *a2c, struct FloatQuat *a2b, struct FloatQuat *b2c)
Composition (multiplication) of two quaternions.
#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)
int32_t lat
in degrees*1e7
int32_t hmsl
Height above mean sea level in mm.
int32_t alt
in millimeters above WGS84 reference ellipsoid
struct LlaCoor_i lla
Reference point in lla.
struct EcefCoor_i ecef
Reference point in ecef.
int32_t lon
in degrees*1e7
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.
static float pprz_isa_height_of_pressure_full(float pressure, float ref_p)
Get relative altitude from pressure (using full equation).
static void stateSetAccelNed_f(uint16_t id, struct NedCoor_f *ned_accel)
Set acceleration in NED coordinates (float).
static void stateSetAccelBody_i(uint16_t id, struct Int32Vect3 *body_accel)
Set acceleration in Body coordinates (int).
static struct Int32Quat * stateGetNedToBodyQuat_i(void)
Get vehicle body attitude quaternion (int).
static void stateSetNedToBodyQuat_f(uint16_t id, struct FloatQuat *ned_to_body_quat)
Set vehicle body attitude from quaternion (float).
static void stateSetPositionNed_f(uint16_t id, struct NedCoor_f *ned_pos)
Set position from local NED coordinates (float).
static void stateSetLocalOrigin_i(uint16_t id, struct LtpDef_i *ltp_def)
Set the local (flat earth) coordinate frame origin (int).
struct LlaCoor_i stateGetLlaOrigin_i(void)
Get the LLA position of the frame origin (int)
static void stateSetBodyRates_f(uint16_t id, struct FloatRates *body_rate)
Set vehicle body angular rate (float).
static void stateSetSpeedNed_f(uint16_t id, struct NedCoor_f *ned_speed)
Set ground speed in local NED coordinates (float).
#define INS_RESET_VERTICAL_REF
#define INS_RESET_REF
flags for INS reset
static void reset_vertical_ref(void)
static void relpos_cb(uint8_t sender_id, uint32_t stamp, struct RelPosNED *relpos)
static abi_event optical_flow_ev
static void gps_cb(uint8_t sender_id, uint32_t stamp, struct GpsState *gps_s)
#define INS_EKF2_EVV_NOISE
void ins_ekf2_update(void)
#define INS_EKF2_IMU_POS_Z
static void reset_cb(uint8_t sender_id, uint8_t flag)
static void send_ins(struct transport_tx *trans, struct link_device *dev)
#define INS_EKF2_GPS_POS_Y
static void send_ins_ekf2(struct transport_tx *trans, struct link_device *dev)
void ins_ekf2_remove_gps(int32_t mode)
static void send_ins_ekf2_ext(struct transport_tx *trans, struct link_device *dev)
static abi_event temperature_ev
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
#define INS_EKF2_RELHEADING_ERR
#define INS_EKF2_VDIST_SENSOR_TYPE
The EKF2 primary vertical distance sensor type.
static void reset_ref(void)
#define INS_EKF2_RELPOS_ID
static void mag_cb(uint8_t sender_id, uint32_t stamp, struct Int32Vect3 *mag)
static void accel_int_cb(uint8_t sender_id, uint32_t stamp, struct FloatVect3 *delta_accel, uint16_t dt)
#define INS_EKF2_FUSION_MODE
Special configuration for Optitrack.
static abi_event reset_ev
#define INS_EKF2_GPS_CHECK_MASK
The EKF2 GPS checks before initialization.
#define INS_EKF2_RANGE_MAIN_AGL
If enabled uses radar sensor as primary AGL source, if possible.
#define INS_EKF2_MAX_FLOW_RATE
#define INS_EKF2_GPS_POS_Z
static abi_event gyro_int_ev
static abi_event relpos_ev
#define INS_EKF2_EVA_NOISE
#define INS_EKF2_BARO_NOISE
#define INS_EKF2_ACCEL_ID
static void send_ins_ref(struct transport_tx *trans, struct link_device *dev)
static void temperature_cb(uint8_t sender_id, float temp)
#define INS_EKF2_FLOW_POS_Y
static void agl_cb(uint8_t sender_id, uint32_t stamp, float distance)
static void send_ins_z(struct transport_tx *trans, struct link_device *dev)
static parameters * ekf_params
The EKF parameters.
static void send_filter_status(struct transport_tx *trans, struct link_device *dev)
#define INS_EKF2_FLOW_INNOV_GATE
#define INS_EKF2_FLOW_NOISE
#define INS_EKF2_EVP_NOISE
static void baro_cb(uint8_t sender_id, uint32_t stamp, float pressure)
void ins_ekf2_change_param(int32_t unk)
static void send_wind_info_ret(struct transport_tx *trans, struct link_device *dev)
#define INS_EKF2_MIN_FLOW_QUALITY
#define INS_EKF2_GPS_V_NOISE
static Ekf ekf
EKF class itself.
struct ekf2_t ekf2
Local EKF2 status structure.
#define INS_EKF2_FLOW_SENSOR_DELAY
void ins_ekf2_parse_EXTERNAL_POSE(uint8_t *buf)
void ins_ekf2_parse_EXTERNAL_POSE_SMALL(uint8_t *buf)
#define INS_EKF2_IMU_POS_X
#define INS_EKF2_GPS_P_NOISE
static void send_ahrs_quat(struct transport_tx *trans, struct link_device *dev)
#define INS_EKF2_AGL_ID
default AGL sensor to use in INS
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.
static void gyro_int_cb(uint8_t sender_id, uint32_t stamp, struct FloatRates *delta_gyro, uint16_t dt)
#define INS_EKF2_SONAR_MIN_RANGE
Default AGL sensor minimum range.
#define INS_EKF2_FLOW_NOISE_QMIN
#define INS_EKF2_IMU_POS_Y
static abi_event accel_int_ev
#define INS_EKF2_FLOW_POS_Z
static struct extVisionSample sample_ev
External vision sample.
#define INS_EKF2_BARO_ID
default barometer to use in INS
static void send_external_pose_down(struct transport_tx *trans, struct link_device *dev)
#define INS_EKF2_SONAR_MAX_RANGE
Default AGL sensor maximum range.
#define INS_EKF2_GPS_POS_X
#define INS_EKF2_FLOW_POS_X
static void send_ahrs_bias(struct transport_tx *trans, struct link_device *dev)
INS based in the EKF2 of PX4.
bool accel_valid
If we received a acceleration measurement.
bool rel_heading_valid
If we received a valid relative heading.
bool got_imu_data
If we received valid IMU data (any sensor)
bool gyro_valid
If we received a gyroscope measurement.
uint32_t accel_dt
Accelerometer delta timestamp between abi messages (us)
uint32_t gyro_dt
Gyroscope delta timestamp between abi messages (us)
struct LtpDef_i ltp_def
Latest LTP definition from the quat_reset_counter EKF2.
uint32_t flow_stamp
Optic flow last abi message timestamp.
float rel_heading
Relative heading from RTK gps (rad)
float temp
Latest temperature measurement in degrees celcius.
struct FloatVect3 delta_accel
Last accelerometer measurements.
uint64_t ltp_stamp
Last LTP change timestamp from the EKF2.
float qnh
QNH value in hPa.
uint8_t quat_reset_counter
Amount of quaternion resets from the EKF2.
struct FloatRates delta_gyro
Last gyroscope measurements.
void waypoints_localize_all(void)
update local ENU coordinates of global waypoints
void sim_overwrite_ins(void)
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
vector in North East Down coordinates Units: meters
Paparazzi atmospheric pressure conversion utilities.
struct HorizontalGuidance guidance_h
struct HorizontalGuidanceRCInput rc_sp
remote control setpoint
struct HorizontalGuidanceSetpoint sp
setpoints
struct RotorcraftNavigation nav
float heading
heading setpoint (in radians)
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...
static const struct usb_device_descriptor dev
Architecture independent timing functions.
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned long long uint64_t
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.