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

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

Author:  themigthy [ Sat Sep 01, 2012 3:53 pm ]
Post subject:  why wont the code run when i press the bumper?

I'am experimenting to make a autonomous, but i ran across the problem that my autonomous code wont run when the bumper is pressed. I have also tried to place the if statement for if the bumper is touched once on the user control section of the program, but that was a fail.

Code:
task autonomous()
{
 while(true){
  if(SensorValue(bump) == 1){ 
 
  motor[armmotor] = 100;
  wait1Msec(200);
 
    }
  }
   AutonomousCodePlaceholderForTesting();
}

Author:  JohnWatson [ Wed Sep 05, 2012 9:36 am ]
Post subject:  Re: why wont the code run when i press the bumper?

We would have to see the rest of the code (including task main) to see if it's even getting to the autonomous task. One thing I might recommend is using functions instead of tasks; generally speaking, they can do what most users need them to without having to worry about CPU micromanagement like you do with tasks.

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

My guess is that this was for a competition setting, in the competition template, which is why you're using a task autonomous(). If so, that makes it an OK choice, rather than a function.

Regarding the code, try to remember what each part individually does. A while(true) loop will run forever, because the condition "true" is always true. Nothing like an if statement with a touch sensor will make it stop, because the outer while loop just keeps it running.

My advice is to check out some of the free tutorials we have that will build your programming knowledge: http://www.education.rec.ri.cmu.edu/pro ... index.html

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