Crude navigation

Dependencies:   GPS2 L3GD20 LSM303DLHC2 PID mbed SDFileSystem

Fork of GPSNavigation by David Spillman

Files at this revision

API Documentation at this revision

Comitter:
Spilly
Date:
Sat May 09 22:29:01 2015 +0000
Parent:
16:9d1e72ab7ec7
Commit message:
Fix for SD card GPS waypoints

Changed in this revision

LSM303DLHC.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
--- a/LSM303DLHC.lib	Thu May 07 16:35:00 2015 +0000
+++ b/LSM303DLHC.lib	Sat May 09 22:29:01 2015 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/Spilly/code/LSM303DLHC2/#5fe568883921
+http://developer.mbed.org/users/Spilly/code/LSM303DLHC2/#6c74e3e5e105
--- a/main.cpp	Thu May 07 16:35:00 2015 +0000
+++ b/main.cpp	Sat May 09 22:29:01 2015 +0000
@@ -82,7 +82,7 @@
 #define RATIO_TOLERANCE     0.02f                       //How close the difference between the set ratio and current ratio before consider
 #define MIN_RATIO           0.04f                       //Actuator hits retract limit swithc at 2.2%
 #define MAX_RATIO           0.85f                       //Actuator hits extend limit switch at 87.6%
-#define CENTER_RATIO        0.29f                       //Ratio where prop is centered
+#define CENTER_RATIO        0.285f                      //Ratio where prop is centered
 
 #define FIX             0                               // 2 = DGPS (more accurate but slower to initialize) 1 = GPS only (less accurate but faster to initialize)
 #define ARRIVED         5.0f                            //Tolerance, in meters, for when goal location is reached
@@ -144,7 +144,7 @@
     int wayPtNum = 0, mode = 0, adjustMode = 0;
     float magDiff = 0;
     float batVoltage = 0.0f, potVoltage = 0.0f, voltRatio = 0.0f;
-    float curSet = 0.0f, prevSet = 0.29f;
+    float curSet = 0.0f, prevSet = CENTER_RATIO;
     float filtered = 0.0000001f;
     double curPos[2]        =       {0,0};
     double goalPos[10][2];                                  //positions are initially read from SD card
@@ -169,14 +169,14 @@
     
     //Get goal positions from SD card
     //start of SD card read
-    way = fopen ("/sd/GPS_CORDS.txt", "r");
+    way = fopen ("/sd/GPS_CORDS.txt", "rt");
     
     xBee.printf("Reading SD Card Please Wait\n");
     
     for(int x = 0; x<=9; x++)
     {
-        fscanf(way, "%f,%f\n", &goalPos[x][0], &goalPos[x][1]);
-        xBee.printf("waypoint %d = %f,%f\n", x, goalPos[x][0], goalPos[x][1]);
+        fscanf(way, "%lf,%lf\n", &goalPos[x][0], &goalPos[x][1]);
+        xBee.printf("waypoint %d = %lf,%lf\n", x, goalPos[x][0], goalPos[x][1]);
     }
     fclose(way);
     //end of SD card read
@@ -306,6 +306,12 @@
                     goStop();
                     mode = 3;
                 }
+                else if(recChar == '>')
+                {
+                    xBee.printf("Reseting system\n");
+                    wait(0.5f);
+                    NVIC_SystemReset();
+                }
                 else if(recChar == '<')
                 {
                     xBee.printf("Power cycling GPS\nPlease wait\n");
@@ -828,7 +834,7 @@
                     way = fopen("/sd/GPS_CORDS.txt", "w+");
                     for(int x = 0; x<=9; x++)
                     {
-                        fprintf(way, "%f,%f\n", &goalPos[x][0], &goalPos[x][1]);
+                        fprintf(way, "%2.10lf,%2.10lf\n", &goalPos[x][0], &goalPos[x][1]);
                     }
                     fclose(way);                    
                 }
@@ -841,7 +847,7 @@
                     way = fopen("/sd/GPS_CORDS.txt", "w+");
                     for(int x = 0; x<=9; x++)
                     {
-                        fprintf(way, "%f,%f\n", &goalPos[x][0], &goalPos[x][1]);
+                        fprintf(way, "%2.10lf,%2.10lf\n", &goalPos[x][0], &goalPos[x][1]);
                     }
                     fclose(way);            
                 }
@@ -854,7 +860,7 @@
                     way = fopen("/sd/GPS_CORDS.txt", "w+");
                     for(int x = 0; x<=9; x++)
                     {
-                        fprintf(way, "%f,%f\n", &goalPos[x][0], &goalPos[x][1]);
+                        fprintf(way, "%2.10lf,%2.10lf\n", &goalPos[x][0], &goalPos[x][1]);
                     }
                     fclose(way);            
                 }
@@ -867,7 +873,7 @@
                     way = fopen("/sd/GPS_CORDS.txt", "w+");
                     for(int x = 0; x<=9; x++)
                     {
-                        fprintf(way, "%f,%f\n", &goalPos[x][0], &goalPos[x][1]);
+                        fprintf(way, "%2.10lf,%2.10lf\n", &goalPos[x][0], &goalPos[x][1]);
                     }
                     fclose(way);            
                 }
@@ -880,7 +886,7 @@
                     way = fopen("/sd/GPS_CORDS.txt", "w+");
                     for(int x = 0; x<=9; x++)
                     {
-                        fprintf(way, "%f,%f\n", &goalPos[x][0], &goalPos[x][1]);
+                        fprintf(way, "%2.10lf,%2.10lf\n", &goalPos[x][0], &goalPos[x][1]);
                     }
                     fclose(way);            
                 }
@@ -893,7 +899,7 @@
                     way = fopen("/sd/GPS_CORDS.txt", "w+");
                     for(int x = 0; x<=9; x++)
                     {
-                        fprintf(way, "%f,%f\n", &goalPos[x][0], &goalPos[x][1]);
+                        fprintf(way, "%2.10lf,%2.10lf\n", &goalPos[x][0], &goalPos[x][1]);
                     }
                     fclose(way);            
                 }
@@ -911,7 +917,7 @@
                     way = fopen("/sd/GPS_CORDS.txt", "w+");
                     for(int x = 0; x<=9; x++)
                     {
-                        fprintf(way, "%f,%f\n", &goalPos[x][0], &goalPos[x][1]);
+                        fprintf(way, "%2.10lf,%2.10lf\n", &goalPos[x][0], &goalPos[x][1]);
                     }
                     fclose(way);            
                 }
@@ -924,7 +930,7 @@
                     way = fopen("/sd/GPS_CORDS.txt", "w+");
                     for(int x = 0; x<=9; x++)
                     {
-                        fprintf(way, "%f,%f\n", &goalPos[x][0], &goalPos[x][1]);
+                        fprintf(way, "%2.10lf,%2.10lf\n", &goalPos[x][0], &goalPos[x][1]);
                     }
                     fclose(way);            
                 }
@@ -937,7 +943,7 @@
                     way = fopen("/sd/GPS_CORDS.txt", "w+");
                     for(int x = 0; x<=9; x++)
                     {
-                        fprintf(way, "%f,%f\n", &goalPos[x][0], &goalPos[x][1]);
+                        fprintf(way, "%2.10lf,%2.10lf\n", &goalPos[x][0], &goalPos[x][1]);
                     }
                     fclose(way);            
                 }