Allan Brignoli
/
Rome2_P6
gugus
IMU.h@0:1a0321f1ffbc, 2018-05-18 (annotated)
- Committer:
- Brignall
- Date:
- Fri May 18 12:18:21 2018 +0000
- Revision:
- 0:1a0321f1ffbc
lala;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Brignall | 0:1a0321f1ffbc | 1 | /* |
Brignall | 0:1a0321f1ffbc | 2 | * IMU.h |
Brignall | 0:1a0321f1ffbc | 3 | * Copyright (c) 2018, ZHAW |
Brignall | 0:1a0321f1ffbc | 4 | * All rights reserved. |
Brignall | 0:1a0321f1ffbc | 5 | */ |
Brignall | 0:1a0321f1ffbc | 6 | |
Brignall | 0:1a0321f1ffbc | 7 | #ifndef IMU_H_ |
Brignall | 0:1a0321f1ffbc | 8 | #define IMU_H_ |
Brignall | 0:1a0321f1ffbc | 9 | |
Brignall | 0:1a0321f1ffbc | 10 | #include <cstdlib> |
Brignall | 0:1a0321f1ffbc | 11 | #include <mbed.h> |
Brignall | 0:1a0321f1ffbc | 12 | #include "LowpassFilter.h" |
Brignall | 0:1a0321f1ffbc | 13 | |
Brignall | 0:1a0321f1ffbc | 14 | /** |
Brignall | 0:1a0321f1ffbc | 15 | * This is a device driver class for the ST LSM9DS0 inertial measurement unit. |
Brignall | 0:1a0321f1ffbc | 16 | */ |
Brignall | 0:1a0321f1ffbc | 17 | class IMU { |
Brignall | 0:1a0321f1ffbc | 18 | |
Brignall | 0:1a0321f1ffbc | 19 | public: |
Brignall | 0:1a0321f1ffbc | 20 | |
Brignall | 0:1a0321f1ffbc | 21 | IMU(SPI& spi, DigitalOut& csG, DigitalOut& csXM); |
Brignall | 0:1a0321f1ffbc | 22 | virtual ~IMU(); |
Brignall | 0:1a0321f1ffbc | 23 | float readGyroX(); |
Brignall | 0:1a0321f1ffbc | 24 | float readGyroY(); |
Brignall | 0:1a0321f1ffbc | 25 | float readGyroZ(); |
Brignall | 0:1a0321f1ffbc | 26 | float readAccelerationX(); |
Brignall | 0:1a0321f1ffbc | 27 | float readAccelerationY(); |
Brignall | 0:1a0321f1ffbc | 28 | float readAccelerationZ(); |
Brignall | 0:1a0321f1ffbc | 29 | float readMagnetometerX(); |
Brignall | 0:1a0321f1ffbc | 30 | float readMagnetometerY(); |
Brignall | 0:1a0321f1ffbc | 31 | float readMagnetometerZ(); |
Brignall | 0:1a0321f1ffbc | 32 | float readHeading(); |
Brignall | 0:1a0321f1ffbc | 33 | |
Brignall | 0:1a0321f1ffbc | 34 | private: |
Brignall | 0:1a0321f1ffbc | 35 | |
Brignall | 0:1a0321f1ffbc | 36 | static const char WHO_AM_I_G = 0x0F; |
Brignall | 0:1a0321f1ffbc | 37 | static const char CTRL_REG1_G = 0x20; |
Brignall | 0:1a0321f1ffbc | 38 | static const char OUT_X_L_G = 0x28; |
Brignall | 0:1a0321f1ffbc | 39 | static const char OUT_X_H_G = 0x29; |
Brignall | 0:1a0321f1ffbc | 40 | static const char OUT_Y_L_G = 0x2A; |
Brignall | 0:1a0321f1ffbc | 41 | static const char OUT_Y_H_G = 0x2B; |
Brignall | 0:1a0321f1ffbc | 42 | static const char OUT_Z_L_G = 0x2C; |
Brignall | 0:1a0321f1ffbc | 43 | static const char OUT_Z_H_G = 0x2D; |
Brignall | 0:1a0321f1ffbc | 44 | |
Brignall | 0:1a0321f1ffbc | 45 | static const char OUT_X_L_M = 0x08; |
Brignall | 0:1a0321f1ffbc | 46 | static const char OUT_X_H_M = 0x09; |
Brignall | 0:1a0321f1ffbc | 47 | static const char OUT_Y_L_M = 0x0A; |
Brignall | 0:1a0321f1ffbc | 48 | static const char OUT_Y_H_M = 0x0B; |
Brignall | 0:1a0321f1ffbc | 49 | static const char OUT_Z_L_M = 0x0C; |
Brignall | 0:1a0321f1ffbc | 50 | static const char OUT_Z_H_M = 0x0D; |
Brignall | 0:1a0321f1ffbc | 51 | static const char WHO_AM_I_XM = 0x0F; |
Brignall | 0:1a0321f1ffbc | 52 | |
Brignall | 0:1a0321f1ffbc | 53 | static const char INT_CTRL_REG_M = 0x12; |
Brignall | 0:1a0321f1ffbc | 54 | static const char CTRL_REG0_XM = 0x1F; |
Brignall | 0:1a0321f1ffbc | 55 | static const char CTRL_REG1_XM = 0x20; |
Brignall | 0:1a0321f1ffbc | 56 | static const char CTRL_REG2_XM = 0x21; |
Brignall | 0:1a0321f1ffbc | 57 | static const char CTRL_REG3_XM = 0x22; |
Brignall | 0:1a0321f1ffbc | 58 | static const char CTRL_REG4_XM = 0x23; |
Brignall | 0:1a0321f1ffbc | 59 | static const char CTRL_REG5_XM = 0x24; |
Brignall | 0:1a0321f1ffbc | 60 | static const char CTRL_REG6_XM = 0x25; |
Brignall | 0:1a0321f1ffbc | 61 | static const char CTRL_REG7_XM = 0x26; |
Brignall | 0:1a0321f1ffbc | 62 | |
Brignall | 0:1a0321f1ffbc | 63 | static const char OUT_X_L_A = 0x28; |
Brignall | 0:1a0321f1ffbc | 64 | static const char OUT_X_H_A = 0x29; |
Brignall | 0:1a0321f1ffbc | 65 | static const char OUT_Y_L_A = 0x2A; |
Brignall | 0:1a0321f1ffbc | 66 | static const char OUT_Y_H_A = 0x2B; |
Brignall | 0:1a0321f1ffbc | 67 | static const char OUT_Z_L_A = 0x2C; |
Brignall | 0:1a0321f1ffbc | 68 | static const char OUT_Z_H_A = 0x2D; |
Brignall | 0:1a0321f1ffbc | 69 | |
Brignall | 0:1a0321f1ffbc | 70 | static const float PERIOD; |
Brignall | 0:1a0321f1ffbc | 71 | static const float PI; |
Brignall | 0:1a0321f1ffbc | 72 | static const float LOWPASS_FILTER_FREQUENCY; |
Brignall | 0:1a0321f1ffbc | 73 | |
Brignall | 0:1a0321f1ffbc | 74 | SPI& spi; |
Brignall | 0:1a0321f1ffbc | 75 | DigitalOut& csG; |
Brignall | 0:1a0321f1ffbc | 76 | DigitalOut& csXM; |
Brignall | 0:1a0321f1ffbc | 77 | |
Brignall | 0:1a0321f1ffbc | 78 | float magnetometerXMin; |
Brignall | 0:1a0321f1ffbc | 79 | float magnetometerXMax; |
Brignall | 0:1a0321f1ffbc | 80 | float magnetometerYMin; |
Brignall | 0:1a0321f1ffbc | 81 | float magnetometerYMax; |
Brignall | 0:1a0321f1ffbc | 82 | LowpassFilter magnetometerXFilter; |
Brignall | 0:1a0321f1ffbc | 83 | LowpassFilter magnetometerYFilter; |
Brignall | 0:1a0321f1ffbc | 84 | float heading; |
Brignall | 0:1a0321f1ffbc | 85 | Ticker ticker; |
Brignall | 0:1a0321f1ffbc | 86 | |
Brignall | 0:1a0321f1ffbc | 87 | void writeRegister(DigitalOut& cs, char address, char value); |
Brignall | 0:1a0321f1ffbc | 88 | char readRegister(DigitalOut& cs, char address); |
Brignall | 0:1a0321f1ffbc | 89 | void run(); |
Brignall | 0:1a0321f1ffbc | 90 | }; |
Brignall | 0:1a0321f1ffbc | 91 | |
Brignall | 0:1a0321f1ffbc | 92 | #endif /* IMU_H_ */ |
Brignall | 0:1a0321f1ffbc | 93 |