|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Best Way(s) to Implement a Delay in Command Groups
Today, my former team asked me what the best way to implement a delay in a command group is. They are well aware of the built in delays in the adding of the commands.
Code:
addSequential(new DriveForward(), DELAY_TIME); Code:
Timer.delay(DELAY_TIME); Last edited by xForceDee : 03-28-2014 at 09:40 PM. |
|
#2
|
||||
|
||||
|
Re: Best Way(s) to Implement a Delay in Command Groups
AddSequential(new WaitCommand(1)); //Wait 1 second.
|
|
#3
|
||||
|
||||
|
Re: Best Way(s) to Implement a Delay in Command Groups
I discovered that it is best to not use Timer.delay() because that will pause your entire robot (Every other command and every other subsystem). My solution was to create a Wait command that accepts a timeout as an argument. It then sets its timeout (this.setTimeout(arg)) to the argument. Then isFinished() returns this.isTimedout(). This will effectively put a delay in the command group because they command won't finish until the timeout has elapsed.
|
|
#4
|
||||
|
||||
|
Re: Best Way(s) to Implement a Delay in Command Groups
Our team uses the same approach mentioned by Joey1939. I've attached the .java file for the command we use. (You might want to just copy/paste the important bits - there's a lot of unnecessary RobotBuilder crap in here that we never cleaned out.)
We call it in command groups like so: Code:
addSequential(new Delay(1.25)); |
|
#5
|
||||
|
||||
|
Re: Best Way(s) to Implement a Delay in Command Groups
We use:
Code:
addSequential(new WaitCommand(WAIT_TIME)); Also, it is possible to have a command that does not require a subsystem, as we have done this before, but probably is not recommended. |
|
#6
|
||||
|
||||
|
Re: Best Way(s) to Implement a Delay in Command Groups
Wow, I had no idea that was even there. They really ought to put that in the ScreenSteps documentation somewhere...
|
|
#7
|
||||
|
||||
|
Re: Best Way(s) to Implement a Delay in Command Groups
Why would this be a problem? Understandably, you could have two commands trying to use a subsystem at the same time. But I'm sure the WaitCommand itself doesn't require a subsystem, and neither do a lot of the commands that our team used this year.
|
|
#8
|
|||
|
|||
|
Re: Best Way(s) to Implement a Delay in Command Groups
Our team uses States to determine what to do. Drive has a State Machine that is independent of the Shooter. Delays are implemented using timers. Set a timer, and check the time each loop.
Note: Having everything doing "nothing" requires a little thought. Do you disable the compressor so it does not run too? If you are moving, do you stop moving (and if so, how? Drop power abruptly, or gradually)? etc. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|