惯性传感器 (IMU)¶
惯性传感器包含陀螺仪传感器、加速度传感器和兼具多种功能的传感器等。主要用于测量物体的加速度、角速度等,进而解算出物体的运动姿态。
已适配列表¶
名称 |
功能 |
总线 |
供应商 |
规格书 |
硬件抽象层 |
---|---|---|---|---|---|
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.
- Return
sensor_imu_handle_t return imu sensor handle if succeed, NULL is failed.
- Parameters
bus
: i2c bus handle the sensor attached toimu_id
: id declared in imu_id_t
-
esp_err_t
imu_delete
(sensor_imu_handle_t *sensor)¶ Delete and release the sensor resource.
- Return
esp_err_t
ESP_OK Success
ESP_FAIL Fail
- Parameters
sensor
: point to imu sensor handle, will set to NULL if delete succeed.
-
esp_err_t
imu_test
(sensor_imu_handle_t sensor)¶ Test if sensor is active.
- Return
esp_err_t
ESP_OK Success
ESP_FAIL Fail
- Parameters
sensor
: imu sensor handle to operate
-
esp_err_t
imu_acquire_acce
(sensor_imu_handle_t sensor, axis3_t *acce)¶ Acquire imu sensor accelerometer result one time.
- Return
esp_err_t
ESP_OK Success
ESP_FAIL Fail
ESP_ERR_NOT_SUPPORTED Function not supported on this sensor
- Parameters
sensor
: imu sensor handle to operateacce
: result data (unit:g)
-
esp_err_t
imu_acquire_gyro
(sensor_imu_handle_t sensor, axis3_t *gyro)¶ Acquire imu sensor gyroscope result one time.
- Return
esp_err_t
ESP_OK Success
ESP_FAIL Fail
ESP_ERR_NOT_SUPPORTED Function not supported on this sensor
- Parameters
sensor
: imu sensor handle to operategyro
: result data (unit:dps)
-
esp_err_t
imu_sleep
(sensor_imu_handle_t sensor)¶ Set sensor to sleep mode.
- Return
esp_err_t
ESP_OK Success
ESP_FAIL Fail
ESP_ERR_NOT_SUPPORTED Function not supported on this sensor
- Parameters
sensor
: imu sensor handle to operate
-
esp_err_t
imu_wakeup
(sensor_imu_handle_t sensor)¶ Wakeup sensor from sleep mode.
- Return
esp_err_t
ESP_OK Success
ESP_FAIL Fail
ESP_ERR_NOT_SUPPORTED Function not supported on this sensor
- Parameters
sensor
: imu sensor handle to operate
-
esp_err_t
imu_acquire
(sensor_imu_handle_t sensor, sensor_data_group_t *data_group)¶ acquire a group of sensor data
- Return
esp_err_t
ESP_OK Success
ESP_FAIL Fail
- Parameters
sensor
: imu sensor handle to operatedata_group
: acquired data
-
esp_err_t
imu_control
(sensor_imu_handle_t sensor, sensor_command_t cmd, void *args)¶ control sensor mode with control commands and args
- Parameters
sensor
: imu sensor handle to operatecmd
: control commands detailed in sensor_command_targs
: control commands argsESP_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