Hi there, I am a relatively new FTC-er and I had a question about the autonomous coding in ROBOTC. Is there a way to make a while loop abort after a set amount of time, say 20 seconds, even if it has not completed its usual task? Because we are having our robot find the center goal during autonomous and fire balls into it, but if the sensors do not find the beacon or the robot cannot center on it we need our robot to automatically abort the while loop and start other tasks.
Any help would be greatly appreciated.
You can set a while loop as less than one of the timer’s in robotc. You’ll have to check the help files for the exact syntax as I don’t remember it offhand, but if I remember correctly, I think it looks something like…
while(T1<20000)
{
//put code here
}
I think that T1 is a millisecond timer, but just search the help files in RobotC for timer and you should be good to go.
Oh and you probably want to set T1 equal to 0 at the beginning of autonomous, but I’m not 100% sure (again, the help file should tell you everything you need to know).
you can do that if you make sure you clear the timer first, or if you want to have it go through a loop a specific number of times you can use a for loop
for(int i=0; i < 10; i++)
{
//code here
}
if you want to use timers, i’m pretty sure the syntax is timer[T1] to read or write the timer.
to reset a timer you would just to timer[T1] = 0;
Thank you both for the help