PIDs and fun

Dependencies:   btbee m3pi_ng mbed FatFileSystemCpp

Revision:
9:43be0dea44f0
Parent:
8:e7b322f72d16
Child:
10:fd4ae3946c7e
--- a/main.cpp	Thu May 28 12:56:20 2015 +0000
+++ b/main.cpp	Thu May 28 13:44:07 2015 +0000
@@ -2,6 +2,15 @@
 #include "m3pi_ng.h"
 #include "time.h"
 #include "btbee.h"
+#include <string>
+#include <sstream>
+
+using namespace std;
+//For USB writing
+#include "MSCFileSystem.h"
+#define FSNAME "msc"
+MSCFileSystem msc(FSNAME);
+
 
 m3pi m3pi;
 btbee btbee;
@@ -93,8 +102,17 @@
     double timer;
     btbee.printf("\n");
     btbee.printf("Now starting \n");
+    string message;
+    DIR *d;
+    struct dirent *p;
+   
+    d = opendir("/" FSNAME);
     
-    
+    FILE *fp = fopen( "/" FSNAME "/test results.txt", "w"); //file name
+    if ( fp == NULL )
+    {
+        m3pi.leds(1);
+    }
     
     
     while (1) {
@@ -118,6 +136,11 @@
         current_pos_of_line = m3pi.line_position();        
         proportional = current_pos_of_line;
         
+        std::ostringstream ss;
+        ss << current_pos_of_line;
+        message = ss.str();
+        message.append("     ");
+        
         // Compute the derivative
         derivative = current_pos_of_line - previous_pos_of_line;
         
@@ -149,6 +172,14 @@
         m3pi.left_motor(left);
         m3pi.right_motor(right);
         
+        
+        ss << left;
+        message.append(ss.str());
+        message.append("     ");
+        ss << right;
+        message.append(ss.str());
+             
+        
     m3pi.calibrated_sensor(LapTest);
     
     s1 = LapTest[0];
@@ -297,8 +328,12 @@
 //    timer = 0;
 //    LoopTime.reset();
 
+        printf("%s",message);
+        fprintf(fp,"\n");
+        
+        
     }
 
 
-
+    fclose(fp);
 }