惯性传感器 (IMU)

[English]

惯性传感器包含陀螺仪传感器、加速度传感器和兼具多种功能的传感器等。主要用于测量物体的加速度、角速度等,进而解算出物体的运动姿态。

已适配列表

名称

功能

总线

供应商

规格书

硬件抽象层

LIS2DH12

3-axis acceler

I2C

ST

规格书

MPU6050

3-axis acceler + 3-axis gyro

I2C

InvenSense

规格书

API 参考

以下 API 实现了对惯性传感器的硬件抽象,用户可直接调用该层代码编写传感器应用程序,也可以使用 sensor_hub 中的传感器接口实现更简单的调用。

Header File

Functions

sensor_imu_handle_t imu_create(bus_handle_t bus, int imu_id)

Create a Inertial Measurement Unit sensor instance. Same series’ sensor or sensor with same address can only be created once.

参数
  • bus – i2c bus handle the sensor attached to

  • imu_id – id declared in imu_id_t

返回

sensor_imu_handle_t return imu sensor handle if succeed, NULL is failed.

esp_err_t imu_delete(sensor_imu_handle_t *sensor)

Delete and release the sensor resource.

参数

sensor – point to imu sensor handle, will set to NULL if delete succeed.

返回

esp_err_t

  • ESP_OK Success

  • ESP_FAIL Fail

esp_err_t imu_test(sensor_imu_handle_t sensor)

Test if sensor is active.

参数

sensor – imu sensor handle to operate

返回

esp_err_t

  • ESP_OK Success

  • ESP_FAIL Fail

esp_err_t imu_acquire_acce(sensor_imu_handle_t sensor, axis3_t *acce)

Acquire imu sensor accelerometer result one time.

参数
  • sensor – imu sensor handle to operate

  • acce – result data (unit:g)

返回

esp_err_t

  • ESP_OK Success

  • ESP_FAIL Fail

  • ESP_ERR_NOT_SUPPORTED Function not supported on this sensor

esp_err_t imu_acquire_gyro(sensor_imu_handle_t sensor, axis3_t *gyro)

Acquire imu sensor gyroscope result one time.

参数
  • sensor – imu sensor handle to operate

  • gyro – result data (unit:dps)

返回

esp_err_t

  • ESP_OK Success

  • ESP_FAIL Fail

  • ESP_ERR_NOT_SUPPORTED Function not supported on this sensor

esp_err_t imu_sleep(sensor_imu_handle_t sensor)

Set sensor to sleep mode.

参数

sensor – imu sensor handle to operate

返回

esp_err_t

  • ESP_OK Success

  • ESP_FAIL Fail

  • ESP_ERR_NOT_SUPPORTED Function not supported on this sensor

esp_err_t imu_wakeup(sensor_imu_handle_t sensor)

Wakeup sensor from sleep mode.

参数

sensor – imu sensor handle to operate

返回

esp_err_t

  • ESP_OK Success

  • ESP_FAIL Fail

  • ESP_ERR_NOT_SUPPORTED Function not supported on this sensor

esp_err_t imu_acquire(sensor_imu_handle_t sensor, sensor_data_group_t *data_group)

acquire a group of sensor data

参数
  • sensor – imu sensor handle to operate

  • data_group – acquired data

返回

esp_err_t

  • ESP_OK Success

  • ESP_FAIL Fail

esp_err_t imu_control(sensor_imu_handle_t sensor, sensor_command_t cmd, void *args)

control sensor mode with control commands and args

参数
  • sensor – imu sensor handle to operate

  • cmd – control commands detailed in sensor_command_t

  • args – control commands args

    • ESP_OK Success

    • ESP_FAIL Fail

    • ESP_ERR_NOT_SUPPORTED Function not supported on this sensor

Type Definitions

typedef void *sensor_imu_handle_t

imu sensor handle

Enumerations

enum imu_id_t

imu sensor id, used for imu_create

Values:

enumerator MPU6050_ID

MPU6050 imu sensor id

enumerator LIS2DH12_ID

LIS2DH12 imu sensor id

enumerator IMU_MAX_ID

max imu sensor id