one lap kind of works

Dependencies:   FatFileSystem MSCFileSystem btbee m3pi_ng mbed

Fork of Robot by IESS

Files at this revision

API Documentation at this revision

Comitter:
charwhit
Date:
Fri May 29 11:29:53 2015 +0000
Parent:
8:bd2f012e2f57
Child:
10:83dfbc5e93ed
Commit message:
Still trying to get USB write to work for closed loop

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu May 28 13:40:16 2015 +0000
+++ b/main.cpp	Fri May 29 11:29:53 2015 +0000
@@ -4,17 +4,20 @@
 #include "m3pi_ng.h"
 #include <fstream>
 #define FSNAME "msc"
+#include <string>
+#include <sstream>
+#include <vector>
 
 
 MSCFileSystem msc(FSNAME); // Mount flash drive under the name "msc"
-Serial pc(USBTX,USBRX);
+//Serial pc(USBTX,USBRX);
 
 m3pi robot;
 btbee btbee;
 DigitalIn m3pi_IN[]= {(p12),(p21)}; // IR sensor and Knopf
 Timer timer;
 Timer time_wait;
-#define MAX 1
+#define MAX .5
 #define MIN 0
 
 //#define P_TERM 5
@@ -49,23 +52,25 @@
     int count = 0;
     float paramChange[3];
     bool passed = false;
+    //string hallo = "Idk what is going on...\n";
+    //stringstream ss;
 
     char arr_read[30]; // this should be long enough to store any reply coming in over bt.
     int  chars_read;
+    vector<float> leftval, rightval, lineposval;
     
-    int check = msc.disk_initialize();
+    //int check = msc.disk_initialize();
     
-    robot.locate(0,0);
-    robot.printf("USBWrite"); 
-    robot.locate(0,1);
-    robot.printf("Test"); 
+    
     ofstream myFile ("/" FSNAME "/data.txt"); 
+    //myFile << hallo << "\n"; 
+
 
     /* for (int i = 0; i <5; ++i)
          current_pos[i] = 0.0; */
     
     
-    wait(8);
+    //wait(8);
     btbee.printf("Battery: %f\n", robot.battery());
     //timer.start();
 
@@ -98,8 +103,13 @@
                 lap= lap +1;
             }
 
-            else if (lap == 5) {
+            else if (lap == 1) {
                 robot.stop();
+                robot.printf("Size: %d", rightval.size());
+                if(myFile.is_open()){
+                    for (int i = 0; i < rightval.size(); ++i)
+                        myFile << leftval[i] << " " << rightval[i] << " " << lineposval[i] << endl;
+                }
                 lap_time = timer.read();
                 total_time += lap_time;
                 average_time = total_time/lap;
@@ -208,17 +218,14 @@
         robot.right_motor(right);
         
         
-        if (myFile.is_open())
-        {
-            myFile << left << " " << right << " " << robot.line_position(); 
-            robot.cls(); 
-            robot.locate(0,0); 
-            robot.printf("Done."); 
-        }
-        else
-        {
-            robot.printf("Error."); 
-        }
+        //if (myFile.is_open())
+        //{
+            //btbee.printf("%f %f %f\n", left, right, robot.line_position());
+            leftval.push_back(left);
+            rightval.push_back(right);
+            lineposval.push_back(robot.line_position());
+        //}
+    
 
         wait((5-time_wait.read_ms())/1000);
     }