If you're using Java, anonymous classes can make adding two commands seem much less annoying:
Code:
addSequential(new Command(X/1000.0) {
protected void initialize() {
injector.actuateForward();
}
protected void execute() {}
protected boolean isFinished() {
return isTimedOut();
}
protected void end() {
injector.stopActuating();
}
protected void interrupted() {
end();
}
});
addSequential(new Command() {
protected void initialize() {
injector.actuateBackward();
}
protected void execute() {}
protected boolean isFinished() {
return microswitch.isTriggered();
}
protected void end() {
injector.stopActuating();
}
protected void interrupted() {
end();
}
});
Unfortunately, this will only stop the injector within whatever time increment Scheduler.run() is called, which if it's being run in periodic() is the period between driver station packets are coming, or about 20ms. A thread may be a better choice if you need finer resolution.