Inertial Measurement Unit (IMU)¶
The Inertial Measurement Unit (IMU) can be used as a gyroscope sensor, an acceleration sensor, a sensor with multiple functions or etc. It is mainly used to measure the acceleration and angular velocity of an object, and then calculate the motion attitude of the object.
Adapted Products¶
Name |
Function |
Bus |
Vendor |
Datasheet |
HAL |
---|---|---|---|---|---|
LIS2DH12 |
3-axis acceler |
I2C |
ST |
√ |
|
MPU6050 |
3-axis acceler + 3-axis gyro |
I2C |
InvenSense |
√ |
API Reference¶
The following APIs have implemented hardware abstraction on the IMU. Users can call the code from this layer directly to write a sensor application, or use the sensor interface in sensor_hub for easier development.
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