Using LSM303DLM Kompass-Module and Library for m3pi-Robot.

Dependencies:   LSM303DLM m3pi mbed

Files at this revision

API Documentation at this revision

Comitter:
rahm
Date:
Tue Nov 25 13:52:55 2014 +0000
Commit message:
Digital Kompass with LSM303DLM and m3pi-Robot.
;

Changed in this revision

LSM303DLM.lib Show annotated file Show diff for this revision Revisions of this file
m3pi.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r ccf3df1312aa LSM303DLM.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LSM303DLM.lib	Tue Nov 25 13:52:55 2014 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/shimniok/code/LSM303DLM/#0fcea8569714
diff -r 000000000000 -r ccf3df1312aa m3pi.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m3pi.lib	Tue Nov 25 13:52:55 2014 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/chris/code/m3pi/#4b7d6ea9b35b
diff -r 000000000000 -r ccf3df1312aa main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Nov 25 13:52:55 2014 +0000
@@ -0,0 +1,63 @@
+#include "mbed.h"
+#include <math.h>
+#include "LSM303DLM.h"
+#include "m3pi.h"
+
+#define YOFF  100.0    // Y-Offset
+#define XOFF  2.0      // X-Offset
+#define WOFF  12.0     // Winkel-Offset
+
+//Konstruktoren
+//Serial pc(USBTX,USBRX);        // Für Testausgabe auf PC
+LSM303DLM compass(p28, p27);
+m3pi robo;
+
+// Funktionsprototyp calcHeading
+double calcHeading(int *mag);
+
+// Funktion main
+int main()
+{
+  double hdg;
+  int mag[3];
+
+  //pc.printf("LSM303DLH Test    \n\r");
+  robo.locate(0,0);
+  robo.print("LSM303DL",8);
+  while(1)
+  {
+    compass.readMag(mag);
+    hdg = calcHeading(mag);
+    
+    //pc.printf(" %.1f   ", hdg);
+    robo.locate(0,1);
+    robo.printf(" %.1f\xdf   ", hdg);       // \xdf = °-Symbol im Display-Zeichensatz
+    wait(0.4);
+  }
+}
+
+double calcHeading(int *mag)
+{
+    double x,y;
+    double hdg;
+    
+    x = mag[0] + XOFF;                  // X-Achsen Ausgleich
+    y = mag[1] + YOFF;                  // Y-Achsen Ausgleich
+    
+    hdg = atan(y/x);
+    hdg *= 57.2958;                     // Umrechnung von Bogen- nach Winkelmass
+    if (x > 0)
+    {
+        if(y>0) hdg = hdg;              // Korrektur 1. Quadrant
+        else    hdg = 360.0 + hdg;      // Korrektur 4. Quadrant
+    }
+    else
+    {   
+        if(y>0) hdg = 180.0 + hdg;      // Korrektur 2. Quadrant
+        else hdg = 180.0 + hdg;         // Korrektur 3. Quadrant
+    }
+    
+    hdg -= WOFF;                        // Korrektur Winkel (Vorsicht: Bei Winkeln < WOFF wird hdg negativ!)
+    if (hdg <0) hdg = 360 + hdg;        // Winkel soll nicht negativ werden! (Bsp.: -5° => 355°)
+    return (hdg);
+}
\ No newline at end of file
diff -r 000000000000 -r ccf3df1312aa mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Nov 25 13:52:55 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/49a220cc26e0