Framework of classes and program to measure tilt angles using accelerometers

Dependencies:   C12832 mbed

Fork of tilt_angles by Mark Petovello

Committer:
mpetovello
Date:
Fri Nov 25 15:18:28 2016 +0000
Revision:
1:64f1aefe1842
Parent:
0:3bffc1862262
Removed MMA7660 library (unnecessary)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mpetovello 0:3bffc1862262 1 /**
mpetovello 0:3bffc1862262 2 * File : ENGO333_MMA7660.h
mpetovello 0:3bffc1862262 3 * Created by : Chandra Tjhai
mpetovello 0:3bffc1862262 4 * Created on : September 10, 2016
mpetovello 0:3bffc1862262 5 *
mpetovello 0:3bffc1862262 6 * Description :
mpetovello 0:3bffc1862262 7 * This library is created for ENGO 333 class. The accelerometer is mounted
mpetovello 0:3bffc1862262 8 * on the mbed Application Board. The I2C connection is permanently set to p28
mpetovello 0:3bffc1862262 9 * (SDA) and p27 (SCL).
mpetovello 0:3bffc1862262 10 */
mpetovello 0:3bffc1862262 11
mpetovello 0:3bffc1862262 12 #ifndef ENGO333_MMA7660_H
mpetovello 0:3bffc1862262 13 #define ENGO333_MMA7660_H
mpetovello 0:3bffc1862262 14
mpetovello 0:3bffc1862262 15 #include "ENGO333_I2C.h"
mpetovello 0:3bffc1862262 16 #include "Tiltmeter.h"
mpetovello 0:3bffc1862262 17
mpetovello 0:3bffc1862262 18 // Sensor I2C address
mpetovello 0:3bffc1862262 19 #define MMA7660_ADDRESS 0x98
mpetovello 0:3bffc1862262 20
mpetovello 0:3bffc1862262 21 // Define sensor registers
mpetovello 0:3bffc1862262 22 #define MMA7660_XOUT_REG 0x00
mpetovello 0:3bffc1862262 23 #define MMA7660_YOUT_REG 0x01
mpetovello 0:3bffc1862262 24 #define MMA7660_ZOUT_REG 0x02
mpetovello 0:3bffc1862262 25 #define MMA7660_TILT_REG 0x03
mpetovello 0:3bffc1862262 26 #define MMA7660_SRST_REG 0x04
mpetovello 0:3bffc1862262 27 #define MMA7660_SPCNT_REG 0x05
mpetovello 0:3bffc1862262 28 #define MMA7660_INTSU_REG 0x06
mpetovello 0:3bffc1862262 29 #define MMA7660_MODE_REG 0x07
mpetovello 0:3bffc1862262 30 #define MMA7660_SR_REG 0x08
mpetovello 0:3bffc1862262 31 #define MMA7660_PDET_REF 0x09
mpetovello 0:3bffc1862262 32 #define MMA7660_PD_REG 0x0A
mpetovello 0:3bffc1862262 33
mpetovello 0:3bffc1862262 34 // Define acceleration scale
mpetovello 0:3bffc1862262 35 #define MMA7660_SCALE (21.33)
mpetovello 0:3bffc1862262 36
mpetovello 0:3bffc1862262 37 // Define AMSR values
mpetovello 0:3bffc1862262 38 typedef enum
mpetovello 0:3bffc1862262 39 {
mpetovello 0:3bffc1862262 40 MMA7660_AMSR120 = 0,
mpetovello 0:3bffc1862262 41 MMA7660_AMSR64 = 1,
mpetovello 0:3bffc1862262 42 MMA7660_AMSR32 = 2,
mpetovello 0:3bffc1862262 43 MMA7660_AMSR16 = 3,
mpetovello 0:3bffc1862262 44 MMA7660_AMSR8 = 4,
mpetovello 0:3bffc1862262 45 MMA7660_AMSR4 = 5,
mpetovello 0:3bffc1862262 46 MMA7660_AMSR2 = 6,
mpetovello 0:3bffc1862262 47 MMA7660_AMSR1 = 7
mpetovello 0:3bffc1862262 48 }MMA7660_AMSR_t;
mpetovello 0:3bffc1862262 49
mpetovello 0:3bffc1862262 50 /**
mpetovello 0:3bffc1862262 51 * Class
mpetovello 0:3bffc1862262 52 * A class to handle MMA7660 3-DOF accelerometer
mpetovello 0:3bffc1862262 53 */
mpetovello 0:3bffc1862262 54 class ENGO333_MMA7660
mpetovello 0:3bffc1862262 55 {
mpetovello 0:3bffc1862262 56 private:
mpetovello 0:3bffc1862262 57 ENGO333_I2C i2c; // I2C communication connection
mpetovello 0:3bffc1862262 58 float measAccel[3]; // Measured acceleration values in units of m/s/s
mpetovello 0:3bffc1862262 59
mpetovello 0:3bffc1862262 60 public:
mpetovello 0:3bffc1862262 61 /**
mpetovello 0:3bffc1862262 62 * Default Constructor
mpetovello 0:3bffc1862262 63 * Once called, trigger active mode and set MMA7660_AMSR8
mpetovello 0:3bffc1862262 64 */
mpetovello 0:3bffc1862262 65 ENGO333_MMA7660();
mpetovello 0:3bffc1862262 66
mpetovello 0:3bffc1862262 67 /**
mpetovello 0:3bffc1862262 68 * Function :
mpetovello 0:3bffc1862262 69 * Test device's accelerometer connection. MMA7660 does not have identifier
mpetovello 0:3bffc1862262 70 * registers. Thus, this function will simply take measurements and check
mpetovello 0:3bffc1862262 71 * their validity.
mpetovello 0:3bffc1862262 72 *
mpetovello 0:3bffc1862262 73 * Argument :
mpetovello 0:3bffc1862262 74 * NONE
mpetovello 0:3bffc1862262 75 *
mpetovello 0:3bffc1862262 76 * Return :
mpetovello 0:3bffc1862262 77 * Return TRUE if connection is good, otherwise FALSSE
mpetovello 0:3bffc1862262 78 */
mpetovello 0:3bffc1862262 79 virtual bool TestConnection();
mpetovello 0:3bffc1862262 80
mpetovello 0:3bffc1862262 81
mpetovello 0:3bffc1862262 82 private:
mpetovello 0:3bffc1862262 83
mpetovello 0:3bffc1862262 84 // Read the accelerometer data and store the values for later use. You can access the values by
mpetovello 0:3bffc1862262 85 // calling the GetAccelX(), GetAccelY() and/or GetAccelZ();
mpetovello 0:3bffc1862262 86 //
mpetovello 0:3bffc1862262 87 // Arguments:
mpetovello 0:3bffc1862262 88 // None
mpetovello 0:3bffc1862262 89 //
mpetovello 0:3bffc1862262 90 // Returns:
mpetovello 0:3bffc1862262 91 // Nothing
mpetovello 0:3bffc1862262 92 //
mpetovello 0:3bffc1862262 93 // Remarks:
mpetovello 0:3bffc1862262 94 // The data will be stored in the 'MeasuredAccel' member variable in units of m/s/s
mpetovello 0:3bffc1862262 95 virtual void ReadAccelerometers();
mpetovello 0:3bffc1862262 96
mpetovello 0:3bffc1862262 97
mpetovello 0:3bffc1862262 98 // Get the most recently measured X-axis acceleration as stored during the last call to
mpetovello 0:3bffc1862262 99 // ReadAccelerometer()
mpetovello 0:3bffc1862262 100 //
mpetovello 0:3bffc1862262 101 // Arguments:
mpetovello 0:3bffc1862262 102 // None
mpetovello 0:3bffc1862262 103 //
mpetovello 0:3bffc1862262 104 // Returns:
mpetovello 0:3bffc1862262 105 // The function returns the most recently measured X-axis acceleration in units of m/s/s
mpetovello 0:3bffc1862262 106 virtual float GetAccelX() const;
mpetovello 0:3bffc1862262 107
mpetovello 0:3bffc1862262 108
mpetovello 0:3bffc1862262 109 // Get the most recently measured Y-axis acceleration as stored during the last call to
mpetovello 0:3bffc1862262 110 // ReadAccelerometer()
mpetovello 0:3bffc1862262 111 //
mpetovello 0:3bffc1862262 112 // Arguments:
mpetovello 0:3bffc1862262 113 // None
mpetovello 0:3bffc1862262 114 //
mpetovello 0:3bffc1862262 115 // Returns:
mpetovello 0:3bffc1862262 116 // The function returns the most recently measured Y-axis acceleration in units of m/s/s
mpetovello 0:3bffc1862262 117 virtual float GetAccelY() const;
mpetovello 0:3bffc1862262 118
mpetovello 0:3bffc1862262 119
mpetovello 0:3bffc1862262 120 // Get the most recently measured Z-axis acceleration as stored during the last call to
mpetovello 0:3bffc1862262 121 // ReadAccelerometer()
mpetovello 0:3bffc1862262 122 //
mpetovello 0:3bffc1862262 123 // Arguments:
mpetovello 0:3bffc1862262 124 // None
mpetovello 0:3bffc1862262 125 //
mpetovello 0:3bffc1862262 126 // Returns:
mpetovello 0:3bffc1862262 127 // The function returns the most recently measured Z-axis acceleration in units of m/s/s
mpetovello 0:3bffc1862262 128 virtual float GetAccelZ() const;
mpetovello 0:3bffc1862262 129
mpetovello 0:3bffc1862262 130
mpetovello 0:3bffc1862262 131 // Set the device to 'active' mode
mpetovello 0:3bffc1862262 132 //
mpetovello 0:3bffc1862262 133 // Arguments:
mpetovello 0:3bffc1862262 134 // None
mpetovello 0:3bffc1862262 135 //
mpetovello 0:3bffc1862262 136 // Returns:
mpetovello 0:3bffc1862262 137 // Nothing
mpetovello 0:3bffc1862262 138 void SetActiveMode();
mpetovello 0:3bffc1862262 139
mpetovello 0:3bffc1862262 140
mpetovello 0:3bffc1862262 141 // Set the device sampling rate through AM bits, see MMA7660_SR_REG
mpetovello 0:3bffc1862262 142 //
mpetovello 0:3bffc1862262 143 // Arguments:
mpetovello 0:3bffc1862262 144 // samplingRate = setting of AM bits in MMA7660_SR_REG
mpetovello 0:3bffc1862262 145 //
mpetovello 0:3bffc1862262 146 // Returns:
mpetovello 0:3bffc1862262 147 // Nothing
mpetovello 0:3bffc1862262 148 void SetSamplingRateAM(MMA7660_AMSR_t samplingRate);
mpetovello 0:3bffc1862262 149
mpetovello 0:3bffc1862262 150 };
mpetovello 0:3bffc1862262 151
mpetovello 0:3bffc1862262 152 #endif
mpetovello 0:3bffc1862262 153