Nicolas Borla
/
ROME2_Robot_Firmware
ROME2 Robot Firmware
IMU.h@0:4beb2ea291ec, 2020-03-16 (annotated)
- Committer:
- boro
- Date:
- Mon Mar 16 13:12:31 2020 +0000
- Revision:
- 0:4beb2ea291ec
a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
boro | 0:4beb2ea291ec | 1 | /* |
boro | 0:4beb2ea291ec | 2 | * IMU.h |
boro | 0:4beb2ea291ec | 3 | * Copyright (c) 2018, ZHAW |
boro | 0:4beb2ea291ec | 4 | * All rights reserved. |
boro | 0:4beb2ea291ec | 5 | */ |
boro | 0:4beb2ea291ec | 6 | |
boro | 0:4beb2ea291ec | 7 | /* |
boro | 0:4beb2ea291ec | 8 | * Public variable for gain and offset of acc and gyro |
boro | 0:4beb2ea291ec | 9 | * |
boro | 0:4beb2ea291ec | 10 | * for the teststand with 2 IMUs |
boro | 0:4beb2ea291ec | 11 | */ |
boro | 0:4beb2ea291ec | 12 | |
boro | 0:4beb2ea291ec | 13 | #ifndef IMU_H_ |
boro | 0:4beb2ea291ec | 14 | #define IMU_H_ |
boro | 0:4beb2ea291ec | 15 | |
boro | 0:4beb2ea291ec | 16 | #include <cstdlib> |
boro | 0:4beb2ea291ec | 17 | #include <stdint.h> |
boro | 0:4beb2ea291ec | 18 | #include "mbed.h" |
boro | 0:4beb2ea291ec | 19 | |
boro | 0:4beb2ea291ec | 20 | |
boro | 0:4beb2ea291ec | 21 | /** |
boro | 0:4beb2ea291ec | 22 | * This is a device driver class for the ST LSM9DS1 inertial measurement unit. |
boro | 0:4beb2ea291ec | 23 | */ |
boro | 0:4beb2ea291ec | 24 | class IMU { |
boro | 0:4beb2ea291ec | 25 | |
boro | 0:4beb2ea291ec | 26 | public: |
boro | 0:4beb2ea291ec | 27 | |
boro | 0:4beb2ea291ec | 28 | IMU(SPI& spi, DigitalOut& csAG, DigitalOut& csM); |
boro | 0:4beb2ea291ec | 29 | virtual ~IMU(); |
boro | 0:4beb2ea291ec | 30 | float readGyroX(); |
boro | 0:4beb2ea291ec | 31 | float readGyroY(); |
boro | 0:4beb2ea291ec | 32 | float readGyroZ(); |
boro | 0:4beb2ea291ec | 33 | float readAccelerationX(); |
boro | 0:4beb2ea291ec | 34 | float readAccelerationY(); |
boro | 0:4beb2ea291ec | 35 | float readAccelerationZ(); |
boro | 0:4beb2ea291ec | 36 | float readMagnetometerX(); |
boro | 0:4beb2ea291ec | 37 | float readMagnetometerY(); |
boro | 0:4beb2ea291ec | 38 | float readMagnetometerZ(); |
boro | 0:4beb2ea291ec | 39 | |
boro | 0:4beb2ea291ec | 40 | float gainAx; |
boro | 0:4beb2ea291ec | 41 | float gainAy; |
boro | 0:4beb2ea291ec | 42 | float gainAz; |
boro | 0:4beb2ea291ec | 43 | float gainGx; |
boro | 0:4beb2ea291ec | 44 | float gainGy; |
boro | 0:4beb2ea291ec | 45 | float gainGz; |
boro | 0:4beb2ea291ec | 46 | |
boro | 0:4beb2ea291ec | 47 | float offsAx; |
boro | 0:4beb2ea291ec | 48 | float offsAy; |
boro | 0:4beb2ea291ec | 49 | float offsAz; |
boro | 0:4beb2ea291ec | 50 | float offsGx; |
boro | 0:4beb2ea291ec | 51 | float offsGy; |
boro | 0:4beb2ea291ec | 52 | float offsGz; |
boro | 0:4beb2ea291ec | 53 | |
boro | 0:4beb2ea291ec | 54 | private: |
boro | 0:4beb2ea291ec | 55 | |
boro | 0:4beb2ea291ec | 56 | static const uint8_t WHO_AM_I = 0x0F; |
boro | 0:4beb2ea291ec | 57 | static const uint8_t CTRL_REG1_G = 0x10; |
boro | 0:4beb2ea291ec | 58 | static const uint8_t CTRL_REG2_G = 0x11; |
boro | 0:4beb2ea291ec | 59 | static const uint8_t CTRL_REG3_G = 0x12; |
boro | 0:4beb2ea291ec | 60 | static const uint8_t OUT_X_L_G = 0x18; |
boro | 0:4beb2ea291ec | 61 | static const uint8_t OUT_X_H_G = 0x19; |
boro | 0:4beb2ea291ec | 62 | static const uint8_t OUT_Y_L_G = 0x1A; |
boro | 0:4beb2ea291ec | 63 | static const uint8_t OUT_Y_H_G = 0x1B; |
boro | 0:4beb2ea291ec | 64 | static const uint8_t OUT_Z_L_G = 0x1C; |
boro | 0:4beb2ea291ec | 65 | static const uint8_t OUT_Z_H_G = 0x1D; |
boro | 0:4beb2ea291ec | 66 | static const uint8_t CTRL_REG4 = 0x1E; |
boro | 0:4beb2ea291ec | 67 | static const uint8_t CTRL_REG5_XL = 0x1F; |
boro | 0:4beb2ea291ec | 68 | static const uint8_t CTRL_REG6_XL = 0x20; |
boro | 0:4beb2ea291ec | 69 | static const uint8_t CTRL_REG7_XL = 0x21; |
boro | 0:4beb2ea291ec | 70 | static const uint8_t CTRL_REG8 = 0x22; |
boro | 0:4beb2ea291ec | 71 | static const uint8_t CTRL_REG9 = 0x23; |
boro | 0:4beb2ea291ec | 72 | static const uint8_t CTRL_REG10 = 0x24; |
boro | 0:4beb2ea291ec | 73 | static const uint8_t OUT_X_L_XL = 0x28; |
boro | 0:4beb2ea291ec | 74 | static const uint8_t OUT_X_H_XL = 0x29; |
boro | 0:4beb2ea291ec | 75 | static const uint8_t OUT_Y_L_XL = 0x2A; |
boro | 0:4beb2ea291ec | 76 | static const uint8_t OUT_Y_H_XL = 0x2B; |
boro | 0:4beb2ea291ec | 77 | static const uint8_t OUT_Z_L_XL = 0x2C; |
boro | 0:4beb2ea291ec | 78 | static const uint8_t OUT_Z_H_XL = 0x2D; |
boro | 0:4beb2ea291ec | 79 | |
boro | 0:4beb2ea291ec | 80 | static const uint8_t WHO_AM_I_M = 0x0F; |
boro | 0:4beb2ea291ec | 81 | static const uint8_t CTRL_REG1_M = 0x20; |
boro | 0:4beb2ea291ec | 82 | static const uint8_t CTRL_REG2_M = 0x21; |
boro | 0:4beb2ea291ec | 83 | static const uint8_t CTRL_REG3_M = 0x22; |
boro | 0:4beb2ea291ec | 84 | static const uint8_t CTRL_REG4_M = 0x23; |
boro | 0:4beb2ea291ec | 85 | static const uint8_t CTRL_REG5_M = 0x24; |
boro | 0:4beb2ea291ec | 86 | static const uint8_t OUT_X_L_M = 0x28; |
boro | 0:4beb2ea291ec | 87 | static const uint8_t OUT_X_H_M = 0x29; |
boro | 0:4beb2ea291ec | 88 | static const uint8_t OUT_Y_L_M = 0x2A; |
boro | 0:4beb2ea291ec | 89 | static const uint8_t OUT_Y_H_M = 0x2B; |
boro | 0:4beb2ea291ec | 90 | static const uint8_t OUT_Z_L_M = 0x2C; |
boro | 0:4beb2ea291ec | 91 | static const uint8_t OUT_Z_H_M = 0x2D; |
boro | 0:4beb2ea291ec | 92 | |
boro | 0:4beb2ea291ec | 93 | static const float M_PI; |
boro | 0:4beb2ea291ec | 94 | static const float SAMPLE_TIME; |
boro | 0:4beb2ea291ec | 95 | static const float STD_ALPHA; |
boro | 0:4beb2ea291ec | 96 | static const float STD_OMEGA; |
boro | 0:4beb2ea291ec | 97 | static const uint32_t STACK_SIZE = 4096; // stack size of thread, given in [bytes] |
boro | 0:4beb2ea291ec | 98 | |
boro | 0:4beb2ea291ec | 99 | SPI& spi; |
boro | 0:4beb2ea291ec | 100 | DigitalOut& csAG; |
boro | 0:4beb2ea291ec | 101 | DigitalOut& csM; |
boro | 0:4beb2ea291ec | 102 | |
boro | 0:4beb2ea291ec | 103 | void writeRegister(DigitalOut& cs, uint8_t address, uint8_t value); |
boro | 0:4beb2ea291ec | 104 | uint8_t readRegister(DigitalOut& cs, uint8_t address); |
boro | 0:4beb2ea291ec | 105 | }; |
boro | 0:4beb2ea291ec | 106 | |
boro | 0:4beb2ea291ec | 107 | #endif /* IMU_H_ */ |
boro | 0:4beb2ea291ec | 108 | |
boro | 0:4beb2ea291ec | 109 | |
boro | 0:4beb2ea291ec | 110 | |
boro | 0:4beb2ea291ec | 111 | |
boro | 0:4beb2ea291ec | 112 | |
boro | 0:4beb2ea291ec | 113 |