Software > Software

regarding the autocalibration method

(1/2) > >>

Hi, i've read the page about the autocalibrationg method here and tried to write a code based on it and wanna know if it works or not , im going to robocon Egypt 2007 contest and the background on the floor is blue and the line is white.. i've tried to simulate the algorithm in VC++6 , im going to use atmega 8 ..

--- Code: ---#include <iostream>
  #include <bitset>

   using namespace std;

    int left_sensor_white;
int left_sensor_black;
int right_sensor_white;
    int right_sensor_black;
int th_r;
int th_l;
    int ADC_R,ADC_L; // getting new values from Right , Left Sensors
    unsigned char byte;
void main()
bool right;
    bool left; 
th_r= (right_sensor_white + right_sensor_black)/2;
th_l= (left_sensor_black + left_sensor_black)/2;
   cout<<" TH_Right_Sensor"<<th_r<<endl;


cout<<"Input new values from the sensors"<<endl;

if ( ADC_R >= th_r)
else {right=0;};

if( ADC_L >= th_l)
} else {left=0;}

cout<<" LEFT"<<left<<"Right"<<right<<endl;


--- End code ---

yeap, you got the right idea. its 99% correct.

two comments . . .

when gathering initial sensor inputs, put a button operated pause in your code:

--- Quote ---cin>>left_sensor_white;
while(button=0);//wait until you move robot so sensors can see other condition

--- End quote ---

when you determine your threshold, assuming you are using an 8 bit ADC, rewrite it as this:

--- Quote ---th_r= right_sensor_white/2 + right_sensor_black/2;
th_l= left_sensor_black/2 + left_sensor_black/2;

--- End quote ---
it means the same thing, but avoids 8 bit int overflows.

there is one flaw in the autothresholding code that you will probably not encounter -> if the ambient light changes drastically after calibration (such as clouds blocking the sunlight coming in through the windows of the room you are in).

also, since blue contrasts really well with a white line, you may just want to use differencing code, meaning that if two similar sensors get two very different readings, you can assume one is on the line and the other isnt. this removes ambient light problems. the thresholding method works best for 1 or 2 sensors, while the differencing method works better for 3 or more.

thanks alot for your reply , could you please write a pseudo code about the ambient light problem , and the blue problem ?
i intend to use 6 sensors , 5 for line follower and 1 as counter ( it counts the crossed line ) .

last year i used LDRs with compartors it worked but were so bad (manual calibration) , i wish the autoworks, im so scared really i've no time for the contest and dont trust myself :( .

thanks again

this method ignores ambient light, but you need at least 3 sensors for it

do this pseudocode as a loop:

store each sensor value in an array
array = [sensor1, sensor2, sensor3, sensor4, sensor5]

now find the maximum and 2nd maximum value of these equations:

(a maximum means a line edge is detected there)

lets assume B and C are the highest -> that means the line is between B and C.
if the highest were A and B, that means the line is on the left, so you need to turn left.

its basically edge detection with photoresistors.

as for the ambient light problem
suppose its dark in a room and your robot runs the thresholding algorithm. now your robot goes halfway down the course, then suddenly really bright sunlight comes in the windows -> the thresholds now become invalid and your robot starts attacking kittens  :P

thanks alot !
i've some comments , array=[sensorx]
sensor_1,2,3 are getting their values without putting them on the white strip once and on the blue strip ?

i can get the maximum of the some values but the 2nd max element how to do it ?


[0] Message Index

[#] Next page

Go to full version