IMU API

The IMU API abstracts away the need to specify a specific sensor’s init/read/write/etc functions in order to gather positional data.

In order to use this API, the sensors object must be present in the project’s config.json file, along with one of the supported child sensors. An example is given below:

{
    "sensors": {
        "bno055": {
            "i2c_bus": "K_I2C1"
        }
    }
}

This would enable the sensor API and the BNO055 sensor code and configure it for the I2C bus K_I2C1.

KSensorStatus k_initialize_imu_sensor(void)

Setup the IMU interface and any related sensors.

Return
KSensorStatus - SENSOR_OK on success, SENSOR_WRITE_ERROR, SENSOR_NOT_FOUND or SENSOR_NOT_CALIBRATED on error

KSensorStatus k_get_gyro(k_sensor_vector_t *gyro)

Reads gyroscope data from the related sensor.

Return
KSensorStatus - SENSOR_OK on success, SENSOR_NOT_FOUND, SENSOR_READ_ERROR, SENSOR_WRITE_ERROR on error
Parameters
  • gyro: pointer to 3D IMU vector struct

KSensorStatus k_get_compass(k_sensor_vector_t *mag)

Reads magnetometer data from the related sensor.

Return
KSensorStatus - SENSOR_OK on success, SENSOR_NOT_FOUND, SENSOR_READ_ERROR, SENSOR_WRITE_ERROR on error
Parameters
  • mag: pointer to 3D IMU vector struct

KSensorStatus k_get_acceleration(k_sensor_vector_t *accel)

Reads accelerometer data from the related sensor.

Return
KSensorStatus - SENSOR_OK on success, SENSOR_NOT_FOUND, SENSOR_READ_ERROR, SENSOR_WRITE_ERROR on error
Parameters
  • accel: pointer to 3D IMU vector struct

KSensorStatus k_get_absolute_position(k_position_vector_t *pos)

Computes absolute position in a quaternion vector using sensor fusion.

Return
KSensorStatus - SENSOR_OK on success, SENSOR_NOT_FOUND, SENSOR_READ_ERROR, SENSOR_WRITE_ERROR on error
Parameters
  • pos: pointer to quaternion position struct

struct k_sensor_vector_t
#include <imu.h>

3D IMU vector

struct k_position_vector_t
#include <imu.h>

Quaternion absolute position vector.