Quote:
|
wait so would this be fine
|
No.
If you're using commands, I would suggest the following implementation. Assuming the code you wrote is inside a command.
- Create and start the timer in the initialize method of a command.
- Inside the execute method run the intake
- inside isFinished() have your check to see if you've waited long enough:
Code:
return timer.get() >= Constants.solenoid_timing.getDouble()
- inside the end method, stop running the intake
Alternatively, you could create the following commands
- RunIntake - a command which just runs the intake then immediately finishes (isFinished returns true) - leaving the intake running
- Delay command. This is an empty command that does nothing and never finishes. See how it is useful below.
- StopIntake - a command that just stops the intake and immediately finishes (isFinished returns true).
You could then make a command group that looked something like this:
Code:
public class RunIntakeThenStop extends CommandGroup {
public RunIntakeThenStop() {
addSequential(new RunIntake());
addSequential(new Delay(), 2.0); //the 2nd parameter is a timeout period in seconds.
addSequential(new StopIntake());
}
}
See the javadoc for help using
command groups and info on
timeout periods for commands.