go_away

Author Topic: regarding the autocalibration method  (Read 4783 times)

0 Members and 1 Guest are viewing this topic.

Offline andreahmedTopic starter

  • Jr. Member
  • **
  • Posts: 37
  • Helpful? 0
regarding the autocalibration method
« on: December 11, 2006, 08:48:55 AM »
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: [Select]
#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; 
cin>>left_sensor_white;
    cin>>left_sensor_black;
cin>>right_sensor_white;
cin>>right_sensor_black;
 
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<<"TH_Left_Sensor"<<th_l<<endl;

while(1)
{

cout<<"Input new values from the sensors"<<endl;
cin>>ADC_R;
    cin>>ADC_L;

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

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


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


}
}


Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,666
  • Helpful? 169
    • Society of Robots
Re: regarding the autocalibration method
« Reply #1 on: December 11, 2006, 09:22:45 AM »
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;
cin>>left_sensor_black;
while(button=0);//wait until you move robot so sensors can see other condition
cin>>right_sensor_white;
cin>>right_sensor_black;

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;
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.

Offline andreahmedTopic starter

  • Jr. Member
  • **
  • Posts: 37
  • Helpful? 0
Re: regarding the autocalibration method
« Reply #2 on: December 11, 2006, 09:39:41 AM »
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
« Last Edit: December 11, 2006, 09:43:55 AM by andreahmed »

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,666
  • Helpful? 169
    • Society of Robots
Re: regarding the autocalibration method
« Reply #3 on: December 11, 2006, 11:52:23 AM »
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=sensor1-sensor2
B=sensor2-sensor3
C=sensor3-sensor4
D=sensor4-sensor5

(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.
etc.

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

Offline andreahmedTopic starter

  • Jr. Member
  • **
  • Posts: 37
  • Helpful? 0
Re: regarding the autocalibration method
« Reply #4 on: December 11, 2006, 06:33:49 PM »
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 ?

Offline andreahmedTopic starter

  • Jr. Member
  • **
  • Posts: 37
  • Helpful? 0
Re: regarding the autocalibration method
« Reply #5 on: December 12, 2006, 08:10:57 AM »
waiting for the answers please -_-  ::)

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,666
  • Helpful? 169
    • Society of Robots
Re: regarding the autocalibration method
« Reply #6 on: December 12, 2006, 09:14:33 AM »
impatient i see  :P

The way I do it is:
my first reading the robot is off the line entirely
system reads sensors, then waits for next command
the second reading ALL sensors are on the line (i turn my bot sideways)
system reads sensors again

it will become obvious when you do it, i think

so you run a find max algorithm, and only store the two highest values.
max=0
if a>max, then max = a
if b>max, then max = b
etc.
then to find second max:
max2=0
if a>max2 != max, then max2 = a
if b>max2 != max, then max2 = b
etc.

Offline andreahmedTopic starter

  • Jr. Member
  • **
  • Posts: 37
  • Helpful? 0
Re: regarding the autocalibration method
« Reply #7 on: December 12, 2006, 10:04:45 AM »
thanks alot
 ;D
i will try it and will tell ya the results , hope it works with the blue background .

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,666
  • Helpful? 169
    • Society of Robots
Re: regarding the autocalibration method
« Reply #8 on: December 12, 2006, 06:44:56 PM »
i dont know why i didnt send this line following stuff to you earlier!!!
http://www.societyofrobots.com/competitions_mobot.shtml

and videos
http://www.societyofrobots.com/competitions_mobot_video.shtml

 


Get Your Ad Here

data_list