Society of Robots - Robot Forum
Software => Software => Topic started by: robotmir on March 30, 2009, 02:03:41 PM
-
i want to count each junction of line that my robot pass though, but this coding wont work.the counting was TOO fast and the robot didnt even start following the line....can anyone help me??urgent....
:( :(
void line_follower2(unsigned int8 juncnum)
{
unsigned int i;
i = 0;
while(i<juncnum)
{
if ((input(IR1) == 0) && (input(IR2) == 0))
{
motor_direction(forward);
}
else if ((input(IR1) == 0) && (input(IR2) == 1))
{
motor_direction(small_left);
}
else if ((input(IR1) == 1) && (input(IR2) == 0))
{
motor_direction(small_right);
}
else if ((input(IR1) == 1) && (input(IR2) == 1))
{
i++;
}
}
}
-
else if ((input(IR1) == 1) && (input(IR2) == 1))
{
while((input(IR1) == 1) && (input(IR2) == 1));
i++;
}
This make it so that while it sees the junction, it will wait for the robot to pass over it before it increments the counter.
-
i did add the function u suggested, and in the main(void) i did this
void main(void)
{
while(1)
{
line_follower2(2); //line1
output_high(buzzer); //line2
delay_ms(1000); //line3
motor_stop(); //line 4
}
}
*the problem is, the while(1) loop is doing line1 ,line2, line3, and line 4 all at the same time..,i dont understand why is this happening...should the compiler wait until the condition in line_follower2(2) to finish first, then start doing other instruction???? this is very confusing for me ???
-
anyone??