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#

Direction Cosine Matrix

IMU Fusion

Vector and Matrix Math

State Definitions#

#define

The IMU is disabled

#define

The IMU is fully configured and ready to take measurements

#define

The IMU is being initialized

#define

The IMU is being calibrated

Functions#

sl_status_t

Initialize and calibrate the IMU chip.

sl_status_t

De-initialize the IMU chip.

uint8_t

Return IMU state.

void

Get a new set of data from the accel and gyro sensor and updates the fusion calculation.

void

Reset the fusion calculation.

void
sl_imu_get_acceleration(int16_t avec[3])

Retrieve the processed acceleration data.

void
sl_imu_get_orientation(int16_t ovec[3])

Retrieve the processed orientation data.

void
sl_imu_get_gyro(int16_t gvec[3])

Retrieve the processed gyroscope data.

sl_status_t

Perform gyroscope calibration to cancel gyro bias.

void

Retrieve the processed gyroscope correction angles.

void
sl_imu_configure(float sampleRate)

Configure the IMU.

bool

Check if new accel/gyro data is available for read.

void

Retrieve the raw acceleration data from the IMU.

void

Retrieve the raw gyroscope data from the IMU.

State Definitions Documentation#

IMU_STATE_DISABLED#

#define IMU_STATE_DISABLED
Value:
0x00

The IMU is disabled


Definition at line 100 of file hardware/driver/imu/inc/sl_imu.h

IMU_STATE_READY#

#define IMU_STATE_READY
Value:
0x01

The IMU is fully configured and ready to take measurements


Definition at line 101 of file hardware/driver/imu/inc/sl_imu.h

IMU_STATE_INITIALIZING#

#define IMU_STATE_INITIALIZING
Value:
0x02

The IMU is being initialized


Definition at line 102 of file hardware/driver/imu/inc/sl_imu.h

IMU_STATE_CALIBRATING#

#define IMU_STATE_CALIBRATING
Value:
0x03

The IMU is being calibrated


Definition at line 103 of file hardware/driver/imu/inc/sl_imu.h

Function Documentation#

sl_imu_init#

sl_status_t sl_imu_init (void )

Initialize and calibrate the IMU chip.

Parameters
N/A

Returns

  • Returns zero on OK, non-zero otherwise


Definition at line 145 of file hardware/driver/imu/inc/sl_imu.h

sl_imu_deinit#

sl_status_t sl_imu_deinit (void )

De-initialize the IMU chip.

Parameters
N/A

Returns

  • Returns zero on OK, non-zero otherwise


Definition at line 154 of file hardware/driver/imu/inc/sl_imu.h

sl_imu_get_state#

uint8_t sl_imu_get_state (void )

Return IMU state.

Parameters
N/A

Returns

  • IMU state


Definition at line 163 of file hardware/driver/imu/inc/sl_imu.h

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.

Parameters
N/A

Definition at line 170 of file hardware/driver/imu/inc/sl_imu.h

sl_imu_reset#

void sl_imu_reset (void )

Reset the fusion calculation.

Parameters
N/A

Definition at line 176 of file hardware/driver/imu/inc/sl_imu.h

sl_imu_get_acceleration#

void sl_imu_get_acceleration (int16_t avec)

Retrieve the processed acceleration data.

Parameters
[out]avec

Three dimensional acceleration vector


Definition at line 185 of file hardware/driver/imu/inc/sl_imu.h

sl_imu_get_orientation#

void sl_imu_get_orientation (int16_t ovec)

Retrieve the processed orientation data.

Parameters
[out]ovec

Three dimensional orientation vector


Definition at line 194 of file hardware/driver/imu/inc/sl_imu.h

sl_imu_get_gyro#

void sl_imu_get_gyro (int16_t gvec)

Retrieve the processed gyroscope data.

Parameters
[out]gvec

Three dimensional gyro vector


Definition at line 203 of file hardware/driver/imu/inc/sl_imu.h

sl_imu_calibrate_gyro#

sl_status_t sl_imu_calibrate_gyro (void )

Perform gyroscope calibration to cancel gyro bias.

Parameters
N/A

Definition at line 212 of file hardware/driver/imu/inc/sl_imu.h

sl_imu_get_gyro_correction_angles#

void sl_imu_get_gyro_correction_angles (float acorr)

Retrieve the processed gyroscope correction angles.

Parameters
[out]acorr

Three dimensional gyro correction angle vector


Definition at line 221 of file hardware/driver/imu/inc/sl_imu.h

sl_imu_configure#

void sl_imu_configure (float sampleRate)

Configure the IMU.

Parameters
[in]sampleRate

The desired sample rate of the acceleration and gyro sensor


Definition at line 425 of file hardware/driver/imu/inc/sl_imu.h

sl_imu_is_data_ready#

bool sl_imu_is_data_ready (void )

Check if new accel/gyro data is available for read.

Parameters
N/A

Returns

  • True if the measurement data is ready, false otherwise


Definition at line 434 of file hardware/driver/imu/inc/sl_imu.h

sl_imu_get_acceleration_raw_data#

void sl_imu_get_acceleration_raw_data (float avec)

Retrieve the raw acceleration data from the IMU.

Parameters
[out]avec

Three dimensional raw acceleration vector


Definition at line 443 of file hardware/driver/imu/inc/sl_imu.h

sl_imu_get_gyro_raw_data#

void sl_imu_get_gyro_raw_data (float gvec)

Retrieve the raw gyroscope data from the IMU.

Parameters
[out]gvec

Three dimensional raw gyro vector


Definition at line 452 of file hardware/driver/imu/inc/sl_imu.h