pdf-icon

IMU Class

begin

Syntax:

bool begin(I2C_Class* i2c = nullptr, board_t board = board_t::board_unknown);

Description:

  • Initialize the IMU and specify the I2C interface and board type for initialization.

Parameters:

  • I2C_Class* i2c
    • The I2C interface used.
  • board_t board
    • M5Stack board type.

Return:

  • bool:
    • true: Initialization successful.
    • false: Initialization failed.

init

Syntax:

bool init(I2C_Class* i2c = nullptr) { return begin(i2c); }

Description:

  • Initialize the IMU and specify the I2C interface for initialization.

Parameters:

  • I2C_Class* i2c
    • The I2C interface used.

Return:

  • bool:
    • true: Initialization successful.
    • false: Initialization failed.

sleep

Syntax:

bool sleep(void);

Description:

  • Put the IMU into sleep mode.

Parameters:

  • null

Return:

  • bool:
    • true: Successfully entered sleep mode.
    • false: Failed to enter sleep mode.

setClock

Syntax:

void setClock(std::uint32_t freq);

Description:

  • Set the internal IMU clock frequency.

Parameters:

  • uint32_t freq:
    • Clock frequency.

Return:

  • null

update

Syntax:

sensor_mask_t update(void);

Description:

  • Get IMU data update.

Parameters:

  • null

Return:

  • sensor_mask_t:
    • Sensor data acquisition mask values:
      • sensor_mask_none: 0000
      • sensor_mask_accel: 0001
      • sensor_mask_gyro: 0010
      • sensor_mask_mag: 0100
enum sensor_index_t
{
  sensor_index_accel = 0,
  sensor_index_gyro  = 1,
  sensor_index_mag   = 2,
};

enum sensor_mask_t
{
  sensor_mask_none = 0,
  sensor_mask_accel = 1 << sensor_index_accel,
  sensor_mask_gyro  = 1 << sensor_index_gyro,
  sensor_mask_mag   = 1 << sensor_index_mag,
};

getImuData

Syntax:

void getImuData(imu_data_t* imu_data);
const imu_data_t& getImuData(void) { getImuData(&_last_data); return _last_data; }

Description:

  • Get the current IMU data.

Parameters:

  • null

Return:

  • imu_data_t data:
    • data.accel.x: accel x-axis value.
    • data.accel.y: accel y-axis value.
    • data.accel.z: accel z-axis value.
    • data.accel.value: accel 3values array [0]=x / [1]=y / [2]=z.
    • data.gyro.x: gyro x-axis value.
    • data.gyro.y: gyro y-axis value.
    • data.gyro.z: gyro z-axis value.
    • data.gyro.value: gyro 3values array [0]=x / [1]=y / [2]=z.
    • data.mag.x: mag x-axis value.
    • data.mag.y: mag y-axis value.
    • data.mag.z: mag z-axis value.
    • data.mag.value: mag 3values array [0]=x / [1]=y / [2]=z.
    • data.value: all sensor 9values array [0-2]=accel / [3-5]=gyro / [6-8]=mag

setAxisOrder

Syntax:

bool setAxisOrder(axis_t axis0, axis_t axis1, axis_t axis2);

Description:

  • Specify the axis order. Default is X+, Y+, Z+.

Parameters:

  • axis_t axis0, axis_t axis1, axis_t axis2
enum axis_t
{
  axis_x_pos = 0,
  axis_x_neg = 1,
  axis_y_pos = 2,
  axis_y_neg = 3,
  axis_z_pos = 4,
  axis_z_neg = 5,
};

Return:

  • bool:
    • true: Axis order set successfully.
    • false: Axis order set failed.

setAxisOrderRightHanded

Syntax:

bool setAxisOrderRightHanded(axis_t axis0, axis_t axis1);

Description:

  • Specify the axis order for a right-handed coordinate system. Default is X+, Y+, Z+.

Parameters:

  • axis_t axis0, axis_t axis1

Return:

  • bool:
    • true: Axis order set successfully.
    • false: Axis order set failed.

setAxisOrderLeftHanded

Syntax:

bool setAxisOrderLeftHanded(axis_t axis0, axis_t axis1);

getAccel

Syntax:

bool getAccel(float* ax, float* ay, float* az);

Description:

  • Read the three-axis acceleration.

Parameters:

  • float* ax, float* ay, float* az

Return:

  • bool:
    • true: Read successful.
    • false: Read failed.

getGyro

Syntax:

bool getGyro(float* gx, float* gy, float* gz);

Description:

  • Read the three-axis angular velocity.

Parameters:

  • float* gx, float* gy, float* gz

Return:

  • bool:
    • true: Read successful.
    • false: Read failed.

getMag

Syntax:

bool getMag(float* mx, float* my, float* mz);

Description:

  • Read the three-axis magnetic field strength.

Parameters:

  • float* mx, float* my, float* mz

Return:

  • bool:
    • true: Read successful.
    • false: Read failed.

getTemp

Syntax:

bool getTemp(float *t);

Description:

  • Read the temperature measurement data.

Parameters:

  • float *t

Return:

  • bool:
    • true: Read successful.
    • false: Read failed.

isEnabled

Syntax:

bool isEnabled(void) const { return _imu != imu_none; }

Description:

  • Check if the IMU is initialized.

Parameters:

  • null

Return:

  • bool:
    • true: IMU is initialized.
    • false: IMU is not initialized.

getType

Syntax:

imu_t getType(void) const { return _imu; }

Description:

  • Get the IMU type.

Parameters:

  • null

Return:

  • imu_t:
    • The type of IMU chip.
enum imu_t
{ imu_none,
  imu_unknown,
  imu_sh200q,
  imu_mpu6050,
  imu_mpu6886,
  imu_mpu9250,
  imu_bmi270,
};

setINTPinActiveLogic

Syntax:

bool setINTPinActiveLogic(bool level);

Description:

  • Set the active logic level of the interrupt pin.

Parameters:

  • bool level: The active logic level.

Return:

  • bool:
    • true: Setting successful.
    • false: Setting failed.

setCalibration

Syntax:

void setCalibration(uint8_t accel_strength, uint8_t gyro_strength, uint8_t mag_strength);

Description:

  • Specify the strength of the automatic offset adjustment function for each sensor. 0=no auto calibration, 1~255=auto calibration with actual calibration operation performed during each M5.Imu.update.

Parameters:

  • uint8_t accel_strength
  • uint8_t gyro_strength
  • uint8_t mag_strength

Return:

  • null

saveOffsetToNVS

Syntax:

bool saveOffsetToNVS(void);

Description:

  • Save the IMU offset values to NVS.

Parameters:

  • null

Return:

  • bool:
    • true: Save successful.
    • false: Save failed.

loadOffsetFromNVS

Syntax:

bool loadOffsetFromNVS(void);

Description:

  • Load the IMU offset values from NVS.

Parameters:

  • null

Return:

  • bool:
    • true: Load successful.
    • false: Load failed.

clearOffsetData

Syntax:

void clearOffsetData(void);

Description:

  • Clear the IMU offset values in NVS.

Parameters:

  • null

Return:

  • bool:
    • true: Clear successful.
    • false: Clear failed.

setOffsetData

Syntax:

void setOffsetData(size_t index, int32_t value);

Description:

  • Set the IMU offset values.

Parameters:

  • size_t index:
    • The index of the axis to set.
  • int32_t value
    • The offset value.

Return:

  • null

getOffsetData

Syntax:

int32_t getOffsetData(size_t index);

Description:

  • Get the IMU offset values.

Parameters:

  • size_t index:
    • The index of the axis to read.

Return:

  • int32_t: The offset value.

getRawData

Syntax:

int16_t getRawData(size_t index);

Description:

  • Get the IMU Raw data.

Parameters:

  • size_t index:
    • The index of the axis to read.

Return:

  • int16_t: The IMU Raw data.

getImuInstancePtr

Syntax:

IMU_Base* getImuInstancePtr(int idx) const { return _imu_instance[idx].get(); }

Description:

  • Get the IMU instance pointer.

Parameters:

  • int idx:
    • The instance index.

Return:

  • IMU_Base:
    • The IMU instance pointer.
On This Page