
Team Design project 3 main file
Dependencies: LocalPositionSystem MMA8451Q Motor_Driver Sensors mbed
Fork of TDP_main by
Diff: sensor_measure.h
- Revision:
- 37:3d14df6dec34
- Parent:
- 36:a48d57d63630
--- a/sensor_measure.h Wed Mar 25 11:50:44 2015 +0000 +++ b/sensor_measure.h Thu Mar 26 20:13:49 2015 +0000 @@ -30,7 +30,9 @@ DigitalIn pin_left_left_down(PTE22); //pte22 DigitalIn pin_left_right_up(PTE23); //pte29 DigitalIn pin_left_left_up(PTB2); - +DigitalIn pin_center_left (PTC7); +DigitalIn pin_center_center (PTC0); +DigitalIn pin_center_right (PTC3); //timer used by the sensor Timer sensorTimer; @@ -56,62 +58,77 @@ sensor_data left_left_down; sensor_data left_right_up; sensor_data left_left_up; +sensor_data center_left; +sensor_data center_center; +sensor_data center_right; // and so on.... -sensor_data *sensorArray [NUMBER_SENSORS_REGULAR]; //array just used for getting value out of the sensors, helps for iteration(see main program) +sensor_data *sensorArray [NUMBER_SENSORS_REGULAR+3]; //array just used for getting value out of the sensors, helps for iteration(see main program) //Initialise values of all sensors void sensor_initialise () { int arrayBuilder = 0; //integer solely used for populating the array //right_right right_right_up.pin = &pin_right_right_up; - right_right_up.blackValue = 18000*BLACK_THRESHOLD; + right_right_up.blackValue = 4200*BLACK_THRESHOLD; right_right_up.whiteValue = 72000; right_right_up.grayValue = 0; // 0 for all the non-square sensors right_right_up.state = 0; //setting all sensors as black at begging sensorArray [arrayBuilder++] = &right_right_up; //Array goes from rightmost to left, then centre? right_left_up.pin = &pin_right_left_up; - right_left_up.blackValue = 11500*BLACK_THRESHOLD; + right_left_up.blackValue = 5000*BLACK_THRESHOLD; right_left_up.whiteValue = 70000; right_left_up.grayValue = 0; right_left_up.state = 1; sensorArray [arrayBuilder++] = &right_left_up; right_right_down.pin = &pin_right_right_down; - right_right_down.blackValue = 4000*BLACK_THRESHOLD; + right_right_down.blackValue = 900*BLACK_THRESHOLD; right_right_down.whiteValue = 12000; right_right_down.grayValue = 0; right_right_down.state = 0; sensorArray [arrayBuilder++] = &right_right_down; right_left_down.pin = &pin_right_left_down; - right_left_down.blackValue = 2500*BLACK_THRESHOLD; + right_left_down.blackValue = 1500*BLACK_THRESHOLD; right_left_down.whiteValue = 17000; right_left_down.grayValue = 0; right_left_down.state = 1; sensorArray[arrayBuilder++] = &right_left_down; left_right_down.pin = &pin_left_right_down; - left_right_down.blackValue = 1800*BLACK_THRESHOLD; + left_right_down.blackValue = 1000*BLACK_THRESHOLD; left_right_down.whiteValue = 14000; left_right_down.grayValue = 0; left_right_down.state = 1; sensorArray [arrayBuilder++] = &left_right_down; left_left_down.pin = &pin_left_left_down; - left_left_down.blackValue = 3000*BLACK_THRESHOLD; + left_left_down.blackValue = 1000*BLACK_THRESHOLD; left_left_down.whiteValue = 10000; left_left_down.grayValue = 0; left_left_down.state = 0; sensorArray [arrayBuilder++] = &left_left_down; left_right_up.pin = &pin_left_right_up; - left_right_up.blackValue = 9500*BLACK_THRESHOLD; //??? it's a trick ;) + left_right_up.blackValue = 5000*BLACK_THRESHOLD; //??? it's a trick ;) left_right_up.whiteValue = 35000; left_right_up.grayValue = 0; left_right_up.state = 1; sensorArray [arrayBuilder++] = &left_right_up; left_left_up.pin = &pin_left_left_up; - left_left_up.blackValue = 12000*BLACK_THRESHOLD; + left_left_up.blackValue = 9500*BLACK_THRESHOLD; left_left_up.whiteValue = 46000; left_left_up.grayValue = 0; left_left_up.state = 0; sensorArray [arrayBuilder++] = &left_left_up; + center_left.pin = &pin_center_left; + center_left.grayValue = 0; + center_left.state = 0; + sensorArray [arrayBuilder++] = ¢er_left; + center_center.pin = &pin_center_center; + center_center.grayValue = 0; + center_center.state = 0; + sensorArray [arrayBuilder++] = ¢er_center; + center_right.pin = &pin_center_right; + center_right.grayValue = 0; + center_right.state = 0 ; + sensorArray [arrayBuilder++] = ¢er_right; } int counter1 = 0; @@ -139,22 +156,22 @@ freq = (1/period); // Convert period (in us) to frequency (Hz). //pc.printf(" period is %f and freq is %f ", period,freq); // Used for debugging - // sensor->state = freq; -// return 0; + sensor->state = freq; + return 0; // if (sensor->grayValue != 0 && freq < (sensor->grayValue + 1000) && freq > (sensor.grayValue - 1000)) { //definitely not sure about that! // //this is a gray value sensor in its gray region // sensor->state = 2; // return 2; // } - if (freq < (sensor->blackValue)){ - sensor->state = 0; //if it's less than black value it is black - return 0; - } - else { - sensor->state = 1; - } - return 1; +// if (freq < (sensor->blackValue)){ +// sensor->state = 0; //if it's less than black value it is black +// return 0; +// } +// else { +// sensor->state = 1; +// } +// return 1; //(freq < sensor->black_value*2)? 1 : 0; //freq } #endif \ No newline at end of file