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

why wont the bumper run my code when i press it?
http://www.robotc.net/forums/viewtopic.php?f=11&t=4788
Page 1 of 1

Author:  themigthy [ Sat Sep 01, 2012 2:54 pm ]
Post subject:  why wont the bumper run my code when i press it?

why wont my autonomous run when I press the bumper?

task autonomous()
{
Code:
 int threshold = 1000; 
     
      ClearTimer (T1);
      while(time1[T1] < 1000){


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)
    {
      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:
 motor[frontRight] = 100;
      motor[backRight] = 100;
      motor[frontLeft] = -100;
      motor[backLeft] = -100;
     wait1Msec(450);


}
AutonomousCodePlaceholderForTesting();
}

Code:
task mian(){

     if(SensorValue(bump) == 1){
       StartTask(autonomous); 
     }

}

Author:  JohnWatson [ Tue Sep 04, 2012 10:46 am ]
Post subject:  Re: why wont the bumper run my code when i press it?

Task main is misspelled (task mian). Try to see if that solves it for you, if not let us know.

Author:  jbflot [ Mon Oct 01, 2012 2:52 pm ]
Post subject:  Re: why wont the bumper run my code when i press it?

Think about how your robot "flows" through the program. Your robot's starting point is always "task main()".

Based on your code in task main, the robot will check ONCE if "bump" is pressed, then move on. There's nothing else in your code, so the program ends and the robot does nothing.

What you want to do is wait until the touch sensor is pressed, not just check if it is pressed and move on. You can do this by changing your logic based off of the following pseducode;

Code:
while(the touch sensor is NOT pressed)
{
...do nothing
}
StartTask(autonomous);

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