grid following object height detection robot
m using arduino mega make grid following robot check heights of 3 blocks placed @ node...my bot works fine uptil coordinate(3,6) , line follows without detecting node henceforthif encounters 1 or 2 blocks in mean time....if not encounter block till then works till (3,3) , has same problem...pls help!
code: [select]
void grid_check()
{
if (
(!digitalread(els)) && (!digitalread(ers)) && (!digitalread(ls)) && (!digitalread(ms)) && (!digitalread(rs)) //if @ grid
)
{
motorcontrol(0,0);
lcd.clear(); lcd.setcursor(0,0); lcd.print(x); lcd.print(y); //print coods
if(x==0 && y==0)
{
turn_left();
f=forward_sensor();
lcd.setcursor(0,1);lcd.print(f);
if(f<23) //00
{
n++;
c=millis();
while(c+700>millis()) {line_follow();}
motorcontrol(0,0);
height_sensorforward();
gripper_hold();
u_turn();
c=millis();
while(c+500>millis()) {line_follow();}
gripper_release();
c=millis();
while(c+700>millis()) {motorcontrol(2,2);}
u_turn();
}
else //00
{
c=millis();
while(c+500>millis()) {line_follow();}
}
goto a;
}
if(x==1 && y==0)
{
turn_right();
f=forward_sensor();
l=left_sensor();
lcd.setcursor(0,1);lcd.print(l);lcd.print(" ");lcd.print(f);
if(l<23) //10
{
n++;
turn_left();
height_sensor();
turn_right_block();
}
if(f<23) //10
{
n++;
c=millis();
while(c+700>millis()) {line_follow();}
motorcontrol(0,0);
height_sensorforward();
gripper_hold();
u_turn();
c=millis();
while(c+500>millis()) {line_follow();}
gripper_release();
c=millis();
while(c+700>millis()) {motorcontrol(2,2);}
u_turn();
}
if( (l>23 && f>23) || (l<23 && f>23) ) //10
{
c=millis();
while(c+500>millis()) {line_follow();}
}
goto a;
}
if( (x==1 && y==1) || (x==1 && y==2) || (x==1 && y==3) || (x==1 && y==4) || (x==1 && y==5) )
{
l=left_sensor();
r=right_sensor();
f=forward_sensor();
lcd.setcursor(0,1);lcd.print(l);lcd.print(" ");lcd.print(r);lcd.print(" ");lcd.print(f);
if(l<23 && r>23) //11 12 13 14 15
{
n++;
turn_left();
height_sensor();
turn_right_block();
}
if(r<23 && l>23) //11 12 13 14 15
{
n++;
turn_right();
height_sensor();
turn_left_block();
}
if(r<23 && l<23)
{
n=n+2;
turn_right();
height_sensor();
u_turn();
height_sensor();
turn_right_block();
}
if(f<23) //11 12 13 14 15
{
n++;
c=millis();
while(c+700>millis()) {line_follow();}
motorcontrol(0,0);
height_sensorforward();
gripper_hold();
u_turn();
c=millis();
while(c+500>millis()) {line_follow();}
gripper_release();
c=millis();
while(c+700>millis()) {motorcontrol(2,2);}
u_turn();
}
c=millis();
while(c+500>millis()) {line_follow();}
goto a;
}
if(x==1 && y==6)
{
r=right_sensor();
lcd.setcursor(0,1);lcd.print(r);
if(r<23) //16
{
n++;
turn_right();
height_sensor();
u_turn();
}
if(r>23)
{
turn_left();
}
f=forward_sensor();
lcd.setcursor(5,1);lcd.print(f);
if(f<23) //16
{
n++;
c=millis();
while(c+700>millis()) {line_follow();}
motorcontrol(0,0);
height_sensorforward();
gripper_hold();
u_turn();
c=millis();
while(c+500>millis()) {line_follow();}
gripper_release();
c=millis();
while(c+700>millis()) {motorcontrol(2,2);}
u_turn();
}
if(f>23) //16
{
c=millis();
while(c+500>millis()) {line_follow();}
}
goto a;
}
if(x==3 && y==6)
{
turn_left();
r=right_sensor();
f=forward_sensor();
lcd.setcursor(0,1);lcd.print(r);lcd.print(" ");lcd.print(f);
if(r<23) //36
{
n++;
turn_right();
height_sensor();
turn_left_block();
}
if(f<23) //36
{
n++;
c=millis();
while(c+700>millis()) {line_follow();}
motorcontrol(0,0);
height_sensorforward();
gripper_hold();
u_turn();
c=millis();
while(c+500>millis()) {line_follow();}
gripper_release();
c=millis();
while(c+700>millis()) {motorcontrol(2,2);}
u_turn();
}
c=millis();
while(c+500>millis()) {line_follow();}
goto a;
}
if( (x==3 && y==5) || (x==3 && y==4) || (x==3 && y==3) || (x==3 && y==2) || (x==3 && y==1) )
{
r=right_sensor();
f=forward_sensor();
lcd.setcursor(0,1);lcd.print(r);lcd.print(" ");lcd.print(f);
if(r<23) //35 34 33 32 31
{
n++;
turn_right();
height_sensor();
turn_left_block();
}
if(f<23) //35 34 33 32 31
{
n++;
c=millis();
while(c+700>millis()) {line_follow();}
motorcontrol(0,0);
height_sensorforward();
gripper_hold();
u_turn();
c=millis();
while(c+500>millis()) {line_follow();}
gripper_release();
c=millis();
while(c+700>millis()) {motorcontrol(2,2);}
u_turn();
}
c=millis();
while(c+500>millis()) {line_follow();}
goto a;
}
if(x==3 && y==0)
{
r=right_sensor();
lcd.setcursor(0,0);lcd.print(x);lcd.print(y);
lcd.setcursor(0,1);lcd.print(r);
if(r<23) //30
{
n++;
turn_right();
height_sensor();
turn_left_block();
}
motorcontrol(0,0); delay(100000); //reduce delay in final stepup
}
a:
if(dir=='n') y++;
else if(dir=='s') y--;
else if(dir=='w') x++;
else if(dir=='e') x--;
}
else {line_follow();}
}
void loop()
{
while(n<3)
{
grid_check();
}
}
"goto"s and recursion?
incoming!
edit: misread it.
still, no "line_follow" function.
nice comment
incoming!
edit: misread it.
still, no "line_follow" function.
code: [select]
if(r<23) //35 34 33 32 31
nice comment
Arduino Forum > Using Arduino > Project Guidance > grid following object height detection robot
arduino
Comments
Post a Comment