Drivers for the mini robot designed for Princeton's MAE 433 course.

Dependencies:   mbed-dsp mbed-rtos mbed

Dependents:   MAE433_Library_Tester RobotBalancerv2

Committer:
Electrotiger
Date:
Fri Jun 24 21:03:20 2016 +0000
Revision:
0:9afc272fa65f
Child:
1:918a505314ea
First Commit;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Electrotiger 0:9afc272fa65f 1 /**
Electrotiger 0:9afc272fa65f 2 * @file FXOS8700CQ.hpp
Electrotiger 0:9afc272fa65f 3 * @author Weimen Li
Electrotiger 0:9afc272fa65f 4 * @date June 5th, 2016
Electrotiger 0:9afc272fa65f 5 * @class FXOS8700CQ
Electrotiger 0:9afc272fa65f 6 * @brief This class represents the FXOS8700CQ sensor. Only accelerometer reading is currently supported.
Electrotiger 0:9afc272fa65f 7 */
Electrotiger 0:9afc272fa65f 8
Electrotiger 0:9afc272fa65f 9 #ifndef FXOS8700CQ_HPP_
Electrotiger 0:9afc272fa65f 10 #define FXOS8700CQ_HPP_
Electrotiger 0:9afc272fa65f 11 #include <mbed.h>
Electrotiger 0:9afc272fa65f 12
Electrotiger 0:9afc272fa65f 13 class FXOS8700CQ {
Electrotiger 0:9afc272fa65f 14 public:
Electrotiger 0:9afc272fa65f 15 /// Possible accelerometer sensitivity settings.
Electrotiger 0:9afc272fa65f 16 enum AccelerometerSensitivity {TWO, FOUR, EIGHT};
Electrotiger 0:9afc272fa65f 17 /**
Electrotiger 0:9afc272fa65f 18 * @brief Constructor for the FXOS8700CQ Accelerometer/Magnetometer.
Electrotiger 0:9afc272fa65f 19 * @param SDA The SDA Pin.
Electrotiger 0:9afc272fa65f 20 * @param SCL the SCL Pin.
Electrotiger 0:9afc272fa65f 21 * @param INT1 The pin that the INT1 line is connected to.
Electrotiger 0:9afc272fa65f 22 * @param INT2 The pin that the INT2 line is connect to.
Electrotiger 0:9afc272fa65f 23 * @param setting (optional) The maximum measurement acceleration in g's. May be TWO, FOUR, or EIGHT for
Electrotiger 0:9afc272fa65f 24 * +/- 2/4/8 g's. A smaller maximum measurement allows for greater sensitivity.
Electrotiger 0:9afc272fa65f 25 */
Electrotiger 0:9afc272fa65f 26 FXOS8700CQ(PinName SDA, PinName SCL, PinName INT1, PinName INT2, AccelerometerSensitivity setting = TWO);
Electrotiger 0:9afc272fa65f 27 virtual ~FXOS8700CQ();
Electrotiger 0:9afc272fa65f 28 /**
Electrotiger 0:9afc272fa65f 29 * @brief Read data from the accelerometer. Takes pointers to floats that store these variables.
Electrotiger 0:9afc272fa65f 30 * Example code:
Electrotiger 0:9afc272fa65f 31 * @code
Electrotiger 0:9afc272fa65f 32 * float xAccel;
Electrotiger 0:9afc272fa65f 33 * float yAccel;
Electrotiger 0:9afc272fa65f 34 * float zAccel;
Electrotiger 0:9afc272fa65f 35 * ...
Electrotiger 0:9afc272fa65f 36 * readAccelerometer(&xAccel, &yAccel, &zAccel);
Electrotiger 0:9afc272fa65f 37 * ...
Electrotiger 0:9afc272fa65f 38 * @endcode
Electrotiger 0:9afc272fa65f 39 */
Electrotiger 0:9afc272fa65f 40 void readAccelerometer(float *xAccel, float *yAccel, float *zAccel);
Electrotiger 0:9afc272fa65f 41 /**
Electrotiger 0:9afc272fa65f 42 * @brief Set offset compensation values that are subtracted from the readings to zero them.
Electrotiger 0:9afc272fa65f 43 */
Electrotiger 0:9afc272fa65f 44 void setOffset(float x, float y, float z) {
Electrotiger 0:9afc272fa65f 45 xOffset = x;
Electrotiger 0:9afc272fa65f 46 yOffset = y;
Electrotiger 0:9afc272fa65f 47 zOffset = z;
Electrotiger 0:9afc272fa65f 48 }
Electrotiger 0:9afc272fa65f 49 private:
Electrotiger 0:9afc272fa65f 50 /// Member function to handle data-ready interrupt.
Electrotiger 0:9afc272fa65f 51 void dataReadyISR(void);
Electrotiger 0:9afc272fa65f 52 private:
Electrotiger 0:9afc272fa65f 53 /// I2C Object to handle bus communications.
Electrotiger 0:9afc272fa65f 54 I2C I2CObj;
Electrotiger 0:9afc272fa65f 55 /// Interrupt object for a data-ready signal.
Electrotiger 0:9afc272fa65f 56 InterruptIn dataReadyInt;
Electrotiger 0:9afc272fa65f 57 /// The accelerometer sensitivity setting specified by the caller.
Electrotiger 0:9afc272fa65f 58 const AccelerometerSensitivity accelSensitivitySetting;
Electrotiger 0:9afc272fa65f 59 /// The conversion constant to convert the read int16_t type data to a float.
Electrotiger 0:9afc272fa65f 60 const float accelInt2Float;
Electrotiger 0:9afc272fa65f 61 /// The latest x Acceleration value in g's.
Electrotiger 0:9afc272fa65f 62 float lastxAccel;
Electrotiger 0:9afc272fa65f 63 /// The latest y Acceleration value in g's.
Electrotiger 0:9afc272fa65f 64 float lastyAccel;
Electrotiger 0:9afc272fa65f 65 /// The latest z Acceleration values in g's.
Electrotiger 0:9afc272fa65f 66 float lastzAccel;
Electrotiger 0:9afc272fa65f 67 /// The x offset
Electrotiger 0:9afc272fa65f 68 float xOffset;
Electrotiger 0:9afc272fa65f 69 /// The y offset
Electrotiger 0:9afc272fa65f 70 float yOffset;
Electrotiger 0:9afc272fa65f 71 /// The z offset
Electrotiger 0:9afc272fa65f 72 float zOffset;
Electrotiger 0:9afc272fa65f 73 };
Electrotiger 0:9afc272fa65f 74
Electrotiger 0:9afc272fa65f 75 #endif /* FXOS8700CQ_HPP_ */
Electrotiger 0:9afc272fa65f 76