Robot Control Library
mpu.h File Reference
#include <stdint.h>
#include <pthread.h>

Go to the source code of this file.

Data Structures

struct  rc_mpu_config_t
 configuration of the mpu sensor More...
 
struct  rc_mpu_data_t
 data struct populated with new sensor data More...
 

Macros

#define RC_MPU_DEFAULT_I2C_ADDR   0x68
 default i2c address if AD0 is left low More...
 
#define RC_MPU_ALT_I2C_ADDR   0x69
 alternate i2c address if AD0 pin pulled high More...
 
#define TB_PITCH_X   0
 Index of the dmp_TaitBryan[] array corresponding to the Pitch (X) axis. More...
 
#define TB_ROLL_Y   1
 Index of the dmp_TaitBryan[] array corresponding to the Roll (Y) axis. More...
 
#define TB_YAW_Z   2
 Index of the dmp_TaitBryan[] array corresponding to the Yaw (Z) axis. More...
 
#define QUAT_W   0
 First index of the dmp_quat[] quaternion vector. More...
 
#define QUAT_X   1
 Second index of the dmp_quat[] quaternion vector. More...
 
#define QUAT_Y   2
 Third index of the dmp_quat[] quaternion vector. More...
 
#define QUAT_Z   3
 Fourth index of the dmp_quat[] quaternion vector. More...
 
#define DEG_TO_RAD   0.0174532925199
 multiply to convert degrees to radians More...
 
#define RAD_TO_DEG   57.295779513
 multiply to convert radians to degrees More...
 
#define MS2_TO_G   0.10197162129
 multiply to convert m/s^2 to G More...
 
#define G_TO_MS2   9.80665
 multiply to convert G to m/s^2, standard gravity definition More...
 

Typedefs

typedef enum rc_mpu_accel_fsr_t rc_mpu_accel_fsr_t
 accelerometer full scale range options More...
 
typedef enum rc_mpu_gyro_fsr_t rc_mpu_gyro_fsr_t
 gyroscope full scale range options More...
 
typedef enum rc_mpu_accel_dlpf_t rc_mpu_accel_dlpf_t
 accelerometer digital low-pass filter options More...
 
typedef enum rc_mpu_gyro_dlpf_t rc_mpu_gyro_dlpf_t
 gyroscope digital low-pass filter options More...
 
typedef enum rc_mpu_orientation_t rc_mpu_orientation_t
 Orientation of the sensor. More...
 
typedef struct rc_mpu_config_t rc_mpu_config_t
 configuration of the mpu sensor More...
 
typedef struct rc_mpu_data_t rc_mpu_data_t
 data struct populated with new sensor data More...
 

Enumerations

enum  rc_mpu_accel_fsr_t {
  ACCEL_FSR_2G,
  ACCEL_FSR_4G,
  ACCEL_FSR_8G,
  ACCEL_FSR_16G
}
 accelerometer full scale range options More...
 
enum  rc_mpu_gyro_fsr_t {
  GYRO_FSR_250DPS,
  GYRO_FSR_500DPS,
  GYRO_FSR_1000DPS,
  GYRO_FSR_2000DPS
}
 gyroscope full scale range options More...
 
enum  rc_mpu_accel_dlpf_t {
  ACCEL_DLPF_OFF,
  ACCEL_DLPF_460,
  ACCEL_DLPF_184,
  ACCEL_DLPF_92,
  ACCEL_DLPF_41,
  ACCEL_DLPF_20,
  ACCEL_DLPF_10,
  ACCEL_DLPF_5
}
 accelerometer digital low-pass filter options More...
 
enum  rc_mpu_gyro_dlpf_t {
  GYRO_DLPF_OFF,
  GYRO_DLPF_250,
  GYRO_DLPF_184,
  GYRO_DLPF_92,
  GYRO_DLPF_41,
  GYRO_DLPF_20,
  GYRO_DLPF_10,
  GYRO_DLPF_5
}
 gyroscope digital low-pass filter options More...
 
enum  rc_mpu_orientation_t {
  ORIENTATION_Z_UP = 136,
  ORIENTATION_Z_DOWN = 396,
  ORIENTATION_X_UP = 14,
  ORIENTATION_X_DOWN = 266,
  ORIENTATION_Y_UP = 112,
  ORIENTATION_Y_DOWN = 336,
  ORIENTATION_X_FORWARD = 133,
  ORIENTATION_X_BACK = 161
}
 Orientation of the sensor. More...
 

Functions

common functions
rc_mpu_config_t rc_mpu_default_config (void)
 Returns an rc_mpu_config_t struct with default settings. More...
 
int rc_mpu_set_config_to_default (rc_mpu_config_t *conf)
 Resets a config struct to defaults. More...
 
int rc_mpu_power_off (void)
 Powers off the MPU. More...
 
normal one-shot sampling functions
int rc_mpu_initialize (rc_mpu_data_t *data, rc_mpu_config_t conf)
 Sets up the MPU in normal one-shot sampling mode. More...
 
int rc_mpu_read_accel (rc_mpu_data_t *data)
 Reads accelerometer data from the MPU. More...
 
int rc_mpu_read_gyro (rc_mpu_data_t *data)
 Reads gyroscope data from the MPU. More...
 
int rc_mpu_read_temp (rc_mpu_data_t *data)
 Reads thermometer data from the MPU. More...
 
int rc_mpu_read_mag (rc_mpu_data_t *data)
 Reads magnetometer data from the MPU. More...
 
interrupt-driven DMP mode functions
int rc_mpu_initialize_dmp (rc_mpu_data_t *data, rc_mpu_config_t conf)
 Initializes the MPU in DMP mode, see rc_test_dmp example. More...
 
int rc_mpu_set_dmp_callback (void(*func)(void))
 Sets the callback function that will be triggered when new DMP data is ready. More...
 
int rc_mpu_block_until_dmp_data (void)
 blocking function that returns once new DMP data is available More...
 
int64_t rc_mpu_nanos_since_last_dmp_interrupt (void)
 calculates number of nanoseconds since the last DMP interrupt More...
 
int rc_mpu_set_tap_callback (void(*func)(int direction, int counter))
 sets the callback function triggered when a tap is detected More...
 
int rc_mpu_block_until_tap (void)
 blocking function that returns when a tap is detected More...
 
int64_t rc_mpu_nanos_since_last_tap (void)
 calculates nanoseconds since last tap was detected More...
 
calibration functions
int rc_mpu_calibrate_gyro_routine (rc_mpu_config_t conf)
 Runs gyroscope calibration routine. More...
 
int rc_mpu_calibrate_mag_routine (rc_mpu_config_t conf)
 Runs magnetometer calibration routine. More...
 
int rc_mpu_calibrate_accel_routine (rc_mpu_config_t conf)
 Runs accelerometer calibration routine. More...
 
int rc_mpu_is_gyro_calibrated (void)
 Checks if a gyro calibration file is saved to disk. More...
 
int rc_mpu_is_mag_calibrated (void)
 Checks if a magnetometer calibration file is saved to disk. More...
 
int rc_mpu_is_accel_calibrated (void)
 Checks if an accelerometer calibration file is saved to disk. More...