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

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

Author:  themigthy [ Fri May 11, 2012 7:57 pm ]
Post subject:  why wont my line tracking code work?

I installed this code to my robot for my autonomous program i want it to turn then go forward and then follow a black strip of tape.
the robot turns and moves towards the black line but the sensors wont follow the black line, and the sensors are right on the line. its like the program ends as soon as the robot moves forward. Magiccode if you reed this i am sorry if the code is not organized, i didnt get how you told me to do it.

Code:
while (true)
{
 
    if(SensorValue(touch) == 1) // if the vex bumper id touched then it will run the program
    {
     motor[frontright] = 60; //this will make the robot turn
    motor[backright] = 60;
    motor[frontleft] = -60;
    motor[backLeft] = -60;
    wait1Msec(700);

    motor[frontright] = 60;
    motor[backright] = 60; //this will make the robot go forward
    motor[frontleft] = 60;
    motor[backLeft] = 60;
    wait1Msec(600);
   
    int threshold = 1500;


    if(SensorValue(right) > threshold)
    {

    motor[frontright] = 60;
    motor[backright] = 60;
    motor[frontleft] = 0;
    motor[backLeft] = 0;
    }

    if(SensorValue(middle) > threshold)
    {

    motor[frontright] = 60;
    motor[backright] = 60;
    motor[frontleft] = 60;
    motor[backLeft] = 60;
    }

    if(SensorValue(left) > threshold)
    {
    motor[frontright] = 0;
    motor[backright] = 0;
    motor[frontleft] = 70;
    motor[backLeft] = 70;
    }
   

 }

Author:  magicode [ Fri May 11, 2012 8:11 pm ]
Post subject:  Re: why wont my line tracking code work?

Just press edit on your post, and take a look at the "code" tags that are around the code. Also, make sure that you're copying your whole program, as I see a missed curly bracket. As for your program, try to step through your program like the microcontroller would, seeing when each condition is met. Here's some pseudocode for what it's doing assuming the missed curly bracket goes at the end:
Code:
Do forever{
  if the button is pressed{
    do stuff....
  }
}

Unless you keep button pushed down through the entire program, it will only go forward an turn.

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