
Don't want to screw something by updating the code as Ivelin updated himself while I was writing so I am forking it.
Dependencies: LocalPositionSystem MMA8451Q Motor_Driver Sensors mbed
Fork of TDP_main by
Diff: sensor_measure.h
- Revision:
- 17:de8b3111ddc5
- Parent:
- 16:3649eb1a056d
- Child:
- 19:d277614084bc
--- a/sensor_measure.h Fri Mar 13 18:19:01 2015 +0000 +++ b/sensor_measure.h Wed Mar 18 16:55:14 2015 +0000 @@ -17,18 +17,18 @@ #define _SENSOR_MEASURE_H #define NUMBER_SAMPLES 20 // NUMBER OF SAMPLES FOR SENSOR TESTING -#define NUMBER_SENSORS_REGULAR 4 // number for the array of sensors +#define NUMBER_SENSORS_REGULAR 8 // number for the array of sensors #define NUMBER_SENSORS_SQUARE 0 //define pinout for all the sensors -DigitalIn pin_right_right_up(PTE5); -DigitalIn pin_right_left_up(PTE2); +DigitalIn pin_right_right_up(PTE2); +DigitalIn pin_right_left_up(PTE5); DigitalIn pin_right_right_down(PTE3); DigitalIn pin_right_left_down(PTE4); -DigitalIn pin_left_right_down(PTD4); -DigitalIn pin_left_left_down(PTD5); -//DigitalIn pin_left_right_up(); -//DigitalIn pin_left_left_up(); +DigitalIn pin_left_right_down(PTE23); +DigitalIn pin_left_left_down(PTE29); //pte22 +DigitalIn pin_left_right_up(PTE22); //pte29 +DigitalIn pin_left_left_up(PTE30); //timer used by the sensor @@ -64,21 +64,53 @@ int arrayBuilder = 0; //integer solely used for populating the array //right_right right_right_up.pin = &pin_right_right_up; - right_right_up.blackValue = 2013; - right_right_up.whiteValue = 10000; + right_right_up.blackValue = 10000; + right_right_up.whiteValue = 48000; 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 = 6000; - right_left_up.whiteValue = 10000; + right_left_up.blackValue = 30000; + right_left_up.whiteValue = 115000; right_left_up.grayValue = 0; - right_left_up.state = 0; + right_left_up.state = 1; sensorArray [arrayBuilder++] = &right_left_up; right_right_down.pin = &pin_right_right_down; + right_right_down.blackValue = 7000; + right_right_down.whiteValue = 20000; + 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; + right_left_down.whiteValue = 25000; + 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; + left_right_down.whiteValue = 21000; + 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; + left_left_down.whiteValue = 21000; + 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 = 25000; //??? it's a trick ;) + left_right_up.whiteValue = 79000; + 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; + left_left_up.whiteValue = 120000; + left_left_up.grayValue = 0; + left_left_up.state = 0; + sensorArray [arrayBuilder++] = &left_left_up; //and contiune so on.. } @@ -107,20 +139,20 @@ 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; + //sensor->state = freq; // 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; // } -// else if (freq < sensor->blackValue*2){ -// sensor->state = 0; //if it's less than black value it is black -// return 0; -// } -// else { -// sensor->state = 1; -// } + if (freq < (2*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 }