Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
imu.h File Reference

Inertial Measurement Unit interface. More...

#include "math/pprz_algebra_int.h"
#include "math/pprz_algebra_float.h"
#include "math/pprz_orientation_conversion.h"
#include "filters/low_pass_filter.h"
#include "generated/airframe.h"
Include dependency graph for imu.h:

Go to the source code of this file.

Data Structures

struct  imu_calib_t
struct  imu_rate_est_t
 Measured sample rate of a sensor, counted against the timestamps. More...
struct  imu_gyro_t
struct  imu_accel_t
struct  imu_mag_t
struct  Imu
 abstract IMU interface providing fixed point interface More...

Macros

#define IMU_MAX_SENSORS   4

Functions

void imu_init (void)
 External functions.
void imu_set_defaults_gyro (uint8_t abi_id, const struct Int32RMat *imu_to_sensor, const struct Int32Rates *neutral, const struct FloatRates *scale_f)
 Set the defaults for a gyro sensor WARNING: Should be called before sensor is publishing messages to ensure correct values.
void imu_set_defaults_accel (uint8_t abi_id, const struct Int32RMat *imu_to_sensor, const struct Int32Vect3 *neutral, const struct FloatVect3 *scale_f)
 Set the defaults for a accel sensor WARNING: Should be called before sensor is publishing messages to ensure correct values.
void imu_set_defaults_mag (uint8_t abi_id, const struct Int32RMat *imu_to_sensor, const struct Int32Vect3 *neutral, const struct FloatVect3 *scale_f)
 Set the defaults for a mag sensor WARNING: Should be called before sensor is publishing messages to ensure correct values.
struct imu_gyro_t * imu_get_gyro (uint8_t sender_id, bool create)
 Find or create the gyro in the imu structure.
struct imu_accel_t * imu_get_accel (uint8_t sender_id, bool create)
 Find or create the accel in the imu structure.
struct imu_mag_t * imu_get_mag (uint8_t sender_id, bool create)
 Find or create the mag in the imu structure.
void imu_SetBodyToImuPhi (float phi)
void imu_SetBodyToImuTheta (float theta)
void imu_SetBodyToImuPsi (float psi)
void imu_SetBodyToImuCurrent (bool set)
void imu_ResetBodyToImu (float reset)

Variables

struct Imu imu
 global IMU state

Detailed Description

Inertial Measurement Unit interface.

Definition in file imu.h.


Data Structure Documentation

◆ imu_calib_t

struct imu_calib_t

Definition at line 45 of file imu.h.

Data Fields
bool current: 1 Current calibrated.
bool filter: 1 Enable the lowpass filter (gyro and accel only, ignored for the mag).
bool neutral: 1 Neutral values calibrated.
bool rot_euler: 1 Rotation calibrated with floating point eulers.
bool rotation: 1 Rotation calibrated.
bool scale: 1 Scale calibrated.
bool scale_f: 1 Scale calibrated with floating point.

◆ imu_rate_est_t

struct imu_rate_est_t

Measured sample rate of a sensor, counted against the timestamps.

Definition at line 56 of file imu.h.

Data Fields
float rate Filtered measured sample rate (Hz), 0 until the first window.
bool rejected A window was rejected (out of bounds), only warned once.
uint32_t samples Samples received since the window start.
uint32_t start Timestamp of the current window start (us).
uint16_t windows Accepted windows, up to IMU_RATE_EST_REPORT when the rate is reported.

◆ imu_gyro_t

struct imu_gyro_t

Definition at line 64 of file imu.h.

Collaboration diagram for imu_gyro_t:
Data Fields
uint8_t abi_id ABI sensor ID.
struct Int32RMat body_to_sensor Rotation from body to sensor frame, set as imu to sensor in the airframe calibration and combined with body_to_imu at init.
struct FloatEulers body_to_sensor_f Rotation from imu to sensor frame in eulers (airframe calibration, only used at init).
struct imu_calib_t calibrated Calibration bitmask.
Butterworth2LowPass filter[3] Lowpass filter optional.
float filter_freq Lowpass filter cutoff frequency (Hz).
struct FloatVect3 last_delta_alpha Last integrated sample delta angle in sensor frame for the coning correction (IMU_INTEGRATION).
struct FloatVect3 last_sample Last scaled sample in sensor frame for the integration (IMU_INTEGRATION).
uint32_t last_stamp Last measurement timestamp for integration.
struct Int32Rates neutral Neutral values, compensation on unscaled->scaled.
struct imu_rate_est_t rate_est Measured sample rate for the integration (IMU_INTEGRATION).
float sample_freq Calibrated sample frequency (Hz) for the filter, and reference of the measured integration rate (the driver rate if not set).
struct Int32Rates scale[2] Scaling, first is numerator and second denominator.
struct FloatRates scale_f Scaling.
struct Int32Rates scaled Last scaled values in body frame.
float temperature Temperature in degrees celcius.
struct Int32Rates unscaled Last unscaled values in sensor frame.

◆ imu_accel_t

struct imu_accel_t

Definition at line 84 of file imu.h.

Collaboration diagram for imu_accel_t:
Data Fields
uint8_t abi_id ABI sensor ID.
struct Int32RMat body_to_sensor Rotation from body to sensor frame, set as imu to sensor in the airframe calibration and combined with body_to_imu at init.
struct FloatEulers body_to_sensor_f Rotation from imu to sensor frame in eulers (airframe calibration, only used at init).
struct imu_calib_t calibrated Calibration bitmask.
Butterworth2LowPass filter[3] Lowpass filter optional.
float filter_freq Lowpass filter cutoff frequency (Hz).
struct FloatVect3 last_sample Last scaled sample in sensor frame for the integration (IMU_INTEGRATION).
uint32_t last_stamp Last measurement timestamp for integration.
struct Int32Vect3 neutral Neutral values, compensation on unscaled->scaled.
struct imu_rate_est_t rate_est Measured sample rate for the integration (IMU_INTEGRATION).
float sample_freq Calibrated sample frequency (Hz) for the filter, and reference of the measured integration rate (the driver rate if not set).
struct Int32Vect3 scale[2] Scaling, first is numerator and second denominator.
struct FloatVect3 scale_f Scaling.
struct Int32Vect3 scaled Last scaled values in body frame.
float temperature Temperature in degrees celcius.
struct Int32Vect3 unscaled Last unscaled values in sensor frame.

◆ imu_mag_t

struct imu_mag_t

Definition at line 103 of file imu.h.

Collaboration diagram for imu_mag_t:
Data Fields
uint8_t abi_id ABI sensor ID.
struct Int32RMat body_to_sensor Rotation from body to sensor frame, set as imu to sensor in the airframe calibration and combined with body_to_imu at init.
struct FloatEulers body_to_sensor_f Rotation from imu to sensor frame in eulers (airframe calibration, only used at init).
struct imu_calib_t calibrated Calibration bitmask.
struct FloatVect3 current_scale Current scaling multiplying.
struct Int32Vect3 neutral Neutral values, compensation on unscaled->scaled.
struct Int32Vect3 scale[2] Scaling, first is numerator and second denominator.
struct FloatVect3 scale_f Scaling.
struct Int32Vect3 scaled Last scaled values in body frame.
float strength Earth field strength where it was calibrated (gauss), the scaled values are 1 there; 0 if unknown.
struct Int32Vect3 unscaled Last unscaled values in sensor frame.

◆ Imu

struct Imu

abstract IMU interface providing fixed point interface

Definition at line 119 of file imu.h.

Collaboration diagram for Imu:
Data Fields
uint8_t accel_abi_send_id Filter out and send only a specific ABI id in telemetry for the accelerometer.
struct imu_accel_t accels[IMU_MAX_SENSORS] The accelerometer sensors.
bool b2i_set_current flag for adjusting body_to_imu via settings.

if FALSE, reset to airframe values, if TRUE set current roll/pitch

struct OrientationReps body_to_imu Rotation from body to imu (all sensors) frame.
uint8_t gyro_abi_send_id Filter out and send only a specific ABI id in telemetry for the gyro.
struct imu_gyro_t gyros[IMU_MAX_SENSORS] The gyro sensors.
bool initialized Check if the IMU is initialized.
uint8_t mag_abi_send_id Filter out and send only a specific ABI id in telemetry for the magnetometer.
struct imu_mag_t mags[IMU_MAX_SENSORS] The magnetometer sensors.

Macro Definition Documentation

◆ IMU_MAX_SENSORS

Function Documentation

◆ imu_get_accel()

struct imu_accel_t * imu_get_accel ( uint8_t sender_id,
bool create )
extern

Find or create the accel in the imu structure.

Parameters
sender_idThe ABI sender id to search for
createCreate a new index if not found
Returns
struct imu_accel_t* The accel structure if found/created else NULL

Definition at line 1193 of file imu.c.

References ABI_BROADCAST, ABI_DISABLE, imu_accel_t::abi_id, imu, and IMU_MAX_SENSORS.

Referenced by ahrs_aligner_run(), imu_accel_raw_cb(), imu_quality_assessment_periodic(), and imu_set_defaults_accel().

Here is the caller graph for this function:

◆ imu_get_gyro()

struct imu_gyro_t * imu_get_gyro ( uint8_t sender_id,
bool create )
extern

Find or create the gyro in the imu structure.

Parameters
sender_idThe ABI sender id to search for
createCreate a new index if not found
Returns
struct imu_gyro_t* The gyro structure if found/created else NULL

Definition at line 1170 of file imu.c.

References ABI_BROADCAST, ABI_DISABLE, imu_gyro_t::abi_id, imu, and IMU_MAX_SENSORS.

Referenced by ahrs_aligner_run(), imu_gyro_raw_cb(), imu_set_defaults_gyro(), and send_aligner().

Here is the caller graph for this function:

◆ imu_get_mag()

struct imu_mag_t * imu_get_mag ( uint8_t sender_id,
bool create )
extern

Find or create the mag in the imu structure.

Parameters
sender_idThe ABI sender id to search for
createCreate a new index if not found
Returns
struct imu_mag_t* The mag structure if found/created else NULL

Definition at line 1217 of file imu.c.

References ABI_BROADCAST, ABI_DISABLE, imu_mag_t::abi_id, imu, and IMU_MAX_SENSORS.

Referenced by ahrs_aligner_run(), imu_mag_raw_cb(), imu_set_defaults_mag(), and mag_cb().

Here is the caller graph for this function:

◆ imu_init()

◆ imu_ResetBodyToImu()

void imu_ResetBodyToImu ( float reset)
extern

References reset.

◆ imu_set_defaults_accel()

void imu_set_defaults_accel ( uint8_t abi_id,
const struct Int32RMat * imu_to_sensor,
const struct Int32Vect3 * neutral,
const struct FloatVect3 * scale_f )
extern

Set the defaults for a accel sensor WARNING: Should be called before sensor is publishing messages to ensure correct values.

Parameters
abi_idThe ABI sender id to set the defaults for
imu_to_sensorImu to sensor rotation matrix
neutralNeutral values
scale_fScale values

Definition at line 871 of file imu.c.

References imu_accel_t::abi_id, imu_accel_t::body_to_sensor, imu_accel_t::calibrated, imu, IMU_ACCEL_X_SIGN, IMU_ACCEL_Y_SIGN, IMU_ACCEL_Z_SIGN, imu_get_accel(), int32_rmat_comp(), imu_accel_t::neutral, imu_calib_t::neutral, orientationGetRMat_i(), RMAT_COPY, imu_calib_t::rotation, imu_accel_t::scale_f, imu_calib_t::scale_f, VECT3_ASSIGN, VECT3_COPY, FloatVect3::x, FloatVect3::y, and FloatVect3::z.

Referenced by imu_apogee_init(), imu_aspirin2_init(), imu_aspirin_i2c_init(), imu_aspirin_init(), imu_bebop_init(), imu_bmi088_init(), imu_cube_init(), imu_disco_init(), imu_mpu9250_init(), imu_mpu_hmc_init(), imu_mpu_i2c_init(), imu_mpu_spi_init(), imu_nps_init(), imu_pixhawk6x_init(), imu_px4_init(), imu_px4fmu_init(), invensense2_fix_config(), invensense3_456_set_scalings(), invensense3_fix_config(), and sensors_hitl_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ imu_set_defaults_gyro()

void imu_set_defaults_gyro ( uint8_t abi_id,
const struct Int32RMat * imu_to_sensor,
const struct Int32Rates * neutral,
const struct FloatRates * scale_f )
extern

Set the defaults for a gyro sensor WARNING: Should be called before sensor is publishing messages to ensure correct values.

Parameters
abi_idThe ABI sender id to set the defaults for
imu_to_sensorImu to sensor rotation matrix
neutralNeutral values
scale_fScale values

Definition at line 842 of file imu.c.

References imu_gyro_t::abi_id, imu_gyro_t::body_to_sensor, imu_gyro_t::calibrated, imu, imu_get_gyro(), IMU_GYRO_P_SIGN, IMU_GYRO_Q_SIGN, IMU_GYRO_R_SIGN, int32_rmat_comp(), imu_calib_t::neutral, imu_gyro_t::neutral, orientationGetRMat_i(), FloatRates::p, FloatRates::q, FloatRates::r, RATES_ASSIGN, RATES_COPY, RMAT_COPY, imu_calib_t::rotation, imu_calib_t::scale_f, and imu_gyro_t::scale_f.

Referenced by imu_apogee_init(), imu_aspirin2_init(), imu_aspirin_i2c_init(), imu_aspirin_init(), imu_bebop_init(), imu_bmi088_init(), imu_cube_init(), imu_disco_init(), imu_mpu9250_init(), imu_mpu_hmc_init(), imu_mpu_i2c_init(), imu_mpu_spi_init(), imu_nps_init(), imu_pixhawk6x_init(), imu_px4_init(), imu_px4fmu_init(), invensense2_fix_config(), invensense3_456_set_scalings(), invensense3_fix_config(), and sensors_hitl_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ imu_set_defaults_mag()

void imu_set_defaults_mag ( uint8_t abi_id,
const struct Int32RMat * imu_to_sensor,
const struct Int32Vect3 * neutral,
const struct FloatVect3 * scale_f )
extern

Set the defaults for a mag sensor WARNING: Should be called before sensor is publishing messages to ensure correct values.

Parameters
abi_idThe ABI sender id to set the defaults for
imu_to_sensorImu to sensor rotation matrix
neutralNeutral values
scale_fScale values

Definition at line 900 of file imu.c.

References imu_mag_t::abi_id, imu_mag_t::body_to_sensor, imu_mag_t::calibrated, imu, imu_get_mag(), IMU_MAG_X_SIGN, IMU_MAG_Y_SIGN, IMU_MAG_Z_SIGN, int32_rmat_comp(), imu_calib_t::neutral, imu_mag_t::neutral, orientationGetRMat_i(), RMAT_COPY, imu_calib_t::rotation, imu_calib_t::scale_f, imu_mag_t::scale_f, VECT3_ASSIGN, VECT3_COPY, FloatVect3::x, FloatVect3::y, and FloatVect3::z.

Referenced by imu_nps_init(), mag_ist8310_module_init(), mag_lis3mdl_module_init(), mag_uavcan_init(), and sensors_hitl_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ imu_SetBodyToImuCurrent()

void imu_SetBodyToImuCurrent ( bool set)
extern

◆ imu_SetBodyToImuPhi()

void imu_SetBodyToImuPhi ( float phi)
extern

Definition at line 1268 of file imu.c.

References imu, imu_set_body_to_imu_eulers(), orientationGetEulers_f(), and FloatEulers::phi.

Here is the call graph for this function:

◆ imu_SetBodyToImuPsi()

void imu_SetBodyToImuPsi ( float psi)
extern

Definition at line 1284 of file imu.c.

References imu, imu_set_body_to_imu_eulers(), orientationGetEulers_f(), and FloatEulers::psi.

Here is the call graph for this function:

◆ imu_SetBodyToImuTheta()

void imu_SetBodyToImuTheta ( float theta)
extern

Definition at line 1276 of file imu.c.

References imu, imu_set_body_to_imu_eulers(), orientationGetEulers_f(), and FloatEulers::theta.

Here is the call graph for this function:

Variable Documentation

◆ imu