![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
IMU measurement + Speed controller
IMU.h@1:17fdd812cb8d, 2019-05-30 (annotated)
- Committer:
- boro
- Date:
- Thu May 30 13:21:44 2019 +0000
- Revision:
- 1:17fdd812cb8d
- Parent:
- 0:5a93e4916fb1
a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
boro | 0:5a93e4916fb1 | 1 | /* |
boro | 0:5a93e4916fb1 | 2 | * IMU.h |
boro | 0:5a93e4916fb1 | 3 | * Copyright (c) 2018, ZHAW |
boro | 0:5a93e4916fb1 | 4 | * All rights reserved. |
boro | 0:5a93e4916fb1 | 5 | */ |
boro | 0:5a93e4916fb1 | 6 | |
boro | 0:5a93e4916fb1 | 7 | #ifndef IMU_H_ |
boro | 0:5a93e4916fb1 | 8 | #define IMU_H_ |
boro | 0:5a93e4916fb1 | 9 | |
boro | 0:5a93e4916fb1 | 10 | #include <cstdlib> |
boro | 0:5a93e4916fb1 | 11 | #include <stdint.h> |
boro | 0:5a93e4916fb1 | 12 | #include "mbed.h" |
boro | 0:5a93e4916fb1 | 13 | |
boro | 0:5a93e4916fb1 | 14 | |
boro | 0:5a93e4916fb1 | 15 | /** |
boro | 0:5a93e4916fb1 | 16 | * This is a device driver class for the ST LSM9DS1 inertial measurement unit. |
boro | 0:5a93e4916fb1 | 17 | */ |
boro | 0:5a93e4916fb1 | 18 | class IMU { |
boro | 0:5a93e4916fb1 | 19 | |
boro | 0:5a93e4916fb1 | 20 | public: |
boro | 0:5a93e4916fb1 | 21 | |
boro | 0:5a93e4916fb1 | 22 | IMU(SPI& spi, DigitalOut& csAG, DigitalOut& csM); |
boro | 0:5a93e4916fb1 | 23 | virtual ~IMU(); |
boro | 0:5a93e4916fb1 | 24 | float readGyroX(); |
boro | 0:5a93e4916fb1 | 25 | float readGyroY(); |
boro | 0:5a93e4916fb1 | 26 | float readGyroZ(); |
boro | 0:5a93e4916fb1 | 27 | float readAccelerationX(); |
boro | 0:5a93e4916fb1 | 28 | float readAccelerationY(); |
boro | 0:5a93e4916fb1 | 29 | float readAccelerationZ(); |
boro | 0:5a93e4916fb1 | 30 | float readMagnetometerX(); |
boro | 0:5a93e4916fb1 | 31 | float readMagnetometerY(); |
boro | 0:5a93e4916fb1 | 32 | float readMagnetometerZ(); |
boro | 0:5a93e4916fb1 | 33 | |
boro | 0:5a93e4916fb1 | 34 | private: |
boro | 0:5a93e4916fb1 | 35 | |
boro | 0:5a93e4916fb1 | 36 | static const uint8_t WHO_AM_I = 0x0F; |
boro | 0:5a93e4916fb1 | 37 | static const uint8_t CTRL_REG1_G = 0x10; |
boro | 0:5a93e4916fb1 | 38 | static const uint8_t CTRL_REG2_G = 0x11; |
boro | 0:5a93e4916fb1 | 39 | static const uint8_t CTRL_REG3_G = 0x12; |
boro | 0:5a93e4916fb1 | 40 | static const uint8_t OUT_X_L_G = 0x18; |
boro | 0:5a93e4916fb1 | 41 | static const uint8_t OUT_X_H_G = 0x19; |
boro | 0:5a93e4916fb1 | 42 | static const uint8_t OUT_Y_L_G = 0x1A; |
boro | 0:5a93e4916fb1 | 43 | static const uint8_t OUT_Y_H_G = 0x1B; |
boro | 0:5a93e4916fb1 | 44 | static const uint8_t OUT_Z_L_G = 0x1C; |
boro | 0:5a93e4916fb1 | 45 | static const uint8_t OUT_Z_H_G = 0x1D; |
boro | 0:5a93e4916fb1 | 46 | static const uint8_t CTRL_REG4 = 0x1E; |
boro | 0:5a93e4916fb1 | 47 | static const uint8_t CTRL_REG5_XL = 0x1F; |
boro | 0:5a93e4916fb1 | 48 | static const uint8_t CTRL_REG6_XL = 0x20; |
boro | 0:5a93e4916fb1 | 49 | static const uint8_t CTRL_REG7_XL = 0x21; |
boro | 0:5a93e4916fb1 | 50 | static const uint8_t CTRL_REG8 = 0x22; |
boro | 0:5a93e4916fb1 | 51 | static const uint8_t CTRL_REG9 = 0x23; |
boro | 0:5a93e4916fb1 | 52 | static const uint8_t CTRL_REG10 = 0x24; |
boro | 0:5a93e4916fb1 | 53 | static const uint8_t OUT_X_L_XL = 0x28; |
boro | 0:5a93e4916fb1 | 54 | static const uint8_t OUT_X_H_XL = 0x29; |
boro | 0:5a93e4916fb1 | 55 | static const uint8_t OUT_Y_L_XL = 0x2A; |
boro | 0:5a93e4916fb1 | 56 | static const uint8_t OUT_Y_H_XL = 0x2B; |
boro | 0:5a93e4916fb1 | 57 | static const uint8_t OUT_Z_L_XL = 0x2C; |
boro | 0:5a93e4916fb1 | 58 | static const uint8_t OUT_Z_H_XL = 0x2D; |
boro | 0:5a93e4916fb1 | 59 | |
boro | 0:5a93e4916fb1 | 60 | static const uint8_t WHO_AM_I_M = 0x0F; |
boro | 0:5a93e4916fb1 | 61 | static const uint8_t CTRL_REG1_M = 0x20; |
boro | 0:5a93e4916fb1 | 62 | static const uint8_t CTRL_REG2_M = 0x21; |
boro | 0:5a93e4916fb1 | 63 | static const uint8_t CTRL_REG3_M = 0x22; |
boro | 0:5a93e4916fb1 | 64 | static const uint8_t CTRL_REG4_M = 0x23; |
boro | 0:5a93e4916fb1 | 65 | static const uint8_t CTRL_REG5_M = 0x24; |
boro | 0:5a93e4916fb1 | 66 | static const uint8_t OUT_X_L_M = 0x28; |
boro | 0:5a93e4916fb1 | 67 | static const uint8_t OUT_X_H_M = 0x29; |
boro | 0:5a93e4916fb1 | 68 | static const uint8_t OUT_Y_L_M = 0x2A; |
boro | 0:5a93e4916fb1 | 69 | static const uint8_t OUT_Y_H_M = 0x2B; |
boro | 0:5a93e4916fb1 | 70 | static const uint8_t OUT_Z_L_M = 0x2C; |
boro | 0:5a93e4916fb1 | 71 | static const uint8_t OUT_Z_H_M = 0x2D; |
boro | 0:5a93e4916fb1 | 72 | |
boro | 0:5a93e4916fb1 | 73 | static const float M_PI; |
boro | 0:5a93e4916fb1 | 74 | static const float SAMPLE_TIME; |
boro | 0:5a93e4916fb1 | 75 | static const float STD_ALPHA; |
boro | 0:5a93e4916fb1 | 76 | static const float STD_OMEGA; |
boro | 0:5a93e4916fb1 | 77 | static const uint32_t STACK_SIZE = 4096; // stack size of thread, given in [bytes] |
boro | 0:5a93e4916fb1 | 78 | |
boro | 0:5a93e4916fb1 | 79 | |
boro | 0:5a93e4916fb1 | 80 | SPI& spi; |
boro | 0:5a93e4916fb1 | 81 | DigitalOut& csAG; |
boro | 0:5a93e4916fb1 | 82 | DigitalOut& csM; |
boro | 0:5a93e4916fb1 | 83 | |
boro | 0:5a93e4916fb1 | 84 | void writeRegister(DigitalOut& cs, uint8_t address, uint8_t value); |
boro | 0:5a93e4916fb1 | 85 | uint8_t readRegister(DigitalOut& cs, uint8_t address); |
boro | 0:5a93e4916fb1 | 86 | }; |
boro | 0:5a93e4916fb1 | 87 | |
boro | 0:5a93e4916fb1 | 88 | #endif /* IMU_H_ */ |
boro | 0:5a93e4916fb1 | 89 | |
boro | 0:5a93e4916fb1 | 90 | |
boro | 0:5a93e4916fb1 | 91 |