HRI board firmware  v2.1
Microcontroller firmware of the board used during the HRI labs.
Macros | Functions | Variables
mpu_6050.c File Reference
#include "mpu_6050.h"
#include <limits.h>
#include "i2c.h"
#include "../lib/utils.h"

Macros

#define GRAVITY_INTENSITY   9.81f
 
#define SINT16_MAX_F   ((float32_t)SHRT_MAX)
 
#define SLAVE_ADDRESS   0x68
 0x68 if the AD0 pin is low, 0x69 otherwise. More...
 
#define REG_CONFIG   0x1A
 Configuration register. More...
 
#define REG_GYRO_CONFIG   0x1B
 Gyroscope configuration register. More...
 
#define REG_ACCEL_CONFIG   0x1C
 Accelerometer configuration register. More...
 
#define REG_SMPLRT_DIV   0x19
 Sample rate divider register. More...
 
#define REG_ACCEL_VALUES   0x3b
 Accelerometer measurements register. More...
 
#define REG_TEMP_VALUES   0x41
 Temperature measurements register. More...
 
#define REG_GYRO_VALUES   0x43
 Gyroscope measurements register. More...
 
#define REG_SIG_PATH_RST   0x68
 Signal path reset register. More...
 
#define REG_USER_CTRL   0x6A
 User control register. More...
 
#define REG_POWER_MGMT_1   0x6B
 Power management 1 register. More...
 
#define REG_WHO_AM_I   0x75
 Who am I register. More...
 
#define WHO_AM_I_VAL   0x68
 Expected value of the REG_WHO_AM_I register. 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...
 
float32_t mpu_GetTemperature (void)
 Acquires the temperature from the IMU. More...
 

Variables

const float32_t MPU_ACCEL_RANGE_REG_TO_CONV_FACTOR []
 Gets the actual range value from a mpu_AccelRange enum value. More...
 
const float32_t MPU_GYRO_RANGE_REG_TO_CONV_FACTOR []
 Gets the actual range value from a mpu_GyroRange enum value. More...
 
bool mpu_initialized = false
 True if the MPU-6050 is initialized, false otherwise. More...
 
float32_t accelFactor
 Converts a raw 16-bit integer value to an acceleration [m/s^2]. More...
 
float32_t gyroFactor
 Converts a raw 16-bit integer value to an angular speed [deg/s]. More...
 

Macro Definition Documentation

◆ GRAVITY_INTENSITY

#define GRAVITY_INTENSITY   9.81f

◆ REG_ACCEL_CONFIG

#define REG_ACCEL_CONFIG   0x1C

Accelerometer configuration register.

◆ REG_ACCEL_VALUES

#define REG_ACCEL_VALUES   0x3b

Accelerometer measurements register.

◆ REG_CONFIG

#define REG_CONFIG   0x1A

Configuration register.

◆ REG_GYRO_CONFIG

#define REG_GYRO_CONFIG   0x1B

Gyroscope configuration register.

◆ REG_GYRO_VALUES

#define REG_GYRO_VALUES   0x43

Gyroscope measurements register.

◆ REG_POWER_MGMT_1

#define REG_POWER_MGMT_1   0x6B

Power management 1 register.

◆ REG_SIG_PATH_RST

#define REG_SIG_PATH_RST   0x68

Signal path reset register.

◆ REG_SMPLRT_DIV

#define REG_SMPLRT_DIV   0x19

Sample rate divider register.

◆ REG_TEMP_VALUES

#define REG_TEMP_VALUES   0x41

Temperature measurements register.

◆ REG_USER_CTRL

#define REG_USER_CTRL   0x6A

User control register.

◆ REG_WHO_AM_I

#define REG_WHO_AM_I   0x75

Who am I register.

◆ SINT16_MAX_F

#define SINT16_MAX_F   ((float32_t)SHRT_MAX)

◆ SLAVE_ADDRESS

#define SLAVE_ADDRESS   0x68

0x68 if the AD0 pin is low, 0x69 otherwise.

◆ WHO_AM_I_VAL

#define WHO_AM_I_VAL   0x68

Expected value of the REG_WHO_AM_I register.

Variable Documentation

◆ accelFactor

float32_t accelFactor

Converts a raw 16-bit integer value to an acceleration [m/s^2].

◆ gyroFactor

float32_t gyroFactor

Converts a raw 16-bit integer value to an angular speed [deg/s].

◆ MPU_ACCEL_RANGE_REG_TO_CONV_FACTOR

const float32_t MPU_ACCEL_RANGE_REG_TO_CONV_FACTOR[]
Initial value:
=
{
16.0f / SINT16_MAX_F * GRAVITY_INTENSITY
}
#define GRAVITY_INTENSITY
Definition: mpu_6050.c:24
#define SINT16_MAX_F
Definition: mpu_6050.c:25

Gets the actual range value from a mpu_AccelRange enum value.

◆ MPU_GYRO_RANGE_REG_TO_CONV_FACTOR

const float32_t MPU_GYRO_RANGE_REG_TO_CONV_FACTOR[]
Initial value:
=
{
250.0f / SINT16_MAX_F,
500.0f / SINT16_MAX_F,
1000.0f / SINT16_MAX_F,
2000.0f / SINT16_MAX_F
}
#define SINT16_MAX_F
Definition: mpu_6050.c:25

Gets the actual range value from a mpu_GyroRange enum value.

◆ mpu_initialized

bool mpu_initialized = false

True if the MPU-6050 is initialized, false otherwise.