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

0 Members and 1 Guest are viewing this topic.

Offline robotmirTopic starter

  • Jr. Member
  • **
  • Posts: 21
  • Helpful? 0
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++;

                }

}
}

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,856
  • Helpful? 53
    • RazorConcepts
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.

Offline robotmirTopic starter

  • Jr. Member
  • **
  • Posts: 21
  • Helpful? 0
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 ???

Offline robotmirTopic starter

  • Jr. Member
  • **
  • Posts: 21
  • Helpful? 0
anyone??

 


Get Your Ad Here

data_list