 |
Paparazzi UAS
v6.1.0_stable
Paparazzi is a free software Unmanned Aircraft System.
|
Go to the documentation of this file.
32 #include "stabilization/stabilization_attitude.h"
33 #include "generated/airframe.h"
40 #if defined SITL && USE_NPS
47 #error INS initialization from flight plan is not yet supported
51 #ifndef INS_EKF2_FUSION_MODE
52 #define INS_EKF2_FUSION_MODE (MASK_USE_GPS)
57 #ifndef INS_EKF2_VDIST_SENSOR_TYPE
58 #define INS_EKF2_VDIST_SENSOR_TYPE VDIST_SENSOR_BARO
63 #ifndef INS_EKF2_GPS_CHECK_MASK
64 #define INS_EKF2_GPS_CHECK_MASK 21 // (MASK_GPS_NSATS | MASK_GPS_HACC | MASK_GPS_SACC)
69 #ifndef INS_EKF2_AGL_ID
70 #define INS_EKF2_AGL_ID ABI_BROADCAST
75 #ifndef INS_EKF2_SONAR_MIN_RANGE
76 #define INS_EKF2_SONAR_MIN_RANGE 0.001
81 #ifndef INS_EKF2_SONAR_MAX_RANGE
82 #define INS_EKF2_SONAR_MAX_RANGE 4
87 #ifndef INS_EKF2_RANGE_MAIN_AGL
88 #define INS_EKF2_RANGE_MAIN_AGL 1
93 #ifndef INS_EKF2_BARO_ID
95 #define INS_EKF2_BARO_ID BARO_BOARD_SENDER_ID
97 #define INS_EKF2_BARO_ID ABI_BROADCAST
103 #ifndef INS_EKF2_GYRO_ID
104 #define INS_EKF2_GYRO_ID ABI_BROADCAST
109 #ifndef INS_EKF2_ACCEL_ID
110 #define INS_EKF2_ACCEL_ID ABI_BROADCAST
115 #ifndef INS_EKF2_MAG_ID
116 #define INS_EKF2_MAG_ID ABI_BROADCAST
121 #ifndef INS_EKF2_GPS_ID
122 #define INS_EKF2_GPS_ID GPS_MULTI_ID
127 #ifndef INS_EKF2_OF_ID
128 #define INS_EKF2_OF_ID ABI_BROADCAST
133 #ifndef INS_EKF2_FLOW_SENSOR_DELAY
134 #define INS_EKF2_FLOW_SENSOR_DELAY 15
136 PRINT_CONFIG_VAR(INS_FLOW_SENSOR_DELAY)
139 #ifndef INS_EKF2_MIN_FLOW_QUALITY
140 #define INS_EKF2_MIN_FLOW_QUALITY 100
145 #ifndef INS_EKF2_MAX_FLOW_RATE
146 #define INS_EKF2_MAX_FLOW_RATE 200
151 #ifndef INS_EKF2_FLOW_OFFSET_X
152 #define INS_EKF2_FLOW_OFFSET_X 0
157 #ifndef INS_EKF2_FLOW_OFFSET_Y
158 #define INS_EKF2_FLOW_OFFSET_Y 0
163 #ifndef INS_EKF2_FLOW_OFFSET_Z
164 #define INS_EKF2_FLOW_OFFSET_Z 0
169 #ifndef INS_EKF2_FLOW_NOISE
170 #define INS_EKF2_FLOW_NOISE 0.03
175 #ifndef INS_EKF2_FLOW_NOISE_QMIN
176 #define INS_EKF2_FLOW_NOISE_QMIN 0.05
181 #ifndef INS_EKF2_FLOW_INNOV_GATE
182 #define INS_EKF2_FLOW_INNOV_GATE 4
261 #if PERIODIC_TELEMETRY
266 float qfe = 101325.0;
268 pprz_msg_send_INS_REF(trans,
dev, AC_ID,
276 uint16_t gps_check_status, filter_fault_status, soln_status;
278 ekf.get_gps_check_status(&gps_check_status);
279 ekf.get_filter_fault_status(&filter_fault_status);
280 ekf.get_control_mode(&control_mode);
281 ekf.get_ekf_soln_status(&soln_status);
284 float mag, vel, pos, hgt, tas, hagl, flow, beta, mag_decl;
285 uint8_t terrain_valid, dead_reckoning;
286 ekf.get_innovation_test_status(&innov_test_status, &mag, &vel, &pos, &hgt, &tas, &hagl, &beta);
287 ekf.get_flow_innov(&flow);
288 ekf.get_mag_decl_deg(&mag_decl);
290 uint32_t fix_status = (control_mode >> 2) & 1;
292 if (
ekf.get_terrain_valid()) {
298 if (
ekf.inertial_dead_reckoning()) {
304 pprz_msg_send_INS_EKF2(trans,
dev, AC_ID,
305 &fix_status, &filter_fault_status, &gps_check_status, &soln_status,
306 &innov_test_status, &mag, &vel, &pos, &hgt, &tas, &hagl, &flow, &beta,
307 &mag_decl, &terrain_valid, &dead_reckoning);
312 float gps_drift[3], vibe[3];
315 ekf.get_gps_drift_metrics(gps_drift, &gps_blocked);
316 ekf.get_imu_vibe_metrics(vibe);
317 gps_blocked_b = gps_blocked;
319 pprz_msg_send_INS_EKF2_EXT(trans,
dev, AC_ID,
320 &gps_drift[0], &gps_drift[1], &gps_drift[2], &gps_blocked_b,
321 &vibe[0], &vibe[1], &vibe[2]);
329 ekf.get_control_mode(&control_mode);
330 ekf.get_filter_fault_status(&filter_fault_status);
333 if ((control_mode & 0x7) == 0x7) {
335 }
else if ((control_mode & 0x7) == 0x3) {
342 if (filter_fault_status) {
346 pprz_msg_send_STATE_FILTER_STATUS(trans,
dev, AC_ID, &
ahrs_ekf2_id, &mde, &filter_fault_status);
351 float velNE_wind[2], tas;
355 ekf.get_wind_velocity(velNE_wind);
356 ekf.get_true_airspeed(&tas);
358 pprz_msg_send_WIND_INFO_RET(trans,
dev, AC_ID, &flags, &velNE_wind[1], &velNE_wind[0], &f_zero, &tas);
363 float accel_bias[3], gyro_bias[3],
states[24];
364 ekf.get_accel_bias(accel_bias);
365 ekf.get_gyro_bias(gyro_bias);
368 pprz_msg_send_AHRS_BIAS(trans,
dev, AC_ID, &accel_bias[0], &accel_bias[1], &accel_bias[2],
378 ekf_params->mag_fusion_type = MAG_FUSE_TYPE_HEADING;
417 #if PERIODIC_TELEMETRY
447 filter_control_status_u control_status;
448 ekf.get_control_mode(&control_status.value);
451 if (control_status.flags.tilt_align) {
455 ekf.get_position(pos_f);
466 ekf.get_velocity(vel_f);
475 float vel_deriv_f[3] = {};
477 ekf.get_vel_deriv_ned(vel_deriv_f);
478 accel.
x = vel_deriv_f[0];
479 accel.
y = vel_deriv_f[1];
480 accel.
z = vel_deriv_f[2];
487 struct map_projection_reference_s ekf_origin = {};
493 bool ekf_origin_valid =
ekf.get_ekf_origin(&origin_time, &ekf_origin, &ref_alt);
495 lla_ref.
lat = ekf_origin.lat_rad * 180.0 / M_PI * 1e7;
496 lla_ref.
lon = ekf_origin.lon_rad * 180.0 / M_PI * 1e7;
497 lla_ref.
alt = ref_alt * 1000.0;
509 #if defined SITL && USE_NPS
537 imuSample imu_sample;
538 imu_sample.time_us = stamp;
543 ekf.setIMUData(imu_sample);
545 if (
ekf.attitude_valid()) {
548 const Quatf att_q{
ekf.calculate_quaternion()};
549 ltp_to_body_quat.
qi = att_q(0);
550 ltp_to_body_quat.
qx = att_q(1);
551 ltp_to_body_quat.
qy = att_q(2);
552 ltp_to_body_quat.
qz = att_q(3);
558 float delta_q_reset[4];
560 ekf.get_quat_reset(delta_q_reset, &quat_reset_counter);
562 #ifndef NO_RESET_UPDATE_SETPOINT_HEADING
565 float psi = matrix::Eulerf(matrix::Quatf(delta_q_reset)).psi();
566 #if defined STABILIZATION_ATTITUDE_TYPE_INT
583 ekf.get_gyro_bias(gyro_bias);
594 ekf.get_accel_bias(accel_bias);
614 ekf.set_air_density(rho);
619 ekf.setBaroData(stamp, height_amsl_m);
625 ekf.setRangeData(stamp, distance);
699 mag_r[0] = mag_body.
x;
700 mag_r[1] = mag_body.
y;
701 mag_r[2] = mag_body.
z;
703 ekf.setMagData(stamp, mag_r);
716 #if INS_EKF2_GPS_COURSE_YAW
750 int32_t flow_der_x __attribute__((unused)),
751 int32_t flow_der_y __attribute__((unused)),
753 float size_divergence __attribute__((unused)))
#define MAGS_FLOAT_OF_BFP(_ef, _ei)
int32_t lon
in degrees*1e7
static void gps_cb(uint8_t sender_id, uint32_t stamp, struct GpsState *gps_s)
uint8_t valid_fields
bitfield indicating valid fields (GPS_VALID_x_BIT)
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
static float pprz_isa_density_of_pressure(float pressure, float temp)
Get the air density (rho) from a given pressure and temperature.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
vector in North East Down coordinates Units: meters
#define INS_EKF2_GPS_CHECK_MASK
The EKF2 GPS checks before initialization.
static struct nodeState states[UWB_SERIAL_COMM_DIST_NUM_NODES]
void ins_ekf2_change_param(int32_t unk)
int32_t alt
in millimeters above WGS84 reference ellipsoid
unsigned long long uint64_t
void waypoints_localize_all(void)
update local ENU coordinates of global waypoints
static void stateSetSpeedNed_f(struct NedCoor_f *ned_speed)
Set ground speed in local NED coordinates (float).
static void send_ahrs_bias(struct transport_tx *trans, struct link_device *dev)
#define INS_EKF2_FLOW_OFFSET_X
static abi_event optical_flow_ev
definition of the local (flat earth) coordinate system
#define INS_EKF2_MAX_FLOW_RATE
struct EcefCoor_i ecef
Reference point in ecef.
data structure for GPS information
#define RATES_FLOAT_OF_BFP(_rf, _ri)
Event structure to store callbacks in a linked list.
static void body_to_imu_cb(uint8_t sender_id, struct FloatQuat *q_b2i_f)
struct ekf2_parameters_t ekf2_params
uint32_t sacc
speed accuracy in cm/s
static const struct usb_device_descriptor dev
uint32_t vacc
vertical accuracy in cm
static void baro_cb(uint8_t sender_id, uint32_t stamp, float pressure)
#define INS_EKF2_RANGE_MAIN_AGL
If enabled uses radar sensor as primary AGL source, if possible.
int32_t nav_heading
with INT32_ANGLE_FRAC
static void send_ins_ref(struct transport_tx *trans, struct link_device *dev)
static void stateSetAccelBody_i(struct Int32Vect3 *body_accel)
Set acceleration in Body coordinates (int).
static void send_filter_status(struct transport_tx *trans, struct link_device *dev)
#define INS_EKF2_FLOW_SENSOR_DELAY
struct NedCoor_i ned_vel
speed NED in cm/s
static struct FloatRMat * orientationGetRMat_f(struct OrientationReps *orientation)
Get vehicle body attitude rotation matrix (float).
static uint8_t ahrs_ekf2_id
Component ID for EKF.
struct gps_message gps_msg
#define INS_EKF2_FLOW_OFFSET_Y
bool autopilot_in_flight(void)
get in_flight flag
void float_rmat_transp_vmult(struct FloatVect3 *vb, struct FloatRMat *m_b2a, struct FloatVect3 *va)
rotate 3D vector by transposed rotation matrix.
int32_t lat
in degrees*1e7
uint32_t hacc
horizontal accuracy in cm
static void send_ins_ekf2(struct transport_tx *trans, struct link_device *dev)
void ins_ekf2_remove_gps(int32_t mode)
static void orientationSetQuat_f(struct OrientationReps *orientation, struct FloatQuat *quat)
Set vehicle body attitude from quaternion (float).
#define ANGLE_BFP_OF_REAL(_af)
#define INS_EKF2_ACCEL_ID
static void stateSetBodyRates_f(struct FloatRates *body_rate)
Set vehicle body angular rate (float).
Architecture independent timing functions.
#define ACCEL_BFP_OF_REAL(_af)
uint16_t gspeed
norm of 2d ground speed in cm/s
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
static void stateSetLocalOrigin_i(struct LtpDef_i *ltp_def)
Set the local (flat earth) coordinate frame origin (int).
static float pprz_isa_height_of_pressure_full(float pressure, float ref_p)
Get relative altitude from pressure (using full equation).
static void agl_cb(uint8_t sender_id, uint32_t stamp, float distance)
struct OrientationReps body_to_imu
void ltp_def_from_lla_i(struct LtpDef_i *def, struct LlaCoor_i *lla)
#define INS_EKF2_SONAR_MIN_RANGE
Default AGL sensor minimum range.
struct HorizontalGuidanceSetpoint sp
setpoints
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.
uint16_t f
Camera baseline, in meters (i.e. horizontal distance between the two cameras of the stereo setup)
static parameters * ekf_params
The EKF parameters.
static void stateSetAccelNed_f(struct NedCoor_f *ned_accel)
Set acceleration in NED coordinates (float).
#define INS_EKF2_FLOW_OFFSET_Z
int32_t course
GPS course over ground in rad*1e7, [0, 2*Pi]*1e7 (CW/north)
#define INS_EKF2_FLOW_NOISE_QMIN
static void send_wind_info_ret(struct transport_tx *trans, struct link_device *dev)
static abi_event body_to_imu_ev
int int32_t
Typedef defining 32 bit int type.
#define INS_EKF2_FLOW_INNOV_GATE
void sim_overwrite_ins(void)
#define INS_EKF2_MIN_FLOW_QUALITY
#define GPS_VALID_VEL_NED_BIT
vector in Latitude, Longitude and Altitude
static void gyro_cb(uint8_t sender_id, uint32_t stamp, struct Int32Rates *gyro)
#define INS_EKF2_AGL_ID
default AGL sensor to use in INS
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
int32_t hmsl
Height above mean sea level in mm.
void stabilization_attitude_enter(void)
struct ekf2_t ekf2
Local EKF2 status structure.
static void stateSetPositionNed_f(struct NedCoor_f *ned_pos)
Set position from local NED coordinates (float).
void guidance_h_read_rc(bool in_flight)
uint8_t num_sv
number of sat in fix
#define INS_EKF2_FLOW_NOISE
#define INS_EKF2_SONAR_MAX_RANGE
Default AGL sensor maximum range.
int32_t hmsl
height above mean sea level (MSL) in mm
static void mag_cb(uint8_t sender_id, uint32_t stamp, struct Int32Vect3 *mag)
void float_rmat_transp_ratemult(struct FloatRates *rb, struct FloatRMat *m_b2a, struct FloatRates *ra)
rotate anglular rates by transposed rotation matrix.
static Ekf ekf
EKF class itself.
#define AHRS_COMP_ID_EKF2
static void send_ins_ekf2_ext(struct transport_tx *trans, struct link_device *dev)
#define INS_EKF2_VDIST_SENSOR_TYPE
The EKF2 primary vertical distance sensor type.
struct flow_message flow_msg
#define INS_EKF2_FUSION_MODE
For SITL and NPS we need special includes.
struct HorizontalGuidance guidance_h
#define INS_EKF2_BARO_ID
default barometer to use in INS
#define ACCELS_FLOAT_OF_BFP(_ef, _ei)
struct FloatEulers stab_att_sp_euler
with INT32_ANGLE_FRAC
uint8_t quat_reset_counter
static uint8_t mode
mode holds the current sonar mode mode = 0 used at high altitude, uses 16 wave patterns mode = 1 used...
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)
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
#define ABI_BROADCAST
Broadcast address.
struct LlaCoor_i lla
Reference point in lla.
#define DefaultPeriodic
Set default periodic telemetry.
static void stateSetNedToBodyQuat_f(struct FloatQuat *ned_to_body_quat)
Set vehicle body attitude from quaternion (float).
void ins_ekf2_update(void)
Paparazzi atmospheric pressure conversion utilities.
static void accel_cb(uint8_t sender_id, uint32_t stamp, struct Int32Vect3 *accel)
static abi_event accel_ev