View unanswered posts | View active topics It is currently Fri Nov 28, 2014 2:12 pm






Reply to topic  [ 5 posts ] 
why wont my line tracking code work correctly? 
Author Message
Rookie

Joined: Wed Dec 21, 2011 4:22 pm
Posts: 26
Post 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);


Sat Jun 02, 2012 10:10 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post 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
}

_________________
sudo rm -rf /


Sun Jun 03, 2012 5:34 am
Profile
Rookie

Joined: Wed Dec 21, 2011 4:22 pm
Posts: 26
Post Re: why wont my line tracking code work correctly?
Yes there is a while loop I just forgot to add it.


Sun Jun 03, 2012 2:54 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 610
Post 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!

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Last edited by JohnWatson on Thu Jun 07, 2012 9:20 am, edited 2 times in total.



Wed Jun 06, 2012 5:43 pm
Profile
Moderator
Moderator

Joined: Thu Jun 09, 2011 10:14 am
Posts: 7
Location: Pittsburgh, PA
Post 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.

_________________
Matt McKee
Robotics Academy
Carnegie Mellon University

ROBOTC homepage
Robotics Academy homepage


Thu Jun 07, 2012 8:53 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.