![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
02/07/15
Dependencies: mbed
Diff: Calculate.cpp
- Revision:
- 68:c6399471ea49
- Parent:
- 64:809bd19f4e7c
- Child:
- 69:74bffa1d3f7f
--- a/Calculate.cpp Thu Aug 06 14:45:23 2015 +0000 +++ b/Calculate.cpp Wed Aug 26 16:08:09 2015 +0000 @@ -3,10 +3,12 @@ #include <string> #include <iostream> #include "Distance.h" +#include "Data.h" //*************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); +void reset(int distance, int NoOfPins); //*********mbed pins********************************* extern Serial pc; //defines the communication between MBed and pc @@ -21,6 +23,7 @@ double avgtime= 0;; double avgspeed = 0; double avgdistance = 0; + int bendCounter = 0; //arrays double times[20]; //array of the time the sensor is reached .(the size of #pins) double speeds[20]; //array of inst speeds @@ -28,9 +31,10 @@ double totalTimes[20]; //total runnning times - int calculate(double distance, int NoOfPins) { +while(true){ + int i = 0; //set the pin to 0, starting from the 0th ( first) pin while( i < NoOfPins) //while we have not reached the last pin { @@ -44,7 +48,8 @@ } } - t.start(); //starts the timer once, doesn't do anything next iteration + 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. this must remain above the calculations for avgdistance to work. @@ -84,7 +89,25 @@ i++; //move onto next sensor } } + printArray(speeds,times,NoOfPins,avgSpeeds,totalTimes); + reset(distance, NoOfPins); +} +} +void reset(int distance, int NoOfPins) +{ + while ( sensor[0]){ + + } + wait_ms(50); + bendCounter++; + //resets + std::fill_n(times, 20 , 0); //empty array of times so averaging works + std::fill_n(speeds, 20 , 0); + std::fill_n(avgSpeeds, 20 , 0); + std::fill_n(totalTimes, 20 , 0); + t.reset(); //clock reset + calculate(distance, NoOfPins); } void printArray(double array[20], double timesArray[20], int NoOfPins, double speedAvg[20], double timesTotal[20]) //for printing arrays to the terminal @@ -95,6 +118,7 @@ pc.printf(" Sensor : %d Time %lf Speed %f \n", i,times[i],speeds[i]); // pc.printf(" %d : %d \t", i,times[i]); } */ + initialise(bendCounter); //used to create the Datalog file should happen once for every bend test for (int i = 0; i < NoOfPins ; i++) //printing to Datalog { data( i,times[i],speeds[i],timesTotal[i],speedAvg[i]);