ROBOTC.net forums
http://www.robotc.net/forums/

why wont my line tracking code work correctly?
http://www.robotc.net/forums/viewtopic.php?f=11&t=4601
Page 1 of 1

Author:  themigthy [ Sat Jun 02, 2012 10:10 pm ]
Post subject:  why wont my line tracking code work correctly?

I am basically just trying to run this piece of code for 1 second but it doesn't it just keeps on running.

if(vexRT[Btn5U] == 1)

{
Code:
    // RIGHT sensor sees dark:


           if(SensorValue(rightline) > threshold)
       {
      // counter-steer right:
      motor[frontleft] = 63;
     motor[backleft] = 63;
     motor[frontright] = 0;
     motor[backright] = 0;
       }


Code:
    // CENTER sensor sees dark:
          if(SensorValue(center) > threshold)

       {

      // go straight
      motor[frontleft] = 63;
     motor[backleft] = 63;
     motor[frontright] = 63;
     motor[backright] = 63;
       }


Code:
    // LEFT sensor sees dark:
          if(SensorValue(leftline) > threshold)

       {

      // counter-steer left:
      motor[frontleft] = 0;
     motor[backleft] = 0;
     motor[frontright] = 63;
     motor[backright] = 63;
    }

}
Code:
 wait1Msec(1000);

Author:  magicode [ Sun Jun 03, 2012 5:34 am ]
Post subject:  Re: why wont my line tracking code work correctly?

Is this your whole code? Is there a while loop around the whole thing? In any case, here's how you would accomplish this with timers:
Code:
clearTimer(T1);
while(time1[T1] < 1000){
  //code
}

Author:  themigthy [ Sun Jun 03, 2012 2:54 pm ]
Post subject:  Re: why wont my line tracking code work correctly?

Yes there is a while loop I just forgot to add it.

Author:  JohnWatson [ Wed Jun 06, 2012 5:43 pm ]
Post subject:  Re: why wont my line tracking code work correctly?

Code:
     motor[frontleft] = 0;
     motor[backleft] = 0;
     motor[frontright] = 0;
     motor[backright] = 0;


Gotta stop the motors when you're done :) It's going through the loop for 1 second, but whatever the last state it was in (go left, go right, etc) is being held to the motor values until you stop them.

Edit: I am entirely incorrect in this (I don't know why I thought this was true, this is what I get for trying to finish things right before the end of work :P), it might be something with the loop that's causing problems. Sorry for the misinformation!

Author:  mmckee [ Thu Jun 07, 2012 8:53 am ]
Post subject:  Re: why wont my line tracking code work correctly?

themighty, can you post the while loop? If your code never stops, it is usually an issue relating to the condition of the while loop.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/