Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
IMU.h
00001 /* 00002 * IMU.h 00003 * Copyright (c) 2018, ZHAW 00004 * All rights reserved. 00005 */ 00006 00007 #ifndef IMU_H_ 00008 #define IMU_H_ 00009 00010 #include <cstdlib> 00011 #include <stdint.h> 00012 #include "mbed.h" 00013 00014 00015 /** 00016 * This is a device driver class for the ST LSM9DS1 inertial measurement unit. 00017 */ 00018 class IMU { 00019 00020 public: 00021 00022 IMU(SPI& spi, DigitalOut& csAG, DigitalOut& csM); 00023 virtual ~IMU(); 00024 float readGyroX(); 00025 float readGyroY(); 00026 float readGyroZ(); 00027 float readAccelerationX(); 00028 float readAccelerationY(); 00029 float readAccelerationZ(); 00030 float readMagnetometerX(); 00031 float readMagnetometerY(); 00032 float readMagnetometerZ(); 00033 // Nick ================= 00034 float getGammaX(); 00035 float getGammaY(); 00036 float getGammaZ(); 00037 float getDGammaX(); 00038 float getDGammaY(); 00039 float getDGammaZ(); 00040 void kalman(); 00041 //======================= 00042 00043 private: 00044 00045 static const uint8_t WHO_AM_I = 0x0F; 00046 static const uint8_t CTRL_REG1_G = 0x10; 00047 static const uint8_t CTRL_REG2_G = 0x11; 00048 static const uint8_t CTRL_REG3_G = 0x12; 00049 static const uint8_t OUT_X_L_G = 0x18; 00050 static const uint8_t OUT_X_H_G = 0x19; 00051 static const uint8_t OUT_Y_L_G = 0x1A; 00052 static const uint8_t OUT_Y_H_G = 0x1B; 00053 static const uint8_t OUT_Z_L_G = 0x1C; 00054 static const uint8_t OUT_Z_H_G = 0x1D; 00055 static const uint8_t CTRL_REG4 = 0x1E; 00056 static const uint8_t CTRL_REG5_XL = 0x1F; 00057 static const uint8_t CTRL_REG6_XL = 0x20; 00058 static const uint8_t CTRL_REG7_XL = 0x21; 00059 static const uint8_t CTRL_REG8 = 0x22; 00060 static const uint8_t CTRL_REG9 = 0x23; 00061 static const uint8_t CTRL_REG10 = 0x24; 00062 static const uint8_t OUT_X_L_XL = 0x28; 00063 static const uint8_t OUT_X_H_XL = 0x29; 00064 static const uint8_t OUT_Y_L_XL = 0x2A; 00065 static const uint8_t OUT_Y_H_XL = 0x2B; 00066 static const uint8_t OUT_Z_L_XL = 0x2C; 00067 static const uint8_t OUT_Z_H_XL = 0x2D; 00068 00069 static const uint8_t WHO_AM_I_M = 0x0F; 00070 static const uint8_t CTRL_REG1_M = 0x20; 00071 static const uint8_t CTRL_REG2_M = 0x21; 00072 static const uint8_t CTRL_REG3_M = 0x22; 00073 static const uint8_t CTRL_REG4_M = 0x23; 00074 static const uint8_t CTRL_REG5_M = 0x24; 00075 static const uint8_t OUT_X_L_M = 0x28; 00076 static const uint8_t OUT_X_H_M = 0x29; 00077 static const uint8_t OUT_Y_L_M = 0x2A; 00078 static const uint8_t OUT_Y_H_M = 0x2B; 00079 static const uint8_t OUT_Z_L_M = 0x2C; 00080 static const uint8_t OUT_Z_H_M = 0x2D; 00081 00082 static const float M_PI; 00083 static const float SAMPLE_TIME; 00084 static const float STD_ALPHA; 00085 static const float STD_OMEGA; 00086 00087 float gammaX; // angle in X from kalman-Filter 00088 float gammaY; // angle in Y from kalman-Filter 00089 float gammaZ; // angle in Z from kalman-Filter 00090 float d_gammaX; // angular velocity in X from kalman-Filter 00091 float d_gammaY; // angular velocity in Y from kalman-Filter 00092 float d_gammaZ; // angular velocity in Z from kalman-Filter 00093 00094 Thread thread; 00095 Ticker ticker; 00096 00097 00098 SPI& spi; 00099 DigitalOut& csAG; 00100 DigitalOut& csM; 00101 00102 void writeRegister(DigitalOut& cs, uint8_t address, uint8_t value); 00103 uint8_t readRegister(DigitalOut& cs, uint8_t address); 00104 }; 00105 00106 #endif /* IMU_H_ */ 00107
Generated on Tue Jul 12 2022 12:21:56 by
1.7.2