We want to use a timer for executing commands. (if x button is pushed than p happens and after a certain amount of time q happens) This would most likely be for controlling the solenoids on our robot so that with one button push a piston would extend before the other. We would also use it for driving functions.
you need to add a global variable at the top and if you put a counter in the while loop for autonomous you can count the iterations. this is the only way you can do it. if you put a delay in you will get the red light of death.
For MPLAB IFI/Watson based programming…
To use a real timer take a look at the IFI explanation in this white paper: http://www.ifirobotics.com/docs/timers_white_paper_2004-jan-14.pdf
Kevin Watson has some examples here: http://www.kevin.org/frc/2005/
use a “wait” function in the code
if(button){
do thing one;
Wait(3000);
do thing two;
}
The value inside the “wait” function is in milliseconds, so the above code would pause for 3 seconds between thing one and thing two.
For Easy C or WPILIB based programming …
If you’re using my 2008 robot controller code, I’ve created drop-in replacement code for timer.c and timer.h that implements a millisecond system clock using timer 2. The code is available here: http://kevin.org/frc/ifi_clock.zip.
-Kevin
the program loops at 36 times a second. With this knowledge, you could create something that would measure this. I wouldn’t advise letting a counter variable get into the thousands, because then the program starts running slower. something like this worked nicely for me:
//global variables
int count = 0;
int second = 0;
//somewhere in code
if (count >= 37)
{
count = 0;
}
count++;
//you could compare things like this
switch second
{
case 0: //what happens right off the back
break;
case 1: //what happens in the first second
break;
case 2: //what happens in second second (ha!)
break;
default: //what should happen when out of time
}
The code says we are missing IFI_FRC.h