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