Framework of classes and program to measure tilt angles using accelerometers
Fork of tilt_angles by
ENGO333_MMA7660.h
00001 /** 00002 * File : ENGO333_MMA7660.h 00003 * Created by : Chandra Tjhai 00004 * Created on : September 10, 2016 00005 * 00006 * Description : 00007 * This library is created for ENGO 333 class. The accelerometer is mounted 00008 * on the mbed Application Board. The I2C connection is permanently set to p28 00009 * (SDA) and p27 (SCL). 00010 */ 00011 00012 #ifndef ENGO333_MMA7660_H 00013 #define ENGO333_MMA7660_H 00014 00015 #include "ENGO333_I2C.h" 00016 #include "Tiltmeter.h" 00017 00018 // Sensor I2C address 00019 #define MMA7660_ADDRESS 0x98 00020 00021 // Define sensor registers 00022 #define MMA7660_XOUT_REG 0x00 00023 #define MMA7660_YOUT_REG 0x01 00024 #define MMA7660_ZOUT_REG 0x02 00025 #define MMA7660_TILT_REG 0x03 00026 #define MMA7660_SRST_REG 0x04 00027 #define MMA7660_SPCNT_REG 0x05 00028 #define MMA7660_INTSU_REG 0x06 00029 #define MMA7660_MODE_REG 0x07 00030 #define MMA7660_SR_REG 0x08 00031 #define MMA7660_PDET_REF 0x09 00032 #define MMA7660_PD_REG 0x0A 00033 00034 // Define acceleration scale 00035 #define MMA7660_SCALE (21.33) 00036 00037 // Define AMSR values 00038 typedef enum 00039 { 00040 MMA7660_AMSR120 = 0, 00041 MMA7660_AMSR64 = 1, 00042 MMA7660_AMSR32 = 2, 00043 MMA7660_AMSR16 = 3, 00044 MMA7660_AMSR8 = 4, 00045 MMA7660_AMSR4 = 5, 00046 MMA7660_AMSR2 = 6, 00047 MMA7660_AMSR1 = 7 00048 }MMA7660_AMSR_t; 00049 00050 /** 00051 * Class 00052 * A class to handle MMA7660 3-DOF accelerometer 00053 */ 00054 class ENGO333_MMA7660 00055 { 00056 private: 00057 ENGO333_I2C i2c; // I2C communication connection 00058 float measAccel[3]; // Measured acceleration values in units of m/s/s 00059 00060 public: 00061 /** 00062 * Default Constructor 00063 * Once called, trigger active mode and set MMA7660_AMSR8 00064 */ 00065 ENGO333_MMA7660(); 00066 00067 /** 00068 * Function : 00069 * Test device's accelerometer connection. MMA7660 does not have identifier 00070 * registers. Thus, this function will simply take measurements and check 00071 * their validity. 00072 * 00073 * Argument : 00074 * NONE 00075 * 00076 * Return : 00077 * Return TRUE if connection is good, otherwise FALSSE 00078 */ 00079 virtual bool TestConnection(); 00080 00081 00082 private: 00083 00084 // Read the accelerometer data and store the values for later use. You can access the values by 00085 // calling the GetAccelX(), GetAccelY() and/or GetAccelZ(); 00086 // 00087 // Arguments: 00088 // None 00089 // 00090 // Returns: 00091 // Nothing 00092 // 00093 // Remarks: 00094 // The data will be stored in the 'MeasuredAccel' member variable in units of m/s/s 00095 virtual void ReadAccelerometers(); 00096 00097 00098 // Get the most recently measured X-axis acceleration as stored during the last call to 00099 // ReadAccelerometer() 00100 // 00101 // Arguments: 00102 // None 00103 // 00104 // Returns: 00105 // The function returns the most recently measured X-axis acceleration in units of m/s/s 00106 virtual float GetAccelX() const; 00107 00108 00109 // Get the most recently measured Y-axis acceleration as stored during the last call to 00110 // ReadAccelerometer() 00111 // 00112 // Arguments: 00113 // None 00114 // 00115 // Returns: 00116 // The function returns the most recently measured Y-axis acceleration in units of m/s/s 00117 virtual float GetAccelY() const; 00118 00119 00120 // Get the most recently measured Z-axis acceleration as stored during the last call to 00121 // ReadAccelerometer() 00122 // 00123 // Arguments: 00124 // None 00125 // 00126 // Returns: 00127 // The function returns the most recently measured Z-axis acceleration in units of m/s/s 00128 virtual float GetAccelZ() const; 00129 00130 00131 // Set the device to 'active' mode 00132 // 00133 // Arguments: 00134 // None 00135 // 00136 // Returns: 00137 // Nothing 00138 void SetActiveMode(); 00139 00140 00141 // Set the device sampling rate through AM bits, see MMA7660_SR_REG 00142 // 00143 // Arguments: 00144 // samplingRate = setting of AM bits in MMA7660_SR_REG 00145 // 00146 // Returns: 00147 // Nothing 00148 void SetSamplingRateAM(MMA7660_AMSR_t samplingRate); 00149 00150 }; 00151 00152 #endif 00153
Generated on Sat Jul 16 2022 15:16:04 by
1.7.2
