31 #include "stabilization/stabilization_attitude.h"
32 #include "generated/airframe.h"
39 #if defined SITL && USE_NPS
46 #error INS initialization from flight plan is not yet supported
50 #ifndef INS_EKF2_AGL_ID
51 #define INS_EKF2_AGL_ID ABI_BROADCAST
56 #ifndef INS_SONAR_MIN_RANGE
57 #define INS_SONAR_MIN_RANGE 0.001
62 #ifndef INS_SONAR_MAX_RANGE
63 #define INS_SONAR_MAX_RANGE 4.0
68 #ifndef INS_EKF2_BARO_ID
70 #define INS_EKF2_BARO_ID BARO_BOARD_SENDER_ID
72 #define INS_EKF2_BARO_ID ABI_BROADCAST
78 #ifndef INS_EKF2_GYRO_ID
79 #define INS_EKF2_GYRO_ID ABI_BROADCAST
84 #ifndef INS_EKF2_ACCEL_ID
85 #define INS_EKF2_ACCEL_ID ABI_BROADCAST
90 #ifndef INS_EKF2_MAG_ID
91 #define INS_EKF2_MAG_ID ABI_BROADCAST
96 #ifndef INS_EKF2_GPS_ID
97 #define INS_EKF2_GPS_ID GPS_MULTI_ID
152 #if PERIODIC_TELEMETRY
157 float qfe = 101325.0;
159 pprz_msg_send_INS_REF(trans, dev, AC_ID,
167 uint16_t gps_check_status, filter_fault_status, soln_status;
169 ekf.get_gps_check_status(&gps_check_status);
170 ekf.get_filter_fault_status(&filter_fault_status);
171 ekf.get_control_mode(&control_mode);
172 ekf.get_ekf_soln_status(&soln_status);
175 float mag, vel, pos, hgt, tas, hagl, beta, mag_decl;
176 ekf.get_innovation_test_status(&innov_test_status, &mag, &vel, &pos, &hgt, &tas, &hagl, &beta);
177 ekf.get_mag_decl_deg(&mag_decl);
178 pprz_msg_send_INS_EKF2(trans, dev, AC_ID,
179 &control_mode, &filter_fault_status, &gps_check_status, &soln_status,
180 &innov_test_status, &mag, &vel, &pos, &hgt, &tas, &hagl, &beta,
186 float gps_drift[3], vibe[3];
189 ekf.get_gps_drift_metrics(gps_drift, &gps_blocked);
190 ekf.get_imu_vibe_metrics(vibe);
191 gps_blocked_b = gps_blocked;
193 pprz_msg_send_INS_EKF2_EXT(trans, dev, AC_ID,
194 &gps_drift[0], &gps_drift[1], &gps_drift[2], &gps_blocked_b,
195 &vibe[0], &vibe[1], &vibe[2]);
203 ekf.get_control_mode(&control_mode);
204 ekf.get_filter_fault_status(&filter_fault_status);
207 if ((control_mode & 0x7) == 0x7) {
209 }
else if ((control_mode & 0x7) == 0x3) {
216 if (filter_fault_status) {
220 pprz_msg_send_STATE_FILTER_STATUS(trans, dev, AC_ID, &ahrs_ekf2_id, &mde, &filter_fault_status);
225 float velNE_wind[2], tas;
229 ekf.get_wind_velocity(velNE_wind);
230 ekf.get_true_airspeed(&tas);
232 pprz_msg_send_WIND_INFO_RET(trans, dev, AC_ID, &flags, &velNE_wind[1], &velNE_wind[0], &f_zero, &tas);
237 float accel_bias[3], gyro_bias[3],
states[24];
238 ekf.get_accel_bias(accel_bias);
239 ekf.get_gyro_bias(gyro_bias);
240 ekf.get_state_delayed(states);
242 pprz_msg_send_AHRS_BIAS(trans, dev, AC_ID, &accel_bias[0], &accel_bias[1], &accel_bias[2],
243 &gyro_bias[0], &gyro_bias[1], &gyro_bias[2], &states[19], &states[20], &states[21]);
251 ekf_params = ekf.getParamHandle();
252 ekf_params->mag_fusion_type = MAG_FUSE_TYPE_HEADING;
253 ekf_params->is_moving_scaler = 0.8f;
267 #if PERIODIC_TELEMETRY
296 filter_control_status_u control_status;
297 ekf.get_control_mode(&control_status.value);
300 if (control_status.flags.tilt_align) {
304 ekf.get_position(pos_f);
315 ekf.get_velocity(vel_f);
324 float vel_deriv_f[3] = {};
326 ekf.get_vel_deriv_ned(vel_deriv_f);
327 accel.
x = vel_deriv_f[0];
328 accel.
y = vel_deriv_f[1];
329 accel.
z = vel_deriv_f[2];
336 struct map_projection_reference_s ekf_origin = {};
342 bool ekf_origin_valid = ekf.get_ekf_origin(&origin_time, &ekf_origin, &ref_alt);
344 lla_ref.
lat = ekf_origin.lat_rad * 180.0 / M_PI * 1e7;
345 lla_ref.
lon = ekf_origin.lon_rad * 180.0 / M_PI * 1e7;
346 lla_ref.
alt = ref_alt * 1000.0;
355 #if defined SITL && USE_NPS
373 imuSample imu_sample;
374 imu_sample.time_us = stamp;
379 ekf.setIMUData(imu_sample);
381 if (ekf.attitude_valid()) {
384 const Quatf att_q{ekf.calculate_quaternion()};
385 ltp_to_body_quat.
qi = att_q(0);
386 ltp_to_body_quat.
qx = att_q(1);
387 ltp_to_body_quat.
qy = att_q(2);
388 ltp_to_body_quat.
qz = att_q(3);
394 float delta_q_reset[4];
396 ekf.get_quat_reset(delta_q_reset, &quat_reset_counter);
398 #ifndef NO_RESET_UPDATE_SETPOINT_HEADING
401 float psi = matrix::Eulerf(matrix::Quatf(delta_q_reset)).psi();
402 #if defined STABILIZATION_ATTITUDE_TYPE_INT
419 ekf.get_gyro_bias(gyro_bias);
430 ekf.get_accel_bias(accel_bias);
450 ekf.set_air_density(rho);
455 ekf.setBaroData(stamp, height_amsl_m);
461 ekf.setRangeData(stamp, distance);
535 mag_r[0] = mag_body.
x;
536 mag_r[1] = mag_body.
y;
537 mag_r[2] = mag_body.
z;
539 ekf.setMagData(stamp, mag_r);
566 ekf.setGpsData(stamp,
gps_msg);
Event structure to store callbacks in a linked list.
static void orientationSetQuat_f(struct OrientationReps *orientation, struct FloatQuat *quat)
Set vehicle body attitude from quaternion (float).
void ins_ekf2_change_param(int32_t unk)
void guidance_h_read_rc(bool in_flight)
definition of the local (flat earth) coordinate system
static void body_to_imu_cb(uint8_t sender_id, struct FloatQuat *q_b2i_f)
#define INS_SONAR_MIN_RANGE
Default AGL sensor minimum range.
#define GPS_VALID_VEL_NED_BIT
Periodic telemetry system header (includes downlink utility and generated code).
uint8_t valid_fields
bitfield indicating valid fields (GPS_VALID_x_BIT)
uint32_t hacc
horizontal accuracy in cm
static struct nodeState states[UWB_SERIAL_COMM_DIST_NUM_NODES]
static struct FloatRMat * orientationGetRMat_f(struct OrientationReps *orientation)
Get vehicle body attitude rotation matrix (float).
uint8_t quat_reset_counter
static void stateSetAccelBody_i(struct Int32Vect3 *body_accel)
Set acceleration in Body coordinates (int).
Main include for ABI (AirBorneInterface).
uint32_t vacc
vertical accuracy in cm
static void mag_cb(uint8_t sender_id, uint32_t stamp, struct Int32Vect3 *mag)
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 stateSetNedToBodyQuat_f(struct FloatQuat *ned_to_body_quat)
Set vehicle body attitude from quaternion (float).
struct ekf2_parameters_t ekf2_params
void stabilization_attitude_enter(void)
static void baro_cb(uint8_t sender_id, uint32_t stamp, float pressure)
static parameters * ekf_params
The EKF parameters.
vector in Latitude, Longitude and Altitude
void ltp_def_from_lla_i(struct LtpDef_i *def, struct LlaCoor_i *lla)
struct EcefCoor_i ecef
Reference point in ecef.
int32_t hmsl
Height above mean sea level in mm.
int32_t alt
in millimeters above WGS84 reference ellipsoid
struct gps_message gps_msg
uint32_t sacc
speed accuracy in cm/s
static void send_ins_ekf2_ext(struct transport_tx *trans, struct link_device *dev)
#define INS_EKF2_ACCEL_ID
struct FloatEulers stab_att_sp_euler
with INT32_ANGLE_FRAC
static void gyro_cb(uint8_t sender_id, uint32_t stamp, struct Int32Rates *gyro)
struct ekf2_t ekf2
Local EKF2 status structure.
#define AHRS_COMP_ID_EKF2
INS based in the EKF2 of PX4.
static void stateSetSpeedNed_f(struct NedCoor_f *ned_speed)
Set ground speed in local NED coordinates (float).
unsigned long long uint64_t
int32_t hmsl
height above mean sea level (MSL) in mm
static Ekf ekf
EKF class itself.
void float_rmat_transp_vmult(struct FloatVect3 *vb, struct FloatRMat *m_b2a, struct FloatVect3 *va)
rotate 3D vector by transposed rotation matrix.
#define RATES_FLOAT_OF_BFP(_rf, _ri)
static float pprz_isa_density_of_pressure(float pressure, float temp)
Get the air density (rho) from a given pressure and temperature.
vector in North East Down coordinates Units: meters
Architecture independent timing functions.
data structure for GPS information
bool autopilot_in_flight(void)
get in_flight flag
int32_t nav_heading
with INT32_ANGLE_FRAC
static void stateSetLocalOrigin_i(struct LtpDef_i *ltp_def)
Set the local (flat earth) coordinate frame origin (int).
Paparazzi atmospheric pressure conversion utilities.
#define INS_EKF2_AGL_ID
For SITL and NPS we need special includes.
struct LlaCoor_i lla
Reference point in lla.
#define DefaultPeriodic
Set default periodic telemetry.
int32_t lon
in degrees*1e7
void ins_ekf2_update(void)
struct HorizontalGuidance guidance_h
#define INS_EKF2_BARO_ID
default barometer to use in INS
static void send_ins_ekf2(struct transport_tx *trans, struct link_device *dev)
#define INS_SONAR_MAX_RANGE
Default AGL sensor maximum range.
static float pprz_isa_height_of_pressure_full(float pressure, float ref_p)
Get relative altitude from pressure (using full equation).
static void stateSetPositionNed_f(struct NedCoor_f *ned_pos)
Set position from local NED coordinates (float).
#define ACCELS_FLOAT_OF_BFP(_ef, _ei)
static void send_ins_ref(struct transport_tx *trans, struct link_device *dev)
#define ANGLE_BFP_OF_REAL(_af)
static const struct usb_device_descriptor dev
Core autopilot interface common to all firmwares.
static abi_event body_to_imu_ev
static void agl_cb(uint8_t sender_id, uint32_t stamp, float distance)
void float_rmat_transp_ratemult(struct FloatRates *rb, struct FloatRMat *m_b2a, struct FloatRates *ra)
rotate anglular rates by transposed rotation matrix.
static void send_ahrs_bias(struct transport_tx *trans, struct link_device *dev)
static void send_wind_info_ret(struct transport_tx *trans, struct link_device *dev)
struct OrientationReps body_to_imu
static uint8_t ahrs_ekf2_id
Component ID for EKF.
uint8_t num_sv
number of sat in fix
#define ABI_BROADCAST
Broadcast address.
uint16_t gspeed
norm of 2d ground speed in cm/s
#define MAGS_FLOAT_OF_BFP(_ef, _ei)
static abi_event accel_ev
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
#define ACCEL_BFP_OF_REAL(_af)
int32_t lat
in degrees*1e7
static void stateSetBodyRates_f(struct FloatRates *body_rate)
Set vehicle body angular rate (float).
struct NedCoor_i ned_vel
speed NED in cm/s
static void stateSetAccelNed_f(struct NedCoor_f *ned_accel)
Set acceleration in NED coordinates (float).
struct HorizontalGuidanceSetpoint sp
setpoints
static void send_filter_status(struct transport_tx *trans, struct link_device *dev)
static void gps_cb(uint8_t sender_id, uint32_t stamp, struct GpsState *gps_s)
void sim_overwrite_ins(void)
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
static void accel_cb(uint8_t sender_id, uint32_t stamp, struct Int32Vect3 *accel)