Evan Brown
/
APpart3_E_start
11/18
sensor_fusion.h@0:f43994f44684, 2018-11-08 (annotated)
- Committer:
- evenbrownie
- Date:
- Thu Nov 08 20:48:47 2018 +0000
- Revision:
- 0:f43994f44684
- Child:
- 1:491bd986ce22
All I put in were the addresses from the beginning
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
evenbrownie | 0:f43994f44684 | 1 | /* |
evenbrownie | 0:f43994f44684 | 2 | * @author: Natasha Sarkar, 2018 |
evenbrownie | 0:f43994f44684 | 3 | */ |
evenbrownie | 0:f43994f44684 | 4 | |
evenbrownie | 0:f43994f44684 | 5 | #ifndef __MPU6050_H |
evenbrownie | 0:f43994f44684 | 6 | #define __MPU6050_H |
evenbrownie | 0:f43994f44684 | 7 | |
evenbrownie | 0:f43994f44684 | 8 | #include "mbed.h" |
evenbrownie | 0:f43994f44684 | 9 | |
evenbrownie | 0:f43994f44684 | 10 | /** TO DO |
evenbrownie | 0:f43994f44684 | 11 | * DEFINE THESE REGISTERS. |
evenbrownie | 0:f43994f44684 | 12 | * THE ADDRESS AND CONFIG REGISTERS HAVE BEEN DONE FOR YOU AS AN EXAMPLE. |
evenbrownie | 0:f43994f44684 | 13 | * |
evenbrownie | 0:f43994f44684 | 14 | * You will need to look at the register map. |
evenbrownie | 0:f43994f44684 | 15 | */ |
evenbrownie | 0:f43994f44684 | 16 | |
evenbrownie | 0:f43994f44684 | 17 | #define SDA PB_7 //the pin used for SDA |
evenbrownie | 0:f43994f44684 | 18 | #define SCL PB_6 //the pin used for SCL |
evenbrownie | 0:f43994f44684 | 19 | #define ADDRESS 0xD1 //the slave address of the IMU |
evenbrownie | 0:f43994f44684 | 20 | #define INT_STATUS 0x3A //the interrupt status register |
evenbrownie | 0:f43994f44684 | 21 | #define PWR_MGMT_1 0x6B //power management 1 |
evenbrownie | 0:f43994f44684 | 22 | #define CONFIG 0x1A //the IMU config register |
evenbrownie | 0:f43994f44684 | 23 | #define GYRO_CONFIG 0x1B //the gyroscope config register |
evenbrownie | 0:f43994f44684 | 24 | #define ACCEL_CONFIG 0x1C //the accelerometer config register |
evenbrownie | 0:f43994f44684 | 25 | #define GYRO_X 0x44 //the register that stores the first bit of the gyroscope x value |
evenbrownie | 0:f43994f44684 | 26 | #define ACCEL_X 0x3C //the register that stores the first bit of the accelerometer x value |
evenbrownie | 0:f43994f44684 | 27 | |
evenbrownie | 0:f43994f44684 | 28 | class MPU6050 { |
evenbrownie | 0:f43994f44684 | 29 | |
evenbrownie | 0:f43994f44684 | 30 | public: |
evenbrownie | 0:f43994f44684 | 31 | |
evenbrownie | 0:f43994f44684 | 32 | /** |
evenbrownie | 0:f43994f44684 | 33 | * Creates an MPU6050 object |
evenbrownie | 0:f43994f44684 | 34 | * |
evenbrownie | 0:f43994f44684 | 35 | * sda: pin name of the sda pin |
evenbrownie | 0:f43994f44684 | 36 | * scl: pin name of the scl pin |
evenbrownie | 0:f43994f44684 | 37 | */ |
evenbrownie | 0:f43994f44684 | 38 | MPU6050(PinName sda, PinName scl); |
evenbrownie | 0:f43994f44684 | 39 | |
evenbrownie | 0:f43994f44684 | 40 | /** |
evenbrownie | 0:f43994f44684 | 41 | * Called before using the MPU6050. |
evenbrownie | 0:f43994f44684 | 42 | * |
evenbrownie | 0:f43994f44684 | 43 | * Sets up the I2C by configuring registers |
evenbrownie | 0:f43994f44684 | 44 | * as described in the spec (calls write_reg). |
evenbrownie | 0:f43994f44684 | 45 | */ |
evenbrownie | 0:f43994f44684 | 46 | void start(void); |
evenbrownie | 0:f43994f44684 | 47 | |
evenbrownie | 0:f43994f44684 | 48 | /** |
evenbrownie | 0:f43994f44684 | 49 | * Gets the readings from the gyroscope and accelerometer (calls read_reg). |
evenbrownie | 0:f43994f44684 | 50 | * |
evenbrownie | 0:f43994f44684 | 51 | * Parameters: pointers to addresses where these readings should be stored. |
evenbrownie | 0:f43994f44684 | 52 | * |
evenbrownie | 0:f43994f44684 | 53 | * Returns true upon success, and false upon failure. |
evenbrownie | 0:f43994f44684 | 54 | */ |
evenbrownie | 0:f43994f44684 | 55 | bool read_raw(float *gx, float *gy, float *gz, float *ax, float *ay, float *az); |
evenbrownie | 0:f43994f44684 | 56 | |
evenbrownie | 0:f43994f44684 | 57 | /** |
evenbrownie | 0:f43994f44684 | 58 | * Reads the interrupt status register (calls read_reg). |
evenbrownie | 0:f43994f44684 | 59 | * |
evenbrownie | 0:f43994f44684 | 60 | * Returns true if data is ready, false otherwise. |
evenbrownie | 0:f43994f44684 | 61 | */ |
evenbrownie | 0:f43994f44684 | 62 | bool data_ready(void); |
evenbrownie | 0:f43994f44684 | 63 | |
evenbrownie | 0:f43994f44684 | 64 | private: |
evenbrownie | 0:f43994f44684 | 65 | |
evenbrownie | 0:f43994f44684 | 66 | I2C i2c_object; //instance of an i2c class |
evenbrownie | 0:f43994f44684 | 67 | |
evenbrownie | 0:f43994f44684 | 68 | /** |
evenbrownie | 0:f43994f44684 | 69 | * Writes 1 byte of data to a specific address |
evenbrownie | 0:f43994f44684 | 70 | * |
evenbrownie | 0:f43994f44684 | 71 | * addr: the i2c address of the slave device |
evenbrownie | 0:f43994f44684 | 72 | * reg: the register number to write to |
evenbrownie | 0:f43994f44684 | 73 | * buf: the data to write |
evenbrownie | 0:f43994f44684 | 74 | * |
evenbrownie | 0:f43994f44684 | 75 | * Returns true upon success, and false upon failure. |
evenbrownie | 0:f43994f44684 | 76 | */ |
evenbrownie | 0:f43994f44684 | 77 | bool write_reg(int addr, int reg, char buf); |
evenbrownie | 0:f43994f44684 | 78 | |
evenbrownie | 0:f43994f44684 | 79 | /** |
evenbrownie | 0:f43994f44684 | 80 | * Reads data from a specific address |
evenbrownie | 0:f43994f44684 | 81 | * |
evenbrownie | 0:f43994f44684 | 82 | * addr: the i2c address of the slave device |
evenbrownie | 0:f43994f44684 | 83 | * reg: the register numer to read from |
evenbrownie | 0:f43994f44684 | 84 | * buf: an array to store the data read |
evenbrownie | 0:f43994f44684 | 85 | * length: length of buf (how much to read) |
evenbrownie | 0:f43994f44684 | 86 | * |
evenbrownie | 0:f43994f44684 | 87 | * Returns true upon success, and false upon failure. |
evenbrownie | 0:f43994f44684 | 88 | */ |
evenbrownie | 0:f43994f44684 | 89 | bool read_reg(char addr, char reg, char *buf, int length); |
evenbrownie | 0:f43994f44684 | 90 | }; |
evenbrownie | 0:f43994f44684 | 91 | |
evenbrownie | 0:f43994f44684 | 92 | #endif |
evenbrownie | 0:f43994f44684 | 93 |