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.
Dependencies: mbed
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 <mbed.h> 00012 #include "LowpassFilter.h" 00013 00014 /** 00015 * This is a device driver class for the ST LSM9DS0 inertial measurement unit. 00016 */ 00017 class IMU { 00018 00019 public: 00020 00021 IMU(SPI& spi, DigitalOut& csG, DigitalOut& csXM); 00022 virtual ~IMU(); 00023 float readGyroX(); 00024 float readGyroY(); 00025 float readGyroZ(); 00026 float readAccelerationX(); 00027 float readAccelerationY(); 00028 float readAccelerationZ(); 00029 float readMagnetometerX(); 00030 float readMagnetometerY(); 00031 float readMagnetometerZ(); 00032 float readHeading(); 00033 00034 private: 00035 00036 static const char WHO_AM_I_G = 0x0F; 00037 static const char CTRL_REG1_G = 0x20; 00038 static const char OUT_X_L_G = 0x28; 00039 static const char OUT_X_H_G = 0x29; 00040 static const char OUT_Y_L_G = 0x2A; 00041 static const char OUT_Y_H_G = 0x2B; 00042 static const char OUT_Z_L_G = 0x2C; 00043 static const char OUT_Z_H_G = 0x2D; 00044 00045 static const char OUT_X_L_M = 0x08; 00046 static const char OUT_X_H_M = 0x09; 00047 static const char OUT_Y_L_M = 0x0A; 00048 static const char OUT_Y_H_M = 0x0B; 00049 static const char OUT_Z_L_M = 0x0C; 00050 static const char OUT_Z_H_M = 0x0D; 00051 static const char WHO_AM_I_XM = 0x0F; 00052 00053 static const char INT_CTRL_REG_M = 0x12; 00054 static const char CTRL_REG0_XM = 0x1F; 00055 static const char CTRL_REG1_XM = 0x20; 00056 static const char CTRL_REG2_XM = 0x21; 00057 static const char CTRL_REG3_XM = 0x22; 00058 static const char CTRL_REG4_XM = 0x23; 00059 static const char CTRL_REG5_XM = 0x24; 00060 static const char CTRL_REG6_XM = 0x25; 00061 static const char CTRL_REG7_XM = 0x26; 00062 00063 static const char OUT_X_L_A = 0x28; 00064 static const char OUT_X_H_A = 0x29; 00065 static const char OUT_Y_L_A = 0x2A; 00066 static const char OUT_Y_H_A = 0x2B; 00067 static const char OUT_Z_L_A = 0x2C; 00068 static const char OUT_Z_H_A = 0x2D; 00069 00070 static const float PERIOD; 00071 static const float PI; 00072 static const float LOWPASS_FILTER_FREQUENCY; 00073 00074 SPI& spi; 00075 DigitalOut& csG; 00076 DigitalOut& csXM; 00077 00078 float magnetometerXMin; 00079 float magnetometerXMax; 00080 float magnetometerYMin; 00081 float magnetometerYMax; 00082 LowpassFilter magnetometerXFilter; 00083 LowpassFilter magnetometerYFilter; 00084 float heading; 00085 Ticker ticker; 00086 00087 void writeRegister(DigitalOut& cs, char address, char value); 00088 char readRegister(DigitalOut& cs, char address); 00089 void run(); 00090 }; 00091 00092 #endif /* IMU_H_ */ 00093
Generated on Sun Jul 23 2023 17:17:31 by
1.7.2