This ILC code kinda works
Dependencies: FatFileSystem MSCFileSystem btbee m3pi_ng mbed ILCRobot
Fork of RobotB by
Diff: main.cpp
- Revision:
- 9:030b7e4ff7be
- Parent:
- 8:bd2f012e2f57
- Child:
- 10:83dfbc5e93ed
diff -r bd2f012e2f57 -r 030b7e4ff7be main.cpp --- 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); }