HRI board firmware v2.1 Microcontroller firmware of the board used during the HRI labs.

Enumerations | Functions
Driver / MPU-6050

Driver for the MPU-6050, a 6-axis IMU from Invensense. More...

## Enumerations
enum | mpu_AccelRange { MPU_ACCEL_RANGE_2G = 0, MPU_ACCEL_RANGE_4G = 1, MPU_ACCEL_RANGE_8G = 2, MPU_ACCEL_RANGE_16G = 3 }
| Enumeration of the possible accelerometer ranges. More...
enum | mpu_GyroRange { MPU_GYRO_RANGE_250DPS = 0, MPU_GYRO_RANGE_500DPS = 1, MPU_GYRO_RANGE_1000DPS = 2, MPU_GYRO_RANGE_2000DPS = 3 }
| Enumeration of the possible gyrometer ranges. More...
enum | mpu_Bandwidth { MPU_DLPF_BW_256HZ = 0, MPU_DLPF_BW_188HZ = 1, MPU_DLPF_BW_98HZ = 2, MPU_DLPF_BW_42HZ = 3, MPU_DLPF_BW_20HZ = 4, MPU_DLPF_BW_10HZ = 5, MPU_DLPF_BW_5HZ = 6 }
| Enumeration of the possible bandwidths. More...
enum | mpu_Axis { MPU_AXIS_ACCEL_X = 0x3b, MPU_AXIS_ACCEL_Y = 0x3d, MPU_AXIS_ACCEL_Z = 0x3f, MPU_AXIS_TEMPERATURE = 0x41, MPU_AXIS_GYRO_X = 0x43, MPU_AXIS_GYRO_Y = 0x45, MPU_AXIS_GYRO_Z = 0x47 }
| Enumeration of all the measurement registers. More...

## Functions
bool | mpu_Init (mpu_AccelRange accelRange, mpu_GyroRange gyroRange, mpu_Bandwidth bandwidth)
| Initializes the MPU-6050 device. More...
void | mpu_GetAxis (mpu_Axis axis, float32_t *value)
| Acquires the value of a single axis, from the IMU. More...
void | mpu_GetAcceleration (float32_t *ax, float32_t *ay, float32_t *az)
| Acquires the acceleration from the IMU. More...
void | mpu_GetAngularSpeed (float32_t *gx, float32_t *gy, float32_t *gz)
| Acquires the angular speed from the IMU. More...
float | mpu_GetTemperature (void)
| Acquires the temperature from the IMU. More...

## Detailed Description

Driver for the MPU-6050, a 6-axis IMU from Invensense.

This driver uses the I2C bus of the digital extension connector.

Call mpu_Init() first in the initialization code. Then, call mpu_Get() to get the accelerations and angular speeds.

Note
  This driver setup the MPU-6050 sampling rate to 1 kHz. Calling mpu_Get() more often will return the same values.

## Enumeration Type Documentation

## ◆ mpu_AccelRange

enum mpu_AccelRange

Enumeration of the possible accelerometer ranges.

Enumerator
MPU_ACCEL_RANGE_2G | +-2 G (+-19.62 m/s^2).
MPU_ACCEL_RANGE_4G | +-4 G (+-39.24 m/s^2).
MPU_ACCEL_RANGE_8G | +-8 G (+-78.48 m/s^2).
MPU_ACCEL_RANGE_16G | +-16 G (+-156.96 m/s^2).

## ◆ mpu_Axis

enum mpu_Axis

Enumeration of all the measurement registers.

Enumerator
MPU_AXIS_ACCEL_X |
MPU_AXIS_ACCEL_Y |
MPU_AXIS_ACCEL_Z |
MPU_AXIS_TEMPERATURE |
MPU_AXIS_GYRO_X |
MPU_AXIS_GYRO_Y |
MPU_AXIS_GYRO_Z |

## ◆ mpu_Bandwidth

enum mpu_Bandwidth

Enumeration of the possible bandwidths.

Enumerator
MPU_DLPF_BW_256HZ | Cut-off freq: 256 Hz. IMU sampling freq: 8kHz.
MPU_DLPF_BW_188HZ | Cut-off freq: 188 Hz. IMU sampling freq: 1kHz.
MPU_DLPF_BW_98HZ | Cut-off freq: 98 Hz. IMU sampling freq: 1kHz.
MPU_DLPF_BW_42HZ | Cut-off freq: 42 Hz. IMU sampling freq: 1kHz.
MPU_DLPF_BW_20HZ | Cut-off freq: 20 Hz. IMU sampling freq: 1kHz.
MPU_DLPF_BW_10HZ | Cut-off freq: 10 Hz. IMU sampling freq: 1kHz.
MPU_DLPF_BW_5HZ | Cut-off freq: 5 Hz. IMU sampling freq: 1kHz.

## ◆ mpu_GyroRange

enum mpu_GyroRange

Enumeration of the possible gyrometer ranges.

Enumerator
MPU_GYRO_RANGE_250DPS | +- 250 deg/s.
MPU_GYRO_RANGE_500DPS | +- 500 deg/s.
MPU_GYRO_RANGE_1000DPS | +- 1000 deg/s.
MPU_GYRO_RANGE_2000DPS | +- 2000 deg/s.

## Function Documentation

## ◆ mpu_GetAcceleration()

void mpu_GetAcceleration | ( | float32_t * | ax,
|  | float32_t * | ay,
|  | float32_t * | az
| ) |  |

Acquires the acceleration from the IMU.

Parameters

  ax | variable to write the X-axis acceleration on [m/s^2].
  ay | variable to write the Y-axis acceleration on [m/s^2].
  az | variable to write the Z-axis acceleration on [m/s^2].

Remarks
  ax, ay, and az pointer must be valid (they can't be NULL).
  if the MPU-6050 is not initialized (mpu_Init() was not called successfully), then this function does nothing.
  If the operation failed, then *ax, *ay and *az are not modified.

## ◆ mpu_GetAngularSpeed()

void mpu_GetAngularSpeed | ( | float32_t * | gx,
|  | float32_t * | gy,
|  | float32_t * | gz
| ) |  |

Acquires the angular speed from the IMU.

Parameters

  gx | variable to write the X-axis angular speed on [deg/s].
  gy | variable to write the Y-axis angular speed on [deg/s].
  gz | variable to write the Z-axis angular speed on [deg/s].

Remarks
  gx, gy, and gz pointer must be valid (they can't be NULL).
  if the MPU-6050 is not initialized (mpu_Init() was not called successfully), then this function does nothing.
  If the operation failed, then *ax, *ay and *az are not modified.

## ◆ mpu_GetAxis()

void mpu_GetAxis | ( | mpu_Axis | axis,
|  | float32_t * | value
| ) |  |

Acquires the value of a single axis, from the IMU.

Parameters

  axis | the IMU axis to get (see mpu_Axis).
  value | variable to write the value on. The unit depends on the selected axis: [m/s^2] for an acceleration, [deg/s] for an angular speed, and [celsius] for the temperature.

Remarks
  if the MPU-6050 is not initialized (mpu_Init() was not called successfully), then this function returns 0.0f.
  If the operation failed, then *value is not modified.

## ◆ mpu_GetTemperature()

float mpu_GetTemperature | ( | void |  | ) |

Acquires the temperature from the IMU.

Returns
  the measured temperature [celsius], or 0 if the operation failed.

Remarks
  if the MPU-6050 is not initialized (mpu_Init() was not called successfully), then this function returns 0.0f.

## ◆ mpu_Init()

bool mpu_Init | ( | mpu_AccelRange | accelRange,
|  | mpu_GyroRange | gyroRange,
|  | mpu_Bandwidth | bandwidth
| ) |  |

Initializes the MPU-6050 device.

Parameters

  accelRange | accelerometer range.
  gyroRange | gyroscope range.
  bandwidth | bandwith of the accelerometer and gyroscope.

Returns
  true if the initialization was successful, false otherwise.