THE PROBLEM STATEMENT
To construct an autonomous machine(15x25cm minimum size) which searches for a vacant place in a jammed parking lot and “parks” itself there without touching any other vehicle present there. After a delay of a few seconds, it has to come out of there and park itself in the next vacant place.
THE ALGORITHM
This was the first complete algorithm. It has been modified a little during the completion of the bot.
int turnvar=1,left=0,right=0;
while(1)
{
Readsensors();// Reads all sensors
if(s2=0 && s4=0 && s5=0)
{
if(turnvar ==1 || turnvar==2)
{
turn_hard_right();//turns bot 90 degrees on spot to right
ctr1(); //starts counter 1
right=1;
turnvar++;
}else if(turnvar==3)
{
calibrated_right_turn();//turns bot right based on calculated steps
turnvar++;
}else
{
turn_right();//turns right 90 degrees abt left wheel
ctr2();//starts counter 2
right=1;
turnvar++;
}
}else if(s1==0 && s3==0 && s5=0)
{
if(turnvar ==1 || turnvar==2)
{
turn_hard_left();//turns bot 90 degrees on spot to left
ctr1();
left=1;
turnvar++;
}else if(turnvar==5 || turnvar==6)
{
calibrated_left_turn();//turns bot left based on calculated steps
turnvar++;
}else
{
turn_left();//turns left 90 degrees abt left wheel
ctr2();
left=1;
turnvar++;
}
}else if(s5 == 1)
{
park();
}else go_forward(); //goes forward predetermined steps
}
park()
{ if(ctr1()!=0)
{
if(right == 1)
{
stop_ctr1();
parking_indicator();//turns on a led for sometime
while(ctr1()!= 0)
{
go_back(); //goes back predetermined steps
decrement_ctr1();
}
turn_hard_left();
right=0;
}
else if(left ==1)
{
stop_ctr1();
parking_indicator();
while(ctr1()!=0)
{
go_back();
decrement_ctr1();
}
turn_hard_right();
left=0;
}
}else if(ctr2()!=0)
{
if(right==1)
{
stop_ctr2();
turn_left();
parking_indicator();
turn_left();
while(ctr2()!=0)
{
go_forward();
decrement_ctr2();
}
turn_right();
}
else if(left==1)
{
stop_ctr2();
turn_right();
parking_indicator();
turn_right();
while(ctr2()!=0)
{
go_forward();
decrement_ctr2();
}
turn_left();
}
}
This is a companion discussion topic for the original entry at https://community.robotshop.com/robots/show/duo-x