Team Design project 3 main file

Dependencies:   mbed Motor_Driver Sensors MMA8451Q LocalPositionSystem

Fork of TDP_main by Ivelin Kozarev

Revision:
1:eace997e9a93
Parent:
0:5ca0450111f3
Child:
9:718987b106a8
--- a/sensor_measure.h	Fri Feb 13 15:18:43 2015 +0000
+++ b/sensor_measure.h	Fri Feb 13 15:51:24 2015 +0000
@@ -9,6 +9,8 @@
 -decide whether pins should be Interrupts INs or is it going to be polling - polling atm
 - how to distingisuh between different sensor on/off frequency - maybe create a new class??
 - 
+
+NEED TESTING!
 LAST REVISED 13/02
 */
 
@@ -18,7 +20,7 @@
 #define NUMBER_SAMPLES 40 // NUMBER OF SAMPLES FOR SENSOR TESTING
 
 //define pinout for all the sensors
-InterruptIn pin_right_right(PTD0);
+DigitalIn pin_right_right(PTD0);
 InterruptIn pin_right_centre(PTD1);
 InterruptIn pin_right_left(PTD2);
 InterruptIn pin_left_right(PTD3);
@@ -31,23 +33,38 @@
 
 //structure for sensors
 typedef struct sensor_data {
-    InterruptIn pin;
+    DigitalIn* pin; //TODO can;t seem to be able to declara this
     int  black_value;
     int  white_value;    
 }sensor_data;
 
-//Decalre all the sensors
-//sample rightright
+/*
+All sensors should be declared in the MAIN PROGRAM????
+sensor_data right_right;
+sensor_data.pin = &pin_right_right;
+right_right.black_value = 2013;
+sensor_data.white_value = 10000;
+*/
 sensor_data right_right;
-right_right.pin = pin_right_right;
-right_right.black_value = 2013;
-right_right.white_value = 10000;
+sensor_data right_centre;
+// and so on....
 
-// and continue with the others..
+//Initialise values of all sensors
+void sensor_initialise () {
+    //right_right
+    right_right.pin = &pin_right_right;
+    right_right.black_value = 2013;
+    right_right.white_value = 10000;
+    //and contiune so on..
+}
+
 
 //measuring function - returning whether it is black or white line 
 //"1" - black, "0" - white
 int measure (sensor_data sensor){
+
+
+    
     sensorTimer.reset();
     int freq,period = 0;
     int n =0; //number of samples
@@ -55,14 +72,16 @@
     
     while (n < NUMBER_SAMPLES){
         
-        if (sensor.pin == 1 && sensor_old == 0){ // detect on rising edge
+        if (*sensor.pin == 1 && sensor_old == 0){ // detect on rising edge
             n++;
         }
-        sensor_old = sensor.pin;
+        sensor_old = *sensor.pin;
     }
     
     period = sensorTimer.read_us()/(float)n; // Get time
     freq = (1/period)*1000000;   // Convert period (in us) to frequency (Hz). Works up to 100kHz. 
-    return freq;
+    
+    
+    return (freq < sensor.black_value*2)? 1 : 0;
 }
 #endif
\ No newline at end of file