justin solarski / Gyro

Files at this revision

API Documentation at this revision

Comitter:
jsolarski
Date:
Mon Jan 03 10:13:42 2011 +0000
Parent:
1:a3822b798d67
Commit message:
Added Rate function, the map function in cpp may be missing critical math for the calculation

Changed in this revision

gyro.cpp Show annotated file Show diff for this revision Revisions of this file
gyro.h Show annotated file Show diff for this revision Revisions of this file
--- a/gyro.cpp	Tue Dec 21 06:09:02 2010 +0000
+++ b/gyro.cpp	Mon Jan 03 10:13:42 2011 +0000
@@ -24,6 +24,12 @@
 #include "mbed.h"
 #include "gyro.h"
 
+long map(long x, long in_min, long in_max, long out_min, long out_max)
+{
+  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
+}
+
+
 Gyro::Gyro(PinName g_pin, PinName st, PinName pd) : _g_pin(g_pin), _st(st), _pd(pd) {
     _st.write(0);
     _pd.write(0);
@@ -41,4 +47,11 @@
 }
 void Gyro::wakeup() {
     _pd.write(0);
-}
\ No newline at end of file
+}
+int Gyro::rate() {
+    unsigned int speed;
+    int mapped;
+    speed = _g_pin.read_u16();
+    mapped = map(speed, 0, 65535, -300, 300);
+    return mapped;
+}
--- a/gyro.h	Tue Dec 21 06:09:02 2010 +0000
+++ b/gyro.h	Mon Jan 03 10:13:42 2011 +0000
@@ -30,6 +30,9 @@
  * Used for reading from an analog Gyro Tested with LISY300Al spark fun breakout board
  * http://www.sparkfun.com/products/8955
  * 300o/S
+ * specs - 3.3mV per o/S +-300 0/S max
+ *       - 5% temp variance 
+ *       - 
  *
  * Example:
  *
@@ -46,6 +49,7 @@
  * @param pd = powerdown
  */
     Gyro (PinName g_pin, PinName st, PinName pd);
+
 /** read gyros analog pin 
  *
  * outputs 0.0-1.0 
@@ -66,8 +70,15 @@
  *
  */
     void wakeup();
+/** give you rate or turning degrees per second Fo/S
+ *  - uses the map funciton defined in the cpp file
+ *  - this function works, but no real world data yet
+ *  - I might be missing some critical math for conversion 
+ */
+    int rate();
+        
+private :
 
-private :
     AnalogIn _g_pin;
     DigitalInOut _st;
     DigitalInOut _pd;