Framework of classes and program to measure tilt angles using accelerometers
Fork of tilt_angles by
ENGO333_MPU9150.h
00001 /** 00002 * File : ENGO333_MPU9150.h 00003 * Created by : Chandra Tjhai 00004 * Created on : September 19, 2016 00005 * 00006 * Description : 00007 * This library is created for ENGO 333 class. The inertial sensor needs to be 00008 * mounted on the mbed Application Board. The I2C connection is automatically 00009 * set to p28 (SDA) and p27 (SCL). 00010 */ 00011 00012 #ifndef ENGO333_MPU9150_H 00013 #define ENGO333_MPU9150_H 00014 00015 #include "ENGO333_I2C.h" 00016 #include "Tiltmeter.h" 00017 00018 /** 00019 * Define Macros: Device I2C slave addresses (R/W) 00020 */ 00021 #define MPU9150_ADDRESS (0x68 << 1) 00022 00023 /** 00024 * Define Macros: Configuration Registers 00025 */ 00026 #define MPU9150_CONFIG_REG 0x1A 00027 #define MPU9150_ACCEL_CONFIG_REG 0x1C 00028 #define MPU9150_INT_STATUS_REG 0x3A 00029 #define MPU9150_INT_PIN_CFG_REG 0x37 00030 #define MPU9150_PWR_MGMT_1_REG 0x6B 00031 #define MPU9150_WHO_AM_I_REG 0x75 00032 00033 /** 00034 * Define Macros: Measurement Data Registers 00035 */ 00036 #define MPU9150_ACCEL_XOUT_H_REG 0x3B 00037 #define MPU9150_ACCEL_YOUT_H_REG 0x3D 00038 #define MPU9150_ACCEL_ZOUT_H_REG 0x3F 00039 00040 /** 00041 * Define Macros: IMU Definitions 00042 */ 00043 #define MPU9150_SLEEP_BIT 6 00044 #define MPU9150_ACCEL_RANGE_2G 0 00045 #define MPU9150_ACCEL_RANGE_4G 1 00046 #define MPU9150_ACCEL_RANGE_8G 2 00047 #define MPU9150_ACCEL_RANGE_16G 3 00048 #define MPU9150_I_AM 0x68 00049 #define MPU9150_I2C_FAST_MODE 400000 00050 #define MPU9150_I2C_STD_MODE 100000 00051 00052 /** 00053 * Class 00054 * A class to handle MPU-9150 9-DOF sensor 00055 */ 00056 class ENGO333_MPU9150 00057 { 00058 private: 00059 ENGO333_I2C i2c; 00060 float measAccel[3]; // Measured acceleration values in units of m/s/s 00061 00062 public: 00063 /** 00064 * Default Constructor 00065 * Once called, triggering device initialization and set data variables to 00066 * zero. Accelerometer is set to +-2G by default. 00067 */ 00068 ENGO333_MPU9150(); 00069 00070 /** 00071 * Function : 00072 * Enable/disable device sleep mode 00073 * 00074 * Argument : 00075 * state = TRUE/FALSE 00076 * 00077 * Return : 00078 * NONE 00079 */ 00080 void setSleepMode(bool state); 00081 00082 /** 00083 * Function : 00084 * Test device's accelerometer connection 00085 * 00086 * Argument : 00087 * NONE 00088 * 00089 * Return : 00090 * Return TRUE if connection is good, otherwise FALSSE 00091 */ 00092 virtual bool TestConnection(); 00093 00094 /** 00095 * Function : 00096 * Set accelerometer full scale range, see MPU9150_ACCEL_RANGE_XG 00097 * 00098 * Argument : 00099 * range = values of MPU9150_ACCEL_RANGE_XG 00100 * 00101 * Return : 00102 * NONE 00103 */ 00104 void setAccelRange(char range); 00105 00106 /** 00107 * Function : 00108 * Read raw accelerometer data, 3 axes 00109 * 00110 * Argument : 00111 * NONE 00112 * 00113 * Return : 00114 * NONE 00115 */ 00116 virtual void ReadAccelerometers(); 00117 00118 /** 00119 * Function : 00120 * Get raw X-axis acceleration 00121 * 00122 * Argument : 00123 * NONE 00124 * 00125 * Return : 00126 * Raw X-axis acceleration 00127 */ 00128 virtual float GetAccelX() const; 00129 00130 /** 00131 * Function : 00132 * Get raw Y-axis acceleration 00133 * 00134 * Argument : 00135 * NONE 00136 * 00137 * Return : 00138 * Raw Y-axis acceleration 00139 */ 00140 virtual float GetAccelY() const; 00141 00142 /** 00143 * Function : 00144 * Get raw Z-axis acceleration 00145 * 00146 * Argument : 00147 * NONE 00148 * 00149 * Return : 00150 * Raw Z-axis acceleration 00151 */ 00152 virtual float GetAccelZ() const; 00153 00154 }; 00155 00156 #endif 00157 00158
Generated on Sat Jul 16 2022 15:16:04 by
1.7.2
