Disclaimer: We use Java, and this might change depending the language you use.
It's not the best method when considered computationally, but we just increment an integer variable, and use a typical if statement when using the IterativeRobot template.
Here's an example:
Code:
DoubleSolenoid solenoid = ... ;
int cycles = 0;
public void teleopPeriodic(){
cycles++;
if(cycles<40){
solenoid.set(DoubleSolenoid.Value.kForward);
}else if(cycles<60){
//Do nothing
}else if (cycles<80){
solenoid.set(DoubleSolenoid.Value.kReverse);
}
}
public void disabledInit(){
//Resetting to zero on disable.
cycles = 0;
}
Of course, you'd need to figure out how many times the cRIO enters teleopPeriodic per second to figure out the correct numbers to compare to above.
Don't worry about running out of int space in Java. An int's maximum value is 2^32-1, and at 50Hz (around what we observed), the cRIO's JVM won't run into errors for just over 994 days, assuming it's still running by then.
