IMU - Inertial Measurement Unit#
Inertial Measurement Unit driver.
IMU example code#
Basic example for looping measurement of orientation data:
#include "sl_imu.h"
int main( void )
{
...
int16_t o_vec[3];
sl_imu_init();
// Configure sample rate
sl_imu_configure(10);
// Recalibrate gyro
sl_imu_calibrate_gyro();
while (true) {
sl_imu_update();
while (!sl_imu_is_data_ready()) {
// wait
}
sl_imu_get_orientation(o_vec);
...
}
} Modules#
IMU Fusion Data Types#
Sensor fusion state shared by the IMU fusion routines.
Structure to store the sensor fusion data.
Vector and Matrix Math#
Inertial measurement unit fusion driver math routines.
Normalize the angle ( -PI < angle <= PI )
Multiply two 3x3 matrices.
Normalize the angle of a vector.
Set all elements of a vector to 0.
Scale a vector by a factor.
Multiply a vector by a scalar.
Add two vectors.
Subtract vector b from vector a.
Calculate the dot product of two vectors.
Calculate the cross product of two vectors.
Direction Cosine Matrix#
Unit DCM matrix related routines.
Set the elements of the DCM matrix to the corresponding elements of the identity matrix.
DCM reset, Z direction.
Normalize the DCM matrix.
Rotate the DCM matrix by a given angle.
Calculate the Euler angles (roll, pitch, yaw) from the DCM matrix.
IMU Fusion Functions#
Sensor fusion configuration and update routines.
Set the accelerometer sample rate in the sl_imu_sensor_fusion_t structure.
Add the current accelerometer data to the accumulator.
Set the gyro sample rate and related values in the sl_imu_sensor_fusion_t structure.
Update the fusion calculation with a new gyro data.
Clear the gyro correction vector.
Calculate the gyro correction vector.
Initialize a new sl_imu_sensor_fusion_t structure.
Clear the values of the sensor fusion object.
Update the fusion calculation.
State Definitions#
The IMU is disabled
The IMU is fully configured and ready to take measurements
The IMU is being initialized
The IMU is being calibrated
Functions#
Initialize and calibrate the IMU chip.
De-initialize the IMU chip.
Return IMU state.
Get a new set of data from the accel and gyro sensor and updates the fusion calculation.
Reset the fusion calculation.
Retrieve the processed acceleration data.
Retrieve the processed orientation data.
Retrieve the processed gyroscope data.
Perform gyroscope calibration to cancel gyro bias.
Retrieve the processed gyroscope correction angles.
Configure the IMU.
Check if new accel/gyro data is available for read.
Retrieve the raw acceleration data from the IMU.
Retrieve the raw gyroscope data from the IMU.
IMU Fusion Data Types Documentation#
sl_imu_sensor_fusion_t#
typedef struct sl_imu_sensor_fusion sl_imu_sensor_fusion_t
Structure to store the sensor fusion data.
Vector and Matrix Math Documentation#
sl_imu_normalize_angle#
void sl_imu_normalize_angle (float * a)
Normalize the angle ( -PI < angle <= PI )
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| float * | N/A | a | The angle to be normalized |
sl_imu_matrix_multiply#
void sl_imu_matrix_multiply (float c, float a, float b)
Multiply two 3x3 matrices.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| float | [out] | c | The multiplication result, AB |
| float | [in] | a | Input vector A |
| float | [in] | b | Input vector B |
sl_imu_vector_normalize_angle#
void sl_imu_vector_normalize_angle (float v)
Normalize the angle of a vector.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| float | N/A | v | The vector, which contains angles to be normalized |
sl_imu_vector_zero#
void sl_imu_vector_zero (float v)
Set all elements of a vector to 0.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| float | N/A | v | The vector to be cleared |
sl_imu_vector_scale#
void sl_imu_vector_scale (float v, float scale)
Scale a vector by a factor.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| float | N/A | v | The vector to be scaled |
| float | [in] | scale | The scale factor |
sl_imu_vector_scalar_multiplication#
void sl_imu_vector_scalar_multiplication (float r, float v, float scale)
Multiply a vector by a scalar.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| float | [out] | r | The multiplied vector |
| float | [in] | v | The vector to be multiplied |
| float | [in] | scale | The scalar multiplicator value |
sl_imu_vector_add#
void sl_imu_vector_add (float r, float a, float b)
Add two vectors.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| float | [out] | r | The vectorial sum of the vectors, a+b |
| float | [in] | a | The first vector |
| float | [in] | b | The second vector |
sl_imu_vector_subtract#
void sl_imu_vector_subtract (float r, float a, float b)
Subtract vector b from vector a.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| float | [out] | r | The vectorial difference, a-b |
| float | [in] | a | Vector a |
| float | [in] | b | Vector b |
sl_imu_vector_dot_product#
float sl_imu_vector_dot_product (float a, float b)
Calculate the dot product of two vectors.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| float | [in] | a | The first vector |
| float | [in] | b | The second vector |
Returns
The dot product
sl_imu_vector_cross_product#
void sl_imu_vector_cross_product (float r, float a, float b)
Calculate the cross product of two vectors.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| float | [out] | r | The cross product |
| float | [in] | a | The first vector |
| float | [in] | b | The second vector |
Direction Cosine Matrix Documentation#
sl_imu_dcm_reset#
void sl_imu_dcm_reset (float dcm)
Set the elements of the DCM matrix to the corresponding elements of the identity matrix.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| float | N/A | dcm | DCM matrix |
sl_imu_dcm_reset_z#
void sl_imu_dcm_reset_z (float dcm)
DCM reset, Z direction.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| float | N/A | dcm | DCM matrix |
sl_imu_dcm_normalize#
void sl_imu_dcm_normalize (float dcm)
Normalize the DCM matrix.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| float | N/A | dcm | DCM matrix |
sl_imu_dcm_rotate#
void sl_imu_dcm_rotate (float dcm, float ang)
Rotate the DCM matrix by a given angle.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| float | [inout] | dcm | DCM matrix |
| float | [in] | ang | Rotation angle |
sl_imu_dcm_get_angles#
void sl_imu_dcm_get_angles (float dcm, float ang)
Calculate the Euler angles (roll, pitch, yaw) from the DCM matrix.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| float | [in] | dcm | DCM matrix |
| float | [out] | ang | An array containing the Euler angles |
IMU Fusion Functions Documentation#
sl_imu_fuse_accelerometer_set_sample_rate#
void sl_imu_fuse_accelerometer_set_sample_rate (sl_imu_sensor_fusion_t * f, float rate)
Set the accelerometer sample rate in the sl_imu_sensor_fusion_t structure.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| sl_imu_sensor_fusion_t * | [inout] | f | Pointer to the sl_imu_sensor_fusion_t object |
| float | [in] | rate | Sample rate of the accelerometer |
sl_imu_fuse_accelerometer_update_filter#
void sl_imu_fuse_accelerometer_update_filter (sl_imu_sensor_fusion_t * f, float avec)
Add the current accelerometer data to the accumulator.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| sl_imu_sensor_fusion_t * | [inout] | f | Pointer to the sl_imu_sensor_fusion_t object |
| float | [in] | avec | Accelerometer vector |
sl_imu_fuse_gyro_set_sample_rate#
void sl_imu_fuse_gyro_set_sample_rate (sl_imu_sensor_fusion_t * f, float rate)
Set the gyro sample rate and related values in the sl_imu_sensor_fusion_t structure.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| sl_imu_sensor_fusion_t * | [inout] | f | Pointer to the sl_imu_sensor_fusion_t object |
| float | [in] | rate | Sample rate of the gyroscope |
sl_imu_fuse_gyro_update#
void sl_imu_fuse_gyro_update (sl_imu_sensor_fusion_t * f, float gvec)
Update the fusion calculation with a new gyro data.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| sl_imu_sensor_fusion_t * | [inout] | f | Pointer to the sl_imu_sensor_fusion_t object |
| float | [in] | gvec | Gyroscope vector |
sl_imu_fuse_gyro_clear_correction_vector#
void sl_imu_fuse_gyro_clear_correction_vector (sl_imu_sensor_fusion_t * f)
Clear the gyro correction vector.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| sl_imu_sensor_fusion_t * | [inout] | f | Pointer to the sl_imu_sensor_fusion_t object |
sl_imu_fuse_gyro_calculate_correction_vector#
void sl_imu_fuse_gyro_calculate_correction_vector (sl_imu_sensor_fusion_t * f, bool accValid, bool dirValid, float dirZ)
Calculate the gyro correction vector.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| sl_imu_sensor_fusion_t * | [inout] | f | Pointer to the sl_imu_sensor_fusion_t object |
| bool | [in] | accValid | True if the acceleration value is within limits |
| bool | [in] | dirValid | True if the direction value is valid |
| float | [in] | dirZ | The direction of the Z axis |
sl_imu_fuse_new#
void sl_imu_fuse_new (sl_imu_sensor_fusion_t * f)
Initialize a new sl_imu_sensor_fusion_t structure.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| sl_imu_sensor_fusion_t * | [inout] | f | Pointer to the sl_imu_sensor_fusion_t object to be initialized |
sl_imu_fuse_reset#
void sl_imu_fuse_reset (sl_imu_sensor_fusion_t * f)
Clear the values of the sensor fusion object.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| sl_imu_sensor_fusion_t * | [inout] | f | Pointer to the sl_imu_sensor_fusion_t object |
sl_imu_fuse_update#
void sl_imu_fuse_update (sl_imu_sensor_fusion_t * f)
Update the fusion calculation.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| sl_imu_sensor_fusion_t * | [inout] | f | Pointer to the sl_imu_sensor_fusion_t object |
State Definitions Documentation#
IMU_STATE_READY#
#define IMU_STATE_READYValue:
0x01
The IMU is fully configured and ready to take measurements
Function Documentation#
sl_imu_init#
sl_status_t sl_imu_init (sl_ssi_handle_t ssi_driver_handle)
Initialize and calibrate the IMU chip.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| sl_ssi_handle_t | N/A | ssi_driver_handle |
Returns
Returns zero on OK, non-zero otherwise
sl_imu_deinit#
sl_status_t sl_imu_deinit (void )
De-initialize the IMU chip.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
Returns
Returns zero on OK, non-zero otherwise
sl_imu_get_state#
uint8_t sl_imu_get_state (void )
Return IMU state.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
Returns
IMU state
sl_imu_update#
void sl_imu_update (void )
Get a new set of data from the accel and gyro sensor and updates the fusion calculation.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
sl_imu_reset#
void sl_imu_reset (void )
Reset the fusion calculation.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
sl_imu_get_acceleration#
void sl_imu_get_acceleration (int16_t avec)
Retrieve the processed acceleration data.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| int16_t | [out] | avec | Three dimensional acceleration vector |
sl_imu_get_orientation#
void sl_imu_get_orientation (int16_t ovec)
Retrieve the processed orientation data.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| int16_t | [out] | ovec | Three dimensional orientation vector |
sl_imu_get_gyro#
void sl_imu_get_gyro (int16_t gvec)
Retrieve the processed gyroscope data.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| int16_t | [out] | gvec | Three dimensional gyro vector |
sl_imu_calibrate_gyro#
sl_status_t sl_imu_calibrate_gyro (sl_ssi_handle_t ssi_driver_handle)
Perform gyroscope calibration to cancel gyro bias.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| sl_ssi_handle_t | N/A | ssi_driver_handle |
sl_imu_get_gyro_correction_angles#
void sl_imu_get_gyro_correction_angles (float acorr)
Retrieve the processed gyroscope correction angles.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| float | [out] | acorr | Three dimensional gyro correction angle vector |
sl_imu_configure#
void sl_imu_configure (float sampleRate, sl_ssi_handle_t ssi_driver_handle)
Configure the IMU.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| float | [in] | sampleRate | The desired sample rate of the acceleration and gyro sensor |
| sl_ssi_handle_t | N/A | ssi_driver_handle |
sl_imu_is_data_ready#
bool sl_imu_is_data_ready (sl_ssi_handle_t ssi_driver_handle)
Check if new accel/gyro data is available for read.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| sl_ssi_handle_t | N/A | ssi_driver_handle |
Returns
True if the measurement data is ready, false otherwise
sl_imu_get_acceleration_raw_data#
void sl_imu_get_acceleration_raw_data (float avec)
Retrieve the raw acceleration data from the IMU.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| float | [out] | avec | Three dimensional raw acceleration vector |
sl_imu_get_gyro_raw_data#
void sl_imu_get_gyro_raw_data (float gvec)
Retrieve the raw gyroscope data from the IMU.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| float | [out] | gvec | Three dimensional raw gyro vector |