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_MAG_FUSION_TYPE
63#define INS_EKF2_MAG_FUSION_TYPE MAG_FUSE_TYPE_INDOOR
65#ifndef INS_EKF2_VDIST_SENSOR_TYPE
66#define INS_EKF2_VDIST_SENSOR_TYPE VDIST_SENSOR_EV
71#ifndef INS_EKF2_FUSION_MODE
72#define INS_EKF2_FUSION_MODE (MASK_USE_GPS)
77#ifndef INS_EKF2_MAG_FUSION_TYPE
78#define INS_EKF2_MAG_FUSION_TYPE MAG_FUSE_TYPE_AUTO
83#ifndef INS_EKF2_VDIST_SENSOR_TYPE
84#define INS_EKF2_VDIST_SENSOR_TYPE VDIST_SENSOR_BARO
89#ifndef INS_EKF2_GPS_CHECK_MASK
90#define INS_EKF2_GPS_CHECK_MASK 21
95#ifndef INS_EKF2_SONAR_MIN_RANGE
96#define INS_EKF2_SONAR_MIN_RANGE 0.001
101#ifndef INS_EKF2_SONAR_MAX_RANGE
102#define INS_EKF2_SONAR_MAX_RANGE 4
107#ifndef INS_EKF2_RANGE_MAIN_AGL
108#define INS_EKF2_RANGE_MAIN_AGL 1
113#ifndef INS_EKF2_BARO_ID
115#define INS_EKF2_BARO_ID BARO_BOARD_SENDER_ID
117#define INS_EKF2_BARO_ID ABI_BROADCAST
123#ifndef INS_EKF2_TEMPERATURE_ID
124#define INS_EKF2_TEMPERATURE_ID ABI_BROADCAST
129#ifndef INS_EKF2_AGL_ID
130#define INS_EKF2_AGL_ID ABI_BROADCAST
135#ifndef INS_EKF2_GYRO_ID
136#define INS_EKF2_GYRO_ID ABI_BROADCAST
141#ifndef INS_EKF2_ACCEL_ID
142#define INS_EKF2_ACCEL_ID ABI_BROADCAST
147#ifndef INS_EKF2_MAG_ID
148#define INS_EKF2_MAG_ID ABI_BROADCAST
153#ifndef INS_EKF2_GPS_ID
154#define INS_EKF2_GPS_ID GPS_MULTI_ID
159#ifndef INS_EKF2_RELPOS_ID
160#define INS_EKF2_RELPOS_ID ABI_BROADCAST
165#ifndef INS_EKF2_OF_ID
166#define INS_EKF2_OF_ID ABI_BROADCAST
171#ifndef INS_EKF2_IMU_POS_X
172#define INS_EKF2_IMU_POS_X 0
177#ifndef INS_EKF2_IMU_POS_Y
178#define INS_EKF2_IMU_POS_Y 0
183#ifndef INS_EKF2_IMU_POS_Z
184#define INS_EKF2_IMU_POS_Z 0
189#ifndef INS_EKF2_GPS_POS_X
190#define INS_EKF2_GPS_POS_X 0
195#ifndef INS_EKF2_GPS_POS_Y
196#define INS_EKF2_GPS_POS_Y 0
201#ifndef INS_EKF2_GPS_POS_Z
202#define INS_EKF2_GPS_POS_Z 0
207#ifndef INS_EKF2_FLOW_SENSOR_DELAY
208#define INS_EKF2_FLOW_SENSOR_DELAY 15
213#ifndef INS_EKF2_MIN_FLOW_QUALITY
214#define INS_EKF2_MIN_FLOW_QUALITY 100
219#ifndef INS_EKF2_MAX_FLOW_RATE
220#define INS_EKF2_MAX_FLOW_RATE 200
225#ifndef INS_EKF2_FLOW_POS_X
226#define INS_EKF2_FLOW_POS_X 0
231#ifndef INS_EKF2_FLOW_POS_Y
232#define INS_EKF2_FLOW_POS_Y 0
237#ifndef INS_EKF2_FLOW_POS_Z
238#define INS_EKF2_FLOW_POS_Z 0
243#ifndef INS_EKF2_FLOW_NOISE
244#define INS_EKF2_FLOW_NOISE 0.03
249#ifndef INS_EKF2_FLOW_NOISE_QMIN
250#define INS_EKF2_FLOW_NOISE_QMIN 0.05
255#ifndef INS_EKF2_FLOW_INNOV_GATE
256#define INS_EKF2_FLOW_INNOV_GATE 4
261#ifndef INS_EKF2_EVP_NOISE
262#define INS_EKF2_EVP_NOISE 0.02f
267#ifndef INS_EKF2_EVV_NOISE
268#define INS_EKF2_EVV_NOISE 0.1f
273#ifndef INS_EKF2_EVA_NOISE
274#define INS_EKF2_EVA_NOISE 0.05f
279#ifndef INS_EKF2_GPS_V_NOISE
280#define INS_EKF2_GPS_V_NOISE 0.3f
285#ifndef INS_EKF2_GPS_P_NOISE
286#define INS_EKF2_GPS_P_NOISE 0.5f
291#ifndef INS_EKF2_BARO_NOISE
292#define INS_EKF2_BARO_NOISE 3.5f
297#ifndef INS_EKF2_RELHEADING_ERR
298#define INS_EKF2_RELHEADING_ERR 0.2
301#ifdef INS_EXT_VISION_ROTATION
337#if PERIODIC_TELEMETRY
362 &pos.
x, &pos.
y, &pos.
z,
363 &speed.
x, &speed.
y, &speed.
z,
364 &accel.
x, &accel.
y, &accel.
z);
389 float qfe = 101325.0;
412 if (
ekf.isTerrainEstimateValid()) {
418 if (
ekf.inertial_dead_reckoning()) {
476 ekf.get_true_airspeed(&tas);
504 <p_to_body_quat.
qi,
505 <p_to_body_quat.
qx,
506 <p_to_body_quat.
qy,
507 <p_to_body_quat.
qz,
636#if PERIODIC_TELEMETRY
669 if (
ekf.setEkfGlobalOrigin(lla_pos.
lat*1e-7, lla_pos.
lon*1e-7,
gps.
hmsl*1e-3)) {
780#if defined SITL && USE_NPS
813#ifdef INS_EXT_VISION_ROTATION
827 sample_ev.vel_frame = velocity_frame_t::LOCAL_FRAME_FRD;
849 if (
ekf.attitude_valid()) {
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);
866#ifndef NO_RESET_UPDATE_SETPOINT_HEADING
869 float psi = matrix::Eulerf(matrix::Quatf(
delta_q_reset)).psi();
1002#if INS_EKF2_GPS_COURSE_YAW
1005#elif defined(INS_EKF2_GPS_YAW_OFFSET)
1087 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)
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_MAG_FUSION_TYPE
The EKF2 magnetometer fusion type.
#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.
int16_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint16_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.