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 00034 private: 00035 00036 static const uint8_t WHO_AM_I = 0x0F; 00037 static const uint8_t CTRL_REG1_G = 0x10; 00038 static const uint8_t CTRL_REG2_G = 0x11; 00039 static const uint8_t CTRL_REG3_G = 0x12; 00040 static const uint8_t OUT_X_L_G = 0x18; 00041 static const uint8_t OUT_X_H_G = 0x19; 00042 static const uint8_t OUT_Y_L_G = 0x1A; 00043 static const uint8_t OUT_Y_H_G = 0x1B; 00044 static const uint8_t OUT_Z_L_G = 0x1C; 00045 static const uint8_t OUT_Z_H_G = 0x1D; 00046 static const uint8_t CTRL_REG4 = 0x1E; 00047 static const uint8_t CTRL_REG5_XL = 0x1F; 00048 static const uint8_t CTRL_REG6_XL = 0x20; 00049 static const uint8_t CTRL_REG7_XL = 0x21; 00050 static const uint8_t CTRL_REG8 = 0x22; 00051 static const uint8_t CTRL_REG9 = 0x23; 00052 static const uint8_t CTRL_REG10 = 0x24; 00053 static const uint8_t OUT_X_L_XL = 0x28; 00054 static const uint8_t OUT_X_H_XL = 0x29; 00055 static const uint8_t OUT_Y_L_XL = 0x2A; 00056 static const uint8_t OUT_Y_H_XL = 0x2B; 00057 static const uint8_t OUT_Z_L_XL = 0x2C; 00058 static const uint8_t OUT_Z_H_XL = 0x2D; 00059 00060 static const uint8_t WHO_AM_I_M = 0x0F; 00061 static const uint8_t CTRL_REG1_M = 0x20; 00062 static const uint8_t CTRL_REG2_M = 0x21; 00063 static const uint8_t CTRL_REG3_M = 0x22; 00064 static const uint8_t CTRL_REG4_M = 0x23; 00065 static const uint8_t CTRL_REG5_M = 0x24; 00066 static const uint8_t OUT_X_L_M = 0x28; 00067 static const uint8_t OUT_X_H_M = 0x29; 00068 static const uint8_t OUT_Y_L_M = 0x2A; 00069 static const uint8_t OUT_Y_H_M = 0x2B; 00070 static const uint8_t OUT_Z_L_M = 0x2C; 00071 static const uint8_t OUT_Z_H_M = 0x2D; 00072 00073 static const float M_PI; 00074 static const float SAMPLE_TIME; 00075 static const float STD_ALPHA; 00076 static const float STD_OMEGA; 00077 static const uint32_t STACK_SIZE = 4096; // stack size of thread, given in [bytes] 00078 00079 00080 SPI& spi; 00081 DigitalOut& csAG; 00082 DigitalOut& csM; 00083 00084 void writeRegister(DigitalOut& cs, uint8_t address, uint8_t value); 00085 uint8_t readRegister(DigitalOut& cs, uint8_t address); 00086 }; 00087 00088 #endif /* IMU_H_ */ 00089 00090 00091
Generated on Sat Jul 16 2022 18:27:07 by
1.7.2