Library containing Crazyflie 2.0 sensors drivers: - LPS25H (barometer) - MPU9250 (IMU) - PMW3901 (optical flow) - VL53L0X (range)
Dependents: Drones-Controlador controladoatitude_cteste Drone_Controlador_Atitude optical_test
MPU9250/MPU9250.h
- Committer:
- fbob
- Date:
- 2018-04-19
- Revision:
- 3:2f2b8e863991
- Parent:
- 2:3d5f4b1c7bdb
- Child:
- 5:1ef8b91a0318
File content as of revision 3:2f2b8e863991:
#ifndef MPU9250_h #define MPU9250_h #include "mbed.h" // Physical constants #define GRAVITY 9.80665 #define PI 3.14159 // MPU9250 I2C address #define MPU9250_ADDRESS 0b1101001 << 1 // Shift 1 bit left because mbed utilizes 8-bit addresses and not 7-bit // Accelerometer configuration registers addresses #define ACCEL_CONFIG_1 0x1C #define ACCEL_CONFIG_2 0x1D // Accelerometer output register addresses #define ACCEL_XOUT_H 0x3B #define ACCEL_XOUT_L 0x3C #define ACCEL_YOUT_H 0x3D #define ACCEL_YOUT_L 0x3E #define ACCEL_ZOUT_H 0x3F #define ACCEL_ZOUT_L 0x40 // Gyroscope configuration registers addresses #define GYRO_CONFIG 0x1B // Accelerometer output register addresses #define GYRO_XOUT_H 0x43 #define GYRO_XOUT_L 0x44 #define GYRO_YOUT_H 0x45 #define GYRO_YOUT_L 0x46 #define GYRO_ZOUT_H 0x47 #define GYRO_ZOUT_L 0x48 // Auxiliary I2C configuration registers addresses #define INT_PIN_CFG 0x37 // Accelerometer full-scale ranges enum accel_scale { ACCEL_SCALE_2G = 0b00, ACCEL_SCALE_4G = 0b01, ACCEL_SCALE_8G = 0b10, ACCEL_SCALE_16G = 0b11 }; // Gyroscope full-scale ranges enum gyro_scale { GYRO_SCALE_250DPS = 0b00, GYRO_SCALE_500DPS = 0b01, GYRO_SCALE_1000DPS = 0b10, GYRO_SCALE_2000DPS = 0b11 }; /** MPU9250 (IMU sensor) class * * Example code (print accelerometer and gyroscope data on serial port every 1 second): * @code * #include "mbed.h" * #include "USBSerial.h" * #include "MPU9250.h" * * USBSerial pc; * MPU9250 imu(PC_9,PA_8); * * int main() * { * imu.init(); * while(1) * { * imu.read(); * pc.printf("Accel [m/s^2]: %6.2f %6.2f %6.2f \n", imu.ax, imu.ay, imu.az); * pc.printf("Gyro [rad/s]: %6.2f %6.2f %6.2f \n\n", imu.gx, imu.gy, imu.gz); * wait(1); * } * } * @endcode * (Need to target to NUCLEO-F401RE board platform) */ class MPU9250 { public: /** Class constructor */ MPU9250(PinName sda, PinName scl); /** Initialize accelerometer and gyroscope */ void init(); /** Read accelerometer and gyroscope */ void read(); /** Accelerometer data in x-axis [m/s^2]*/ float ax; /** Accelerometer data in y-axis [m/s^2]*/ float ay; /** Accelerometer data in z-axis [m/s^2]*/ float az; /** Gyroscope data in x-axis [rad/s]*/ float gx; /** Gyroscope data in y-axis [rad/s]*/ float gy; /** Gyroscope data in z-axis [rad/s]*/ float gz; private: /** I2C bus */ I2C i2c; /** Setup auxiliary I2C */ void setup_aux_i2c(); /** Setup accelerometer with given output data rate and full-scale range*/ void setup_accel(accel_scale a_scale = ACCEL_SCALE_16G); /** Setup gyroscope with given output data rate and full-scale range*/ void setup_gyro(gyro_scale g_scale = GYRO_SCALE_500DPS); /** Read accelerometer output data */ void read_accel(); /** Read accelerometer output data */ void read_gyro(); /** Accelerometer resolution [m/s^2 / bit]*/ float a_res; /** Gyroscope resolution [rad/s / bit]*/ float g_res; }; #endif