
Team Design project 3 main file
Dependencies: mbed Motor_Driver Sensors MMA8451Q LocalPositionSystem
Fork of TDP_main by
Diff: sensor_measure.h
- Revision:
- 30:307b45a52401
- Parent:
- 23:9b53c72fcd38
- Child:
- 32:d1dc27f4a18d
--- a/sensor_measure.h Mon Mar 23 14:23:21 2015 +0000 +++ b/sensor_measure.h Mon Mar 23 16:42:27 2015 +0000 @@ -22,14 +22,14 @@ #define BLACK_THRESHOLD 2 //define pinout for all the sensors -DigitalIn pin_right_right_up(PTE29); -DigitalIn pin_right_left_up(PTC1); -DigitalIn pin_right_right_down(PTC2); -DigitalIn pin_right_left_down(PTE30); -DigitalIn pin_left_right_down(PTB2); +DigitalIn pin_right_right_up(PTC2); +DigitalIn pin_right_left_up(PTE30); +DigitalIn pin_right_right_down(PTE29); +DigitalIn pin_right_left_down(PTC1); +DigitalIn pin_left_right_down(PTB3); DigitalIn pin_left_left_down(PTE22); //pte22 -DigitalIn pin_left_right_up(PTB3); //pte29 -DigitalIn pin_left_left_up(PTE23); +DigitalIn pin_left_right_up(PTE23); //pte29 +DigitalIn pin_left_left_up(PTB2); //timer used by the sensor @@ -65,50 +65,50 @@ int arrayBuilder = 0; //integer solely used for populating the array //right_right right_right_up.pin = &pin_right_right_up; - right_right_up.blackValue = 10000*BLACK_THRESHOLD; - right_right_up.whiteValue = 48000; + right_right_up.blackValue = 8500*BLACK_THRESHOLD; + right_right_up.whiteValue = 37000; 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 = 30000*BLACK_THRESHOLD; - right_left_up.whiteValue = 115000; + right_left_up.blackValue = 10500*BLACK_THRESHOLD; + right_left_up.whiteValue = 37000; 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 = 7000*BLACK_THRESHOLD; - right_right_down.whiteValue = 20000; + right_right_down.blackValue = 1500*BLACK_THRESHOLD; + right_right_down.whiteValue = 7300; 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 = 8000*BLACK_THRESHOLD; - right_left_down.whiteValue = 25000; + right_left_down.blackValue = 2500*BLACK_THRESHOLD; + right_left_down.whiteValue = 11000; 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 = 2500*BLACK_THRESHOLD; - left_right_down.whiteValue = 21000; + left_right_down.blackValue = 1800*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 = 6500*BLACK_THRESHOLD; - left_left_down.whiteValue = 21000; + left_left_down.blackValue = 4500*BLACK_THRESHOLD; + left_left_down.whiteValue = 18000; 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 = 20000*BLACK_THRESHOLD; //??? it's a trick ;) - left_right_up.whiteValue = 79000; + left_right_up.blackValue = 11500*BLACK_THRESHOLD; //??? it's a trick ;) + left_right_up.whiteValue = 63000; 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 = 27000*BLACK_THRESHOLD; - left_left_up.whiteValue = 120000; + left_left_up.blackValue = 20000*BLACK_THRESHOLD; + left_left_up.whiteValue = 80000; left_left_up.grayValue = 0; left_left_up.state = 0; sensorArray [arrayBuilder++] = &left_left_up; @@ -139,22 +139,21 @@ 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; + // 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