Nicolas Borla
/
BBR_1Ebene
BBR 1 Ebene
IMU.h@0:fbdae7e6d805, 2018-05-14 (annotated)
- Committer:
- borlanic
- Date:
- Mon May 14 11:29:06 2018 +0000
- Revision:
- 0:fbdae7e6d805
BBR
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
borlanic | 0:fbdae7e6d805 | 1 | /* |
borlanic | 0:fbdae7e6d805 | 2 | * IMU.h |
borlanic | 0:fbdae7e6d805 | 3 | * Copyright (c) 2018, ZHAW |
borlanic | 0:fbdae7e6d805 | 4 | * All rights reserved. |
borlanic | 0:fbdae7e6d805 | 5 | */ |
borlanic | 0:fbdae7e6d805 | 6 | |
borlanic | 0:fbdae7e6d805 | 7 | #ifndef IMU_H_ |
borlanic | 0:fbdae7e6d805 | 8 | #define IMU_H_ |
borlanic | 0:fbdae7e6d805 | 9 | |
borlanic | 0:fbdae7e6d805 | 10 | #include <cstdlib> |
borlanic | 0:fbdae7e6d805 | 11 | #include <stdint.h> |
borlanic | 0:fbdae7e6d805 | 12 | #include "mbed.h" |
borlanic | 0:fbdae7e6d805 | 13 | #include "LowpassFilter.h" |
borlanic | 0:fbdae7e6d805 | 14 | #include "Signal.h" |
borlanic | 0:fbdae7e6d805 | 15 | #include "SerialCom.h" |
borlanic | 0:fbdae7e6d805 | 16 | |
borlanic | 0:fbdae7e6d805 | 17 | |
borlanic | 0:fbdae7e6d805 | 18 | /** |
borlanic | 0:fbdae7e6d805 | 19 | * This is a device driver class for the ST LSM9DS1 inertial measurement unit. |
borlanic | 0:fbdae7e6d805 | 20 | */ |
borlanic | 0:fbdae7e6d805 | 21 | class IMU { |
borlanic | 0:fbdae7e6d805 | 22 | |
borlanic | 0:fbdae7e6d805 | 23 | public: |
borlanic | 0:fbdae7e6d805 | 24 | |
borlanic | 0:fbdae7e6d805 | 25 | IMU(SPI& spi, DigitalOut& csAG, DigitalOut& csM); |
borlanic | 0:fbdae7e6d805 | 26 | virtual ~IMU(); |
borlanic | 0:fbdae7e6d805 | 27 | float readGyroX(); |
borlanic | 0:fbdae7e6d805 | 28 | float readGyroY(); |
borlanic | 0:fbdae7e6d805 | 29 | float readGyroZ(); |
borlanic | 0:fbdae7e6d805 | 30 | float readAccelerationX(); |
borlanic | 0:fbdae7e6d805 | 31 | float readAccelerationY(); |
borlanic | 0:fbdae7e6d805 | 32 | float readAccelerationZ(); |
borlanic | 0:fbdae7e6d805 | 33 | float readMagnetometerX(); |
borlanic | 0:fbdae7e6d805 | 34 | float readMagnetometerY(); |
borlanic | 0:fbdae7e6d805 | 35 | float readMagnetometerZ(); |
borlanic | 0:fbdae7e6d805 | 36 | // Nick ================= |
borlanic | 0:fbdae7e6d805 | 37 | float getGammaX(); |
borlanic | 0:fbdae7e6d805 | 38 | float getGammaY(); |
borlanic | 0:fbdae7e6d805 | 39 | float getGammaZ(); |
borlanic | 0:fbdae7e6d805 | 40 | float getDGammaX(); |
borlanic | 0:fbdae7e6d805 | 41 | float getDGammaY(); |
borlanic | 0:fbdae7e6d805 | 42 | float getDGammaZ(); |
borlanic | 0:fbdae7e6d805 | 43 | |
borlanic | 0:fbdae7e6d805 | 44 | private: |
borlanic | 0:fbdae7e6d805 | 45 | |
borlanic | 0:fbdae7e6d805 | 46 | static const uint8_t WHO_AM_I = 0x0F; |
borlanic | 0:fbdae7e6d805 | 47 | static const uint8_t CTRL_REG1_G = 0x10; |
borlanic | 0:fbdae7e6d805 | 48 | static const uint8_t CTRL_REG2_G = 0x11; |
borlanic | 0:fbdae7e6d805 | 49 | static const uint8_t CTRL_REG3_G = 0x12; |
borlanic | 0:fbdae7e6d805 | 50 | static const uint8_t OUT_X_L_G = 0x18; |
borlanic | 0:fbdae7e6d805 | 51 | static const uint8_t OUT_X_H_G = 0x19; |
borlanic | 0:fbdae7e6d805 | 52 | static const uint8_t OUT_Y_L_G = 0x1A; |
borlanic | 0:fbdae7e6d805 | 53 | static const uint8_t OUT_Y_H_G = 0x1B; |
borlanic | 0:fbdae7e6d805 | 54 | static const uint8_t OUT_Z_L_G = 0x1C; |
borlanic | 0:fbdae7e6d805 | 55 | static const uint8_t OUT_Z_H_G = 0x1D; |
borlanic | 0:fbdae7e6d805 | 56 | static const uint8_t CTRL_REG4 = 0x1E; |
borlanic | 0:fbdae7e6d805 | 57 | static const uint8_t CTRL_REG5_XL = 0x1F; |
borlanic | 0:fbdae7e6d805 | 58 | static const uint8_t CTRL_REG6_XL = 0x20; |
borlanic | 0:fbdae7e6d805 | 59 | static const uint8_t CTRL_REG7_XL = 0x21; |
borlanic | 0:fbdae7e6d805 | 60 | static const uint8_t CTRL_REG8 = 0x22; |
borlanic | 0:fbdae7e6d805 | 61 | static const uint8_t CTRL_REG9 = 0x23; |
borlanic | 0:fbdae7e6d805 | 62 | static const uint8_t CTRL_REG10 = 0x24; |
borlanic | 0:fbdae7e6d805 | 63 | static const uint8_t OUT_X_L_XL = 0x28; |
borlanic | 0:fbdae7e6d805 | 64 | static const uint8_t OUT_X_H_XL = 0x29; |
borlanic | 0:fbdae7e6d805 | 65 | static const uint8_t OUT_Y_L_XL = 0x2A; |
borlanic | 0:fbdae7e6d805 | 66 | static const uint8_t OUT_Y_H_XL = 0x2B; |
borlanic | 0:fbdae7e6d805 | 67 | static const uint8_t OUT_Z_L_XL = 0x2C; |
borlanic | 0:fbdae7e6d805 | 68 | static const uint8_t OUT_Z_H_XL = 0x2D; |
borlanic | 0:fbdae7e6d805 | 69 | |
borlanic | 0:fbdae7e6d805 | 70 | static const uint8_t WHO_AM_I_M = 0x0F; |
borlanic | 0:fbdae7e6d805 | 71 | static const uint8_t CTRL_REG1_M = 0x20; |
borlanic | 0:fbdae7e6d805 | 72 | static const uint8_t CTRL_REG2_M = 0x21; |
borlanic | 0:fbdae7e6d805 | 73 | static const uint8_t CTRL_REG3_M = 0x22; |
borlanic | 0:fbdae7e6d805 | 74 | static const uint8_t CTRL_REG4_M = 0x23; |
borlanic | 0:fbdae7e6d805 | 75 | static const uint8_t CTRL_REG5_M = 0x24; |
borlanic | 0:fbdae7e6d805 | 76 | static const uint8_t OUT_X_L_M = 0x28; |
borlanic | 0:fbdae7e6d805 | 77 | static const uint8_t OUT_X_H_M = 0x29; |
borlanic | 0:fbdae7e6d805 | 78 | static const uint8_t OUT_Y_L_M = 0x2A; |
borlanic | 0:fbdae7e6d805 | 79 | static const uint8_t OUT_Y_H_M = 0x2B; |
borlanic | 0:fbdae7e6d805 | 80 | static const uint8_t OUT_Z_L_M = 0x2C; |
borlanic | 0:fbdae7e6d805 | 81 | static const uint8_t OUT_Z_H_M = 0x2D; |
borlanic | 0:fbdae7e6d805 | 82 | |
borlanic | 0:fbdae7e6d805 | 83 | static const float M_PI; |
borlanic | 0:fbdae7e6d805 | 84 | static const float SAMPLE_TIME; |
borlanic | 0:fbdae7e6d805 | 85 | static const float STD_ALPHA; |
borlanic | 0:fbdae7e6d805 | 86 | static const float STD_OMEGA; |
borlanic | 0:fbdae7e6d805 | 87 | static const uint32_t STACK_SIZE = 4096; // stack size of thread, given in [bytes] |
borlanic | 0:fbdae7e6d805 | 88 | |
borlanic | 0:fbdae7e6d805 | 89 | float gammaX; // angle in X from kalman-Filter |
borlanic | 0:fbdae7e6d805 | 90 | float gammaY; // angle in Y from kalman-Filter |
borlanic | 0:fbdae7e6d805 | 91 | float gammaZ; // angle in Z from kalman-Filter |
borlanic | 0:fbdae7e6d805 | 92 | float d_gammaX; // angular velocity in X from kalman-Filter |
borlanic | 0:fbdae7e6d805 | 93 | float d_gammaY; // angular velocity in Y from kalman-Filter |
borlanic | 0:fbdae7e6d805 | 94 | float d_gammaZ; // angular velocity in Z from kalman-Filter |
borlanic | 0:fbdae7e6d805 | 95 | |
borlanic | 0:fbdae7e6d805 | 96 | LowpassFilter gammaXFilter; |
borlanic | 0:fbdae7e6d805 | 97 | LowpassFilter gammaYFilter; |
borlanic | 0:fbdae7e6d805 | 98 | LowpassFilter d_gammaXFilter; |
borlanic | 0:fbdae7e6d805 | 99 | LowpassFilter d_gammaYFilter; |
borlanic | 0:fbdae7e6d805 | 100 | |
borlanic | 0:fbdae7e6d805 | 101 | Signal signal; |
borlanic | 0:fbdae7e6d805 | 102 | Thread thread; |
borlanic | 0:fbdae7e6d805 | 103 | Ticker ticker; |
borlanic | 0:fbdae7e6d805 | 104 | Mutex mutex; // mutex to lock critical sections |
borlanic | 0:fbdae7e6d805 | 105 | |
borlanic | 0:fbdae7e6d805 | 106 | void sendSignal(); |
borlanic | 0:fbdae7e6d805 | 107 | void kalman(); |
borlanic | 0:fbdae7e6d805 | 108 | |
borlanic | 0:fbdae7e6d805 | 109 | SPI& spi; |
borlanic | 0:fbdae7e6d805 | 110 | DigitalOut& csAG; |
borlanic | 0:fbdae7e6d805 | 111 | DigitalOut& csM; |
borlanic | 0:fbdae7e6d805 | 112 | |
borlanic | 0:fbdae7e6d805 | 113 | void writeRegister(DigitalOut& cs, uint8_t address, uint8_t value); |
borlanic | 0:fbdae7e6d805 | 114 | uint8_t readRegister(DigitalOut& cs, uint8_t address); |
borlanic | 0:fbdae7e6d805 | 115 | }; |
borlanic | 0:fbdae7e6d805 | 116 | |
borlanic | 0:fbdae7e6d805 | 117 | #endif /* IMU_H_ */ |
borlanic | 0:fbdae7e6d805 | 118 | |
borlanic | 0:fbdae7e6d805 | 119 | |
borlanic | 0:fbdae7e6d805 | 120 |