View Single Post
  #4   Spotlight this post!  
Unread 07-01-2014, 16:50
brennonbrimhall brennonbrimhall is offline
Free Agent
AKA: Brennon Brimhall
no team
Team Role: Alumni
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Clifton Park, NY
Posts: 222
brennonbrimhall is a name known to allbrennonbrimhall is a name known to allbrennonbrimhall is a name known to allbrennonbrimhall is a name known to allbrennonbrimhall is a name known to allbrennonbrimhall is a name known to all
Re: How to make timed sequences in java?

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.
__________________
Team 20, 2012-2014: 4 blue banners, 5 medals, and 9 team awards.
Church of Jesus Christ of Latter-day Saints, 2014-2016: Missionary, Colorado Denver South Mission.