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:
Thu Jun 30 23:52:51 2016 +0000
Revision:
8:da95e4ccbe4c
Parent:
4:2d38ad348e0d
Decreased H-Bridge Period to Provide for Even Finer Control.

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 4:2d38ad348e0d 7 * @remark WARNING: I2C Reading is unreliable when built outside of the mbed compiler. If you're compiling this outside
Electrotiger 4:2d38ad348e0d 8 * of the mBed compiler, ensure that the accelerometer is reading reliably. My testing shows that the readings often glitch.
Electrotiger 0:9afc272fa65f 9 */
Electrotiger 0:9afc272fa65f 10
Electrotiger 0:9afc272fa65f 11 #ifndef FXOS8700CQ_HPP_
Electrotiger 0:9afc272fa65f 12 #define FXOS8700CQ_HPP_
Electrotiger 0:9afc272fa65f 13 #include <mbed.h>
Electrotiger 0:9afc272fa65f 14
Electrotiger 0:9afc272fa65f 15 class FXOS8700CQ {
Electrotiger 0:9afc272fa65f 16 public:
Electrotiger 0:9afc272fa65f 17 /// Possible accelerometer sensitivity settings.
Electrotiger 0:9afc272fa65f 18 enum AccelerometerSensitivity {TWO, FOUR, EIGHT};
Electrotiger 0:9afc272fa65f 19 /**
Weimen Li 1:918a505314ea 20 * @brief Constructor for the FXOS8700CQ Accelerometer/Magnetometer. Pin assignments have default values for the K22F board.
Electrotiger 0:9afc272fa65f 21 * @param SDA The SDA Pin.
Electrotiger 0:9afc272fa65f 22 * @param SCL the SCL Pin.
Electrotiger 0:9afc272fa65f 23 * @param INT1 The pin that the INT1 line is connected to.
Electrotiger 0:9afc272fa65f 24 * @param INT2 The pin that the INT2 line is connect to.
Electrotiger 0:9afc272fa65f 25 * @param setting (optional) The maximum measurement acceleration in g's. May be TWO, FOUR, or EIGHT for
Electrotiger 0:9afc272fa65f 26 * +/- 2/4/8 g's. A smaller maximum measurement allows for greater sensitivity.
Electrotiger 0:9afc272fa65f 27 */
Weimen Li 1:918a505314ea 28 FXOS8700CQ(PinName SDA = PTB3, PinName SCL = PTB2, PinName INT1 = PTD0, PinName INT2 = PTD1, AccelerometerSensitivity setting = TWO);
Electrotiger 0:9afc272fa65f 29 virtual ~FXOS8700CQ();
Electrotiger 0:9afc272fa65f 30 /**
Electrotiger 0:9afc272fa65f 31 * @brief Read data from the accelerometer. Takes pointers to floats that store these variables.
Electrotiger 0:9afc272fa65f 32 * Example code:
Electrotiger 0:9afc272fa65f 33 * @code
Electrotiger 0:9afc272fa65f 34 * float xAccel;
Electrotiger 0:9afc272fa65f 35 * float yAccel;
Electrotiger 0:9afc272fa65f 36 * float zAccel;
Electrotiger 0:9afc272fa65f 37 * ...
Electrotiger 0:9afc272fa65f 38 * readAccelerometer(&xAccel, &yAccel, &zAccel);
Electrotiger 0:9afc272fa65f 39 * ...
Electrotiger 0:9afc272fa65f 40 * @endcode
Electrotiger 0:9afc272fa65f 41 */
Electrotiger 0:9afc272fa65f 42 void readAccelerometer(float *xAccel, float *yAccel, float *zAccel);
Electrotiger 0:9afc272fa65f 43 /**
Electrotiger 0:9afc272fa65f 44 * @brief Set offset compensation values that are subtracted from the readings to zero them.
Electrotiger 0:9afc272fa65f 45 */
Electrotiger 0:9afc272fa65f 46 void setOffset(float x, float y, float z) {
Electrotiger 0:9afc272fa65f 47 xOffset = x;
Electrotiger 0:9afc272fa65f 48 yOffset = y;
Electrotiger 0:9afc272fa65f 49 zOffset = z;
Electrotiger 0:9afc272fa65f 50 }
Electrotiger 0:9afc272fa65f 51 private:
Electrotiger 0:9afc272fa65f 52 /// Member function to handle data-ready interrupt.
Electrotiger 0:9afc272fa65f 53 void dataReadyISR(void);
Electrotiger 0:9afc272fa65f 54 private:
Electrotiger 0:9afc272fa65f 55 /// I2C Object to handle bus communications.
Electrotiger 0:9afc272fa65f 56 I2C I2CObj;
Electrotiger 0:9afc272fa65f 57 /// Interrupt object for a data-ready signal.
Electrotiger 0:9afc272fa65f 58 InterruptIn dataReadyInt;
Electrotiger 0:9afc272fa65f 59 /// The accelerometer sensitivity setting specified by the caller.
Electrotiger 0:9afc272fa65f 60 const AccelerometerSensitivity accelSensitivitySetting;
Electrotiger 0:9afc272fa65f 61 /// The conversion constant to convert the read int16_t type data to a float.
Electrotiger 0:9afc272fa65f 62 const float accelInt2Float;
Electrotiger 0:9afc272fa65f 63 /// The latest x Acceleration value in g's.
Electrotiger 0:9afc272fa65f 64 float lastxAccel;
Electrotiger 0:9afc272fa65f 65 /// The latest y Acceleration value in g's.
Electrotiger 0:9afc272fa65f 66 float lastyAccel;
Electrotiger 0:9afc272fa65f 67 /// The latest z Acceleration values in g's.
Electrotiger 0:9afc272fa65f 68 float lastzAccel;
Electrotiger 0:9afc272fa65f 69 /// The x offset
Electrotiger 0:9afc272fa65f 70 float xOffset;
Electrotiger 0:9afc272fa65f 71 /// The y offset
Electrotiger 0:9afc272fa65f 72 float yOffset;
Electrotiger 0:9afc272fa65f 73 /// The z offset
Electrotiger 0:9afc272fa65f 74 float zOffset;
Electrotiger 0:9afc272fa65f 75 };
Electrotiger 0:9afc272fa65f 76
Electrotiger 0:9afc272fa65f 77 #endif /* FXOS8700CQ_HPP_ */
Electrotiger 0:9afc272fa65f 78