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

Dependencies:   mbed-dsp mbed-rtos mbed

Dependents:   MAE433_Library_Tester RobotBalancerv2

Revision:
0:9afc272fa65f
Child:
1:918a505314ea
diff -r 000000000000 -r 9afc272fa65f FXOS8700CQ.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FXOS8700CQ.hpp	Fri Jun 24 21:03:20 2016 +0000
@@ -0,0 +1,76 @@
+/**
+ * @file FXOS8700CQ.hpp
+ * @author Weimen Li
+ * @date June 5th, 2016
+ * @class FXOS8700CQ
+ * @brief This class represents the FXOS8700CQ sensor. Only accelerometer reading is currently supported.
+ */
+
+#ifndef FXOS8700CQ_HPP_
+#define FXOS8700CQ_HPP_
+#include <mbed.h>
+
+class FXOS8700CQ {
+public:
+	/// Possible accelerometer sensitivity settings.
+	enum AccelerometerSensitivity {TWO, FOUR, EIGHT};
+	/**
+	 * @brief Constructor for the FXOS8700CQ Accelerometer/Magnetometer.
+	 * @param SDA The SDA Pin.
+	 * @param SCL the SCL Pin.
+	 * @param INT1 The pin that the INT1 line is connected to.
+	 * @param INT2 The pin that the INT2 line is connect to.
+	 * @param setting (optional) The maximum measurement acceleration in g's. May be TWO, FOUR, or EIGHT for
+	 * +/- 2/4/8 g's. A smaller maximum measurement allows for greater sensitivity.
+	 */
+	FXOS8700CQ(PinName SDA, PinName SCL, PinName INT1, PinName INT2, AccelerometerSensitivity setting = TWO);
+	virtual ~FXOS8700CQ();
+	/**
+	 * @brief Read data from the accelerometer. Takes pointers to floats that store these variables.
+	 * Example code:
+	 * @code
+	 * float xAccel;
+	 * float yAccel;
+	 * float zAccel;
+	 * ...
+	 * readAccelerometer(&xAccel, &yAccel, &zAccel);
+	 * ...
+	 * @endcode
+	 */
+	void readAccelerometer(float *xAccel, float *yAccel, float *zAccel);
+	/**
+	 * @brief Set offset compensation values that are subtracted from the readings to zero them. 
+	 */
+	 void setOffset(float x, float y, float z) {
+	 	xOffset = x;
+	 	yOffset = y;
+	 	zOffset = z;
+	 }
+private:
+	/// Member function to handle data-ready interrupt.
+	void dataReadyISR(void);
+private:
+	/// I2C Object to handle bus communications.
+	I2C I2CObj;
+	/// Interrupt object for a data-ready signal.
+	InterruptIn dataReadyInt;
+	/// The accelerometer sensitivity setting specified by the caller.
+	const AccelerometerSensitivity accelSensitivitySetting;
+	/// The conversion constant to convert the read int16_t type data to a float.
+	const float accelInt2Float;
+	/// The latest x Acceleration value in g's.
+	float lastxAccel;
+	/// The latest y Acceleration value in g's.
+	float lastyAccel;
+	/// The latest z Acceleration values in g's.
+	float lastzAccel;
+	/// The x offset
+	float xOffset;
+	/// The y offset
+	float yOffset;
+	/// The z offset
+	float zOffset;
+};
+
+#endif /* FXOS8700CQ_HPP_ */
+