basic version
Dependencies: C12832_lcd USBHost mbed
Diff: main.cpp
- Revision:
- 10:6059097698f7
- Parent:
- 9:88d70b0c1b8b
- Child:
- 12:309dc0947373
diff -r 88d70b0c1b8b -r 6059097698f7 main.cpp --- a/main.cpp Thu Jan 29 16:18:19 2015 +0000 +++ b/main.cpp Thu Jan 29 20:32:37 2015 +0000 @@ -2,8 +2,11 @@ #include "rtos.h" #include "C12832_lcd.h" +//File Access +LocalFileSystem local("local"); - +//Timer +Timer t; //Varible float sonarDistance; @@ -46,26 +49,40 @@ int Size=16; float Average_4[16]; //number of value in the array float Average_Sum=0; - + bool exportDebugData = true; + float debugDataTimeLimit = 60.0f; + FILE *graphcsv = fopen("/local/graph.csv","w"); while(true) { for(int i=0;i<Size;i++) { - + if (exportDebugData){ + fprintf(graphcsv, "%f,",t.read()); // Print time to file; + } Average_Sum = Average_Sum-Average_4[i]; //Remove the 4th oldest value from the average sum sonarDistance_mutex.lock(); //Mutex lock for the Sonar value - Average_4[i]= sonarDistance; //Add the new value to the array + Average_4[i]= sonarDistance; //Add the new value to the array + if (exportDebugData){ + fprintf(graphcsv, "%f,",sonarDistance); // Write sonarDistance to file + } sonarDistance_mutex.unlock(); //Mutex unlock for the Sonar value Average_Sum = Average_Sum + Average_4[i]; //Add the new array value to the sum servoPosition_mutex.lock(); //Mutex lock for the servo value - servoPosition = Average_Sum/Size; //Divide the array by the number of element in the array + servoPosition = Average_Sum/Size; //Divide the array by the number of element in the array + if (exportDebugData){ + fprintf(graphcsv, "%f\n",servoPosition); // Write servoPosition to file + } servoPosition_mutex.unlock(); //Mutex unlock for the servo value + if(t.read() <= debugDataTimeLimit){ + fclose(graphcsv); + exportDebugData = false; + } }//end for loop }//end of while loop }//End of thread @@ -137,6 +154,7 @@ sonarDistance = 0.0f; servoPosition = 0.0f; + t.start(); Thread sonarSensor_thread(sonarSensor); Thread servoControl_thread(servoControl);