Quote:
Originally Posted by notmattlythgoe
What about something like this?
Code:
private Command2 timeoutCommand = new Command2();
public SomethingCommandGroup() {
addSequential(new Command1());
addSequential(timeoutCommand, 5);
addSequential(new Command3());
}
protected boolean isFinished() {
return super.isFinished()
|| timeoutCommand.isTimedOut();
}
Since a CommandGroup is still a Command you can override isFinished() to finish if a certain command or several have timed out.
I am unsure if the timed out command will need reinitialized or not. My gut says no.
|
Unfortunately, after looking into this a bit further, the commands don't know they've timed out when they are added with a timeout to the CommandGroup. However, you could set a timeout value of the command itself and let it take car of the timeout. To do this you are going to need to increase the visibility of isTimedOut() and setTimeout() to public. Tod o this just add both of these methods to your command like this:
Code:
public boolean isTimedOut() {
return super.isTimedOut();
}
public void setTImeout(double timeout) {
super.setTimeout(timeout);
}
Then use it like this:
Code:
private Command2 timeoutCommand = new Command2();
public SomethingCommandGroup() {
addSequential(new Command1());
timeoutCommand.setTimeout(5);
addSequential(timeoutCommand);
addSequential(new Command3());
}
protected boolean isFinished() {
return super.isFinished()
|| timeoutCommand.isTimedOut();
}