
02/07/15
Dependencies: mbed
Revision 64:809bd19f4e7c, committed 2015-08-05
- Comitter:
- aidanPJG
- Date:
- Wed Aug 05 08:44:12 2015 +0000
- Parent:
- 63:7d2bff227f65
- Child:
- 65:08b3eb9b95dd
- Commit message:
- added avgtime array and avgspeed array to xl
Changed in this revision
Calculate.cpp | Show annotated file Show diff for this revision Revisions of this file |
Data.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/Calculate.cpp Wed Aug 05 08:13:19 2015 +0000 +++ b/Calculate.cpp Wed Aug 05 08:44:12 2015 +0000 @@ -4,25 +4,29 @@ #include <iostream> #include "Distance.h" -void printArray(double array[20], double timesArray[20], int NoOfPins); //defining the methods -void data(int sensor_number, double time, double speed); -DigitalOut led4(LED4); - +//*************defining methods used in this method +void printArray(double array[20], double timesArray[20], int NoOfPins,double speedAvg[20], double timesTotal[20]); +void data(int sensor_number, double time, double speed, double timesTotal, double speedAvg); + //*********mbed pins********************************* extern Serial pc; //defines the communication between MBed and pc DigitalIn sensor[20] = {p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19,p20,p21,p22,p23,p24} ; //array of sensors. +DigitalOut led4(LED4); -//********c++ variables******************************* +//********c++ variables******************************* + Timer t; - double timeDiff= 0; //time between 2 sensors - not used right now - double speed = 0; - double times[20]; //array the size of #pins - double speeds[20]; //array of speeds - double avgSpeeds[20]; - double totalTimes[20]; - double avgtime= 0;; + double timeDiff= 0; //time between 2 sensors + double speed = 0; //instspeed + double avgtime= 0;; double avgspeed = 0; double avgdistance = 0; + //arrays + double times[20]; //array of the time the sensor is reached .(the size of #pins) + double speeds[20]; //array of inst speeds + double avgSpeeds[20]; //avg speeds + double totalTimes[20]; //total runnning times + int calculate(double distance, int NoOfPins) @@ -43,7 +47,7 @@ t.start(); //starts the timer once, doesn't do anything next iteration timeDiff = t.read(); //reads what the timer is currently at t.reset(); //starts the timer again from 0. - times[i] = timeDiff; //adds sensor times to array for logging. + times[i] = timeDiff; //adds sensor times to array for logging. this must remain above the calculations for avgdistance to work. if( i <1 ) //for the first one so it prints out 0 instead of getting inf from dividing by 0 and getting nan symbols. { @@ -80,10 +84,10 @@ i++; //move onto next sensor } } - printArray(speeds,times,NoOfPins); + printArray(speeds,times,NoOfPins,avgSpeeds,totalTimes); } -void printArray(double array[20], double timesArray[20], int NoOfPins) //for printing arrays to the terminal +void printArray(double array[20], double timesArray[20], int NoOfPins, double speedAvg[20], double timesTotal[20]) //for printing arrays to the terminal { /*prints to the terminal for (int i = 0; i < NoOfPins ; i++) //printing module for array @@ -93,6 +97,6 @@ } */ for (int i = 0; i < NoOfPins ; i++) //printing to Datalog { - data( i,times[i],speeds[i]); + data( i,times[i],speeds[i],timesTotal[i],speedAvg[i]); } }
--- a/Data.cpp Wed Aug 05 08:13:19 2015 +0000 +++ b/Data.cpp Wed Aug 05 08:44:12 2015 +0000 @@ -1,20 +1,21 @@ #include "mbed.h" LocalFileSystem local("local"); +extern Serial pc; void initialise(int counter ) { FILE *fp1 = fopen("/local/Datalog.xls", "a"); // opens or creates fill Datalog, and gives the headings fprintf(fp1, " Test %d \n", counter); - fprintf(fp1, " Sensor \t Time \t Speed \n"); + fprintf(fp1, " Sensor \t Total Time \t Time Diff \t Inst Speed \t Avg Speed\n"); fclose(fp1); } -void data(int sensor_number, double time, double speed) +void data(int sensor_number, double time, double speed, double timesTotal,double speedAvg) { // printf("it be printing"); //testing FILE *fp = fopen("/local/Datalog.xls", "a"); // Open "Datalog - fprintf(fp, " %d \t %lf \t %lf \n",sensor_number, time, speed); //fills the tables with the results + fprintf(fp, " %d \t %lf \t %lf \t %lf \t %lf \n",sensor_number + 1, timesTotal ,time, speed, speedAvg); //fills the tables with the results fclose(fp); }