### Author Topic: line following robot junction counting loop not working, need help from experts.  (Read 2663 times)

0 Members and 1 Guest are viewing this topic.

#### robotmir

• Jr. Member
• Posts: 21
##### line following robot junction counting loop not working, need help from experts.
« 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++;

}

}
}

#### Razor Concepts

• Supreme Robot
• Posts: 1,855
##### Re: line following robot junction counting loop not working, need help from experts.
« Reply #1 on: March 30, 2009, 03:13:33 PM »
Code: [Select]
`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.

#### robotmir

• Jr. Member
• Posts: 21
##### Re: line following robot junction counting loop not working, need help from experts.
« Reply #2 on: March 30, 2009, 09:55:17 PM »
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

• Jr. Member
• Posts: 21