![](/media/cache/group/11700697_10200701668420946_8214886085951071495_o.jpg.50x50_q85.jpg)
Class of MPU9250
Dependencies: AHRS_fillter mbed
Fork of MPU9250AHRS by
MPU9250.h@6:5665d427bceb, 2016-01-20 (annotated)
- Committer:
- icyzkungz
- Date:
- Wed Jan 20 02:34:07 2016 +0000
- Revision:
- 6:5665d427bceb
- Parent:
- 5:d31487b34216
MPU9250-OOP
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
onehorse | 0:2e5e65a6fb30 | 1 | #ifndef MPU9250_H |
onehorse | 0:2e5e65a6fb30 | 2 | #define MPU9250_H |
icyzkungz | 6:5665d427bceb | 3 | |
onehorse | 0:2e5e65a6fb30 | 4 | #include "mbed.h" |
onehorse | 0:2e5e65a6fb30 | 5 | #include "math.h" |
icyzkungz | 6:5665d427bceb | 6 | #include "register.h" |
onehorse | 0:2e5e65a6fb30 | 7 | |
soulx | 5:d31487b34216 | 8 | |
icyzkungz | 6:5665d427bceb | 9 | static DigitalOut myled(LED1); |
onehorse | 0:2e5e65a6fb30 | 10 | |
onehorse | 0:2e5e65a6fb30 | 11 | |
icyzkungz | 6:5665d427bceb | 12 | class MPU9250 |
onehorse | 0:2e5e65a6fb30 | 13 | { |
onehorse | 0:2e5e65a6fb30 | 14 | |
icyzkungz | 6:5665d427bceb | 15 | protected: |
onehorse | 0:2e5e65a6fb30 | 16 | |
icyzkungz | 6:5665d427bceb | 17 | public: |
icyzkungz | 6:5665d427bceb | 18 | enum Ascale { |
icyzkungz | 6:5665d427bceb | 19 | AFS_2G = 0, |
icyzkungz | 6:5665d427bceb | 20 | AFS_4G, |
icyzkungz | 6:5665d427bceb | 21 | AFS_8G, |
icyzkungz | 6:5665d427bceb | 22 | AFS_16G |
icyzkungz | 6:5665d427bceb | 23 | }; |
onehorse | 0:2e5e65a6fb30 | 24 | |
icyzkungz | 6:5665d427bceb | 25 | enum Gscale { |
icyzkungz | 6:5665d427bceb | 26 | GFS_250DPS = 0, |
icyzkungz | 6:5665d427bceb | 27 | GFS_500DPS, |
icyzkungz | 6:5665d427bceb | 28 | GFS_1000DPS, |
icyzkungz | 6:5665d427bceb | 29 | GFS_2000DPS |
icyzkungz | 6:5665d427bceb | 30 | }; |
onehorse | 0:2e5e65a6fb30 | 31 | |
icyzkungz | 6:5665d427bceb | 32 | enum Mscale { |
icyzkungz | 6:5665d427bceb | 33 | MFS_14BITS = 0, // 0.6 mG per LSB |
icyzkungz | 6:5665d427bceb | 34 | MFS_16BITS // 0.15 mG per LSB |
icyzkungz | 6:5665d427bceb | 35 | }; |
onehorse | 0:2e5e65a6fb30 | 36 | |
icyzkungz | 6:5665d427bceb | 37 | MPU9250(PinName sda, PinName scl, PinName tx, PinName rx, int address); |
icyzkungz | 6:5665d427bceb | 38 | ~MPU9250() {} |
onehorse | 0:2e5e65a6fb30 | 39 | |
icyzkungz | 6:5665d427bceb | 40 | Serial pc; |
icyzkungz | 6:5665d427bceb | 41 | I2C i2c; |
icyzkungz | 6:5665d427bceb | 42 | void writeByte(uint8_t address, uint8_t subAddress, uint8_t data); |
icyzkungz | 6:5665d427bceb | 43 | char readByte(uint8_t address, uint8_t subAddress); |
icyzkungz | 6:5665d427bceb | 44 | void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t * dest) ; |
onehorse | 0:2e5e65a6fb30 | 45 | |
icyzkungz | 6:5665d427bceb | 46 | void initMPU9250(); |
icyzkungz | 6:5665d427bceb | 47 | void calibrateMPU9250(); |
onehorse | 0:2e5e65a6fb30 | 48 | |
icyzkungz | 6:5665d427bceb | 49 | void setMres(); |
icyzkungz | 6:5665d427bceb | 50 | void setGres(); |
icyzkungz | 6:5665d427bceb | 51 | void setAres(); |
onehorse | 0:2e5e65a6fb30 | 52 | |
icyzkungz | 6:5665d427bceb | 53 | void getMres(); |
icyzkungz | 6:5665d427bceb | 54 | void getGres(); |
icyzkungz | 6:5665d427bceb | 55 | void getAres(); |
onehorse | 0:2e5e65a6fb30 | 56 | |
icyzkungz | 6:5665d427bceb | 57 | void AccelXYZCal(); |
icyzkungz | 6:5665d427bceb | 58 | void GyroXYZCal(); |
icyzkungz | 6:5665d427bceb | 59 | void MagXYZCal(); |
onehorse | 0:2e5e65a6fb30 | 60 | |
icyzkungz | 6:5665d427bceb | 61 | void MagCal(); |
onehorse | 0:2e5e65a6fb30 | 62 | |
icyzkungz | 6:5665d427bceb | 63 | void readAccelData(); |
icyzkungz | 6:5665d427bceb | 64 | void readGyroData(); |
icyzkungz | 6:5665d427bceb | 65 | void readMagData(); |
icyzkungz | 6:5665d427bceb | 66 | void readTempData(); |
onehorse | 0:2e5e65a6fb30 | 67 | |
icyzkungz | 6:5665d427bceb | 68 | void resetMPU9250(); |
icyzkungz | 6:5665d427bceb | 69 | void initAK8963(); |
icyzkungz | 6:5665d427bceb | 70 | void MPU9250SelfTest(); |
icyzkungz | 6:5665d427bceb | 71 | |
icyzkungz | 6:5665d427bceb | 72 | void Start(); |
icyzkungz | 6:5665d427bceb | 73 | void ReadRawAccGyroMag(); |
icyzkungz | 6:5665d427bceb | 74 | |
icyzkungz | 6:5665d427bceb | 75 | float ax, ay, az, gx, gy, gz, mx, my, mz; // variables to hold latest sensor data values |
icyzkungz | 6:5665d427bceb | 76 | |
onehorse | 2:4e59a37182df | 77 | |
icyzkungz | 6:5665d427bceb | 78 | protected: |
icyzkungz | 6:5665d427bceb | 79 | float temperature; |
icyzkungz | 6:5665d427bceb | 80 | uint8_t whoami; |
icyzkungz | 6:5665d427bceb | 81 | |
icyzkungz | 6:5665d427bceb | 82 | private: |
icyzkungz | 6:5665d427bceb | 83 | uint8_t MPU9250_ADDRESS; |
onehorse | 2:4e59a37182df | 84 | |
icyzkungz | 6:5665d427bceb | 85 | int16_t accelCount[3]; // Stores the 16-bit signed accelerometer sensor output |
icyzkungz | 6:5665d427bceb | 86 | int16_t gyroCount[3]; // Stores the 16-bit signed gyro sensor output |
icyzkungz | 6:5665d427bceb | 87 | int16_t magCount[3]; // Stores the 16-bit signed magnetometer sensor output |
icyzkungz | 6:5665d427bceb | 88 | float magCalibration[3], magbias[3]; // Factory mag calibration and mag bias |
icyzkungz | 6:5665d427bceb | 89 | float gyroBias[3], accelBias[3]; // Bias corrections for gyro and accelerometer |
icyzkungz | 6:5665d427bceb | 90 | //int16_t tempCount; // Stores the real internal chip temperature in degrees Celsius |
icyzkungz | 6:5665d427bceb | 91 | float SelfTest[6]; |
onehorse | 0:2e5e65a6fb30 | 92 | |
onehorse | 0:2e5e65a6fb30 | 93 | |
onehorse | 0:2e5e65a6fb30 | 94 | |
icyzkungz | 6:5665d427bceb | 95 | //MagCal |
icyzkungz | 6:5665d427bceb | 96 | float xmax,xmin; |
icyzkungz | 6:5665d427bceb | 97 | float ymax,ymin; |
icyzkungz | 6:5665d427bceb | 98 | float zmax,zmin; |
icyzkungz | 6:5665d427bceb | 99 | bool change; |
onehorse | 0:2e5e65a6fb30 | 100 | |
icyzkungz | 6:5665d427bceb | 101 | uint8_t Ascale; // AFS_2G, AFS_4G, AFS_8G, AFS_16G |
icyzkungz | 6:5665d427bceb | 102 | uint8_t Gscale; // GFS_250DPS, GFS_500DPS, GFS_1000DPS, GFS_2000DPS |
icyzkungz | 6:5665d427bceb | 103 | uint8_t Mscale; // MFS_14BITS or MFS_16BITS, 14-bit or 16-bit magnetometer resolution |
icyzkungz | 6:5665d427bceb | 104 | uint8_t Mmode; // Either 8 Hz 0x02) or 100 Hz (0x06) magnetometer data ODR |
icyzkungz | 6:5665d427bceb | 105 | float aRes, gRes, mRes; // scale resolutions per LSB for the sensors |
onehorse | 0:2e5e65a6fb30 | 106 | |
icyzkungz | 6:5665d427bceb | 107 | }; |
onehorse | 0:2e5e65a6fb30 | 108 | #endif |