Gerardo Carmona / Mbed 2 deprecated AVC_Robot_Controled_Navigation

Dependencies:   FXOS8700CQ SDFileSystem mbed

Fork of AVC_Robot_Controled_Navigation by AVR Competition

Revision:
0:3a322aad8c88
Child:
1:ab09b233da7b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/magnometer.cpp	Thu Oct 16 01:59:21 2014 +0000
@@ -0,0 +1,46 @@
+// ----- Libraries ------------------------------------------------------------------
+#include "mbed.h"
+#include "FXOS8700CQ.h"
+
+// ----- I/O Pins -------------------------------------------------------------------
+FXOS8700CQ fxos(PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // SDA, SCL, (addr << 1)
+
+// ----- Others ---------------------------------------------------------------------
+SRAWDATA accel_data;
+SRAWDATA magn_data;
+
+// ----- Variables ------------------------------------------------------------------
+double mag_x, mag_y;
+double average;
+
+// ----- Functions ------------------------------------------------------------------
+double get_mag_x(){
+    fxos.get_data(&accel_data, &magn_data);
+    return magn_data.x;
+}
+
+double get_mag_y(){
+    fxos.get_data(&accel_data, &magn_data);
+    return magn_data.y;
+}
+
+double get_mag_angle(){
+    double _angle;
+    int16_t _x=0;
+    int16_t _y=0;
+    
+    for (int i = 0; i < 10; i++){
+        fxos.get_data(&accel_data, &magn_data);
+        avg_x += magn_data.x;
+        avg_y += magn_data.y;
+        //pc.printf("X: %d \tY: %d\r\n", magn_data.x, magn_data.y);
+        //pc.printf("%d\n", magn_data.x);
+    }
+    
+    avg_x = avg_x / 10;
+    avg_y = avg_y / 10;
+    
+    pc.printf("%d\n", avg_x);
+    _angle = atan2((double)_x, (double)_y) * 180.0 / 3.14159;
+    return _angle;
+}
\ No newline at end of file