36 #include "generated/airframe.h"
48 #if defined SITL && USE_NPS
50 #include "nps_autopilot.h"
57 #include "generated/flight_plan.h"
62 #error USE_SONAR needs USE_VFF_EXTENDED
67 #define INS_SONAR_ID ABI_BROADCAST
72 #ifdef INS_SONAR_THROTTLE_THRESHOLD
76 #ifndef INS_SONAR_OFFSET
77 #define INS_SONAR_OFFSET 0.
79 #ifndef INS_SONAR_MIN_RANGE
80 #define INS_SONAR_MIN_RANGE 0.001
82 #ifndef INS_SONAR_MAX_RANGE
83 #define INS_SONAR_MAX_RANGE 4.0
85 #define VFF_R_SONAR_0 0.1
86 #ifndef VFF_R_SONAR_OF_M
87 #define VFF_R_SONAR_OF_M 0.2
90 #ifndef INS_SONAR_UPDATE_ON_AGL
91 #define INS_SONAR_UPDATE_ON_AGL FALSE
98 #define INS_VFF_R_GPS 2.0
102 #ifndef INS_MAX_PROPAGATION_STEPS
103 #define INS_MAX_PROPAGATION_STEPS 200
106 #ifndef USE_INS_NAV_INIT
107 #define USE_INS_NAV_INIT TRUE
112 #warning INS_BARO_SENS is obsolete, please remove it from your airframe file.
118 #define INS_BARO_ID BARO_BOARD_SENDER_ID
120 #define INS_BARO_ID ABI_BROADCAST
130 #ifndef INS_INT_IMU_ID
131 #define INS_INT_IMU_ID ABI_BROADCAST
140 #ifndef INS_INT_VEL_ID
141 #define INS_INT_VEL_ID ABI_BROADCAST
148 #if PERIODIC_TELEMETRY
153 pprz_msg_send_INS(trans, dev, AC_ID,
161 pprz_msg_send_INS_Z(trans, dev, AC_ID,
168 pprz_msg_send_INS_REF(trans, dev, AC_ID,
180 static void ins_update_from_hff(
void);
202 ins_int.update_on_agl = INS_SONAR_UPDATE_ON_AGL;
204 AbiBindMsgAGL(INS_SONAR_ID, &sonar_ev,
sonar_cb);
220 #if PERIODIC_TELEMETRY
294 ins_update_from_hff();
352 #ifdef INS_BODY_TO_GPS_X
355 .
x = INS_BODY_TO_GPS_X,
356 .y = INS_BODY_TO_GPS_Y,
357 .z = INS_BODY_TO_GPS_Z
380 VECT2_SDIV(gps_pos_m_ned, gps_pos_m_ned, 100.0f);
383 VECT2_ASSIGN(gps_speed_m_s_ned, gps_speed_cm_s_ned.
x, gps_speed_cm_s_ned.
y);
384 VECT2_SDIV(gps_speed_m_s_ned, gps_speed_m_s_ned, 100.);
394 ins_update_from_hff();
415 static void sonar_cb(
uint8_t __attribute__((unused)) sender_id,
float distance)
417 static float last_offset = 0.;
420 if (distance < INS_SONAR_MAX_RANGE && distance > INS_SONAR_MIN_RANGE
421 #ifdef INS_SONAR_THROTTLE_THRESHOLD
424 #ifdef INS_SONAR_BARO_THRESHOLD
429 vff_update_z_conf(-(distance), VFF_R_SONAR_0 + VFF_R_SONAR_OF_M * fabsf(distance));
447 llh_nav0.
lat = NAV_LAT0;
448 llh_nav0.
lon = NAV_LON0;
450 llh_nav0.
alt = NAV_ALT0 + NAV_MSL0;
468 #if defined SITL && USE_NPS
469 if (nps_bypass_ins) {
485 static void ins_update_from_hff(
void)
504 if (last_stamp > 0) {
505 float dt = (float)(stamp - last_stamp) * 1e-6;
512 uint32_t stamp __attribute__((unused)),
519 uint32_t stamp __attribute__((unused)),
520 float x,
float y,
float z,
521 float noise __attribute__((unused)))
537 ins_update_from_hff();
static void stateSetPositionNed_i(struct NedCoor_i *ned_pos)
Set position from local NED coordinates (int).
Event structure to store callbacks in a linked list.
#define VECT3_SUB(_a, _b)
static struct Int32RMat * orientationGetRMat_i(struct OrientationReps *orientation)
Get vehicle body attitude rotation matrix (int).
void vff_update_z_conf(float z_meas, float conf)
Generic transmission transport header.
Interface for extended vertical filter (in float).
Horizontal filter (x,y) to estimate position and velocity.
void b2_hff_realign(struct FloatVect2 pos, struct FloatVect2 vel)
Periodic telemetry system header (includes downlink utility and generated code).
static struct Int32RMat * stateGetNedToBodyRMat_i(void)
Get vehicle body attitude rotation matrix (int).
static abi_event vel_est_ev
vector in EarthCenteredEarthFixed coordinates
struct InsInt ins_int
global INS state
static void vel_est_cb(uint8_t sender_id, uint32_t stamp, float x, float y, float z, float noise)
#define POS_BFP_OF_REAL(_af)
#define QUAT_INVERT(_qo, _qi)
#define INS_BARO_ID
default barometer to use in INS
static void ins_update_from_vff(void)
update ins state from vertical filter
#define INT32_VECT3_ZERO(_v)
Main include for ABI (AirBorneInterface).
static void gps_cb(uint8_t sender_id, uint32_t stamp, struct GpsState *gps_s)
void ins_reset_local_origin(void)
INS local origin reset.
void ins_int_register(void)
#define VECT2_ASSIGN(_a, _x, _y)
bool_t vf_reset
request to reset vertical filter.
float z
z-position estimate in m (NED, z-down)
#define INT32_SPEED_OF_CM_S_DEN
vector in Latitude, Longitude and Altitude
static void stateSetSpeedNed_i(struct NedCoor_i *ned_speed)
Set ground speed in local NED coordinates (int).
#define GPS_FIX_3D
3D GPS fix
void ltp_def_from_lla_i(struct LtpDef_i *def, struct LlaCoor_i *lla)
static struct Int32Quat * stateGetNedToBodyQuat_i(void)
Get vehicle body attitude quaternion (int).
void ned_of_ecef_vect_i(struct NedCoor_i *ned, struct LtpDef_i *def, struct EcefCoor_i *ecef)
Rotate a vector from ECEF to NED.
struct EcefCoor_i ecef
Reference point in ecef.
int32_t hmsl
Height above mean sea level in mm.
void ins_int_update_gps(struct GpsState *gps_s)
static void sonar_cb(uint8_t sender_id, float distance)
static struct FloatQuat * stateGetNedToBodyQuat_f(void)
Get vehicle body attitude quaternion (float).
int32_t alt
in millimeters above WGS84 reference ellipsoid
Vertical filter (in float) estimating altitude, velocity and accel bias.
static void stateSetAccelNed_i(struct NedCoor_i *ned_accel)
Set acceleration in NED coordinates (int).
#define INT32_VECT2_SCALE_2(_a, _b, _num, _den)
bool_t hf_realign
request to realign horizontal filter.
int32_t hmsl
height above mean sea level in mm
data structure for GPS information
#define INT32_POS_OF_CM_NUM
static void stateSetLocalOrigin_i(struct LtpDef_i *ltp_def)
Set the local (flat earth) coordinate frame origin (int).
Device independent GPS code (interface)
Paparazzi atmospheric pressure conversion utilities.
#define ACCEL_FLOAT_OF_BFP(_ai)
struct Imu imu
global IMU state
struct EcefCoor_i ecef_pos
position in ECEF in cm
float offset
baro offset estimate
#define INS_INT_IMU_ID
ABI binding for IMU data.
void vff_update_offset(float offset)
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
static void ins_ned_to_state(void)
copy position and speed to state interface
struct LlaCoor_i lla
Reference point in lla.
#define DefaultPeriodic
Set default periodic telemetry.
int32_t lon
in degrees*1e7
#define INS_MAX_PROPAGATION_STEPS
maximum number of propagation steps without any updates in between
void float_quat_vmult(struct FloatVect3 *v_out, struct FloatQuat *q, const struct FloatVect3 *v_in)
rotate 3D vector by quaternion.
void b2_hff_init(float init_x, float init_xdot, float init_y, float init_ydot)
static void accel_cb(uint8_t sender_id, uint32_t stamp, struct Int32Vect3 *accel)
Paparazzi fixed point math for geodetic calculations.
void int32_quat_vmult(struct Int32Vect3 *v_out, struct Int32Quat *q, struct Int32Vect3 *v_in)
rotate 3D vector by quaternion.
float zdotdot
z-acceleration in m/s^2 (NED, z-down)
Inertial Measurement Unit interface.
void vff_propagate(float accel, float dt)
Propagate the filter in time.
struct HfilterFloat b2_hff_state
struct OrientationReps body_to_imu
rotation from body to imu frame
struct NedCoor_i ltp_accel
float baro_z
z-position calculated from baro in meters (z-down)
static const struct usb_device_descriptor dev
struct LtpDef_i ned_origin_i
Definition of the local (flat earth) coordinate system.
#define VECT2_SDIV(_vo, _vi, _s)
uint32_t propagation_cnt
number of propagation steps since the last measurement update
void vff_realign(float z_meas)
Ins implementation state (fixed point)
#define INT32_POS_OF_CM_DEN
float zdot
z-velocity estimate in m/s (NED, z-down)
void ned_of_ecef_point_i(struct NedCoor_i *ned, struct LtpDef_i *def, struct EcefCoor_i *ecef)
Convert a point from ECEF to local NED.
vector in North East Down coordinates
#define INS_INT_VEL_ID
ABI binding for VELOCITY_ESTIMATE.
static abi_event accel_ev
#define INT32_SPEED_OF_CM_S_NUM
void b2_hff_propagate(void)
General stabilization interface for rotorcrafts.
int32_t stabilization_cmd[COMMANDS_NB]
Stabilization commands.
void b2_hff_update_gps(struct FloatVect2 *pos_ned, struct FloatVect2 *speed_ned)
void int32_rmat_transp_vmult(struct Int32Vect3 *vb, struct Int32RMat *m_b2a, struct Int32Vect3 *va)
rotate 3D vector by transposed rotation matrix.
void vff_update(float z_meas)
static void baro_cb(uint8_t sender_id, float pressure)
#define ABI_BROADCAST
Broadcast address.
void vff_update_baro(float z_meas)
void ecef_of_lla_i(struct EcefCoor_i *out, struct LlaCoor_i *in)
struct EcefCoor_i ecef_vel
speed ECEF in cm/s
#define SPEED_BFP_OF_REAL(_af)
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
static float pprz_isa_height_of_pressure(float pressure, float ref_p)
Get relative altitude from pressure (using simplified equation).
#define ACCEL_BFP_OF_REAL(_af)
static void ins_init_origin_from_flightplan(void)
initialize the local origin (ltp_def) from flight plan position
int32_t lat
in degrees*1e7
void ins_register_impl(InsInit init)
struct GpsState gps
global GPS state
void ins_int_propagate(struct Int32Vect3 *accel, float dt)
struct NedCoor_i ltp_speed
void ltp_def_from_ecef_i(struct LtpDef_i *def, struct EcefCoor_i *ecef)
void b2_hff_update_vel(struct FloatVect2 vel, struct FloatVect2 Rvel)
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
void ins_reset_altitude_ref(void)
INS altitude reference reset.
INS for rotorcrafts combining vertical and horizontal filters.