|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Handling Exceptional Cases in a CommandGroup
Hi all -
I'm looking for some advice on handling exceptional cases in a CommandGroup. The most common situation we are considering is if one of the commands times out, we want to cancel the whole group, and/or maybe schedule a different group. Is there any way to do this directly within a CommandGroup or do I have to have the subsystem(s) keep track of what timed out and feed that information on to subsequent commands? tia - mp |
|
#2
|
|||||
|
|||||
|
Re: Handling Exceptional Cases in a CommandGroup
Quote:
Perhaps if you throw an exception that CommandGroup is not ready for, it will stop execution of the group. Another possibility (sounds a bit more likely) I found in the documentation was: Quote:
|
|
#3
|
|||||
|
|||||
|
Re: Handling Exceptional Cases in a CommandGroup
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();
}
I am unsure if the timed out command will need reinitialized or not. My gut says no. Last edited by notmattlythgoe : 22-02-2015 at 13:10. |
|
#4
|
|||
|
|||
|
Re: Handling Exceptional Cases in a CommandGroup
Or in your Robot you can have an enum that is kind of like a Robot State, then in your commands in the isFinished method you can say
Code:
@Override
protected boolean isFinished() {
// TODO Auto-generated method stub
return (Normal End Condition) || Robot.RobotState != RunningCommandGroupX;
}
ps. If you need more help on setting this up just Pm me, Ill be glad to help! |
|
#5
|
|||||
|
|||||
|
Re: Handling Exceptional Cases in a CommandGroup
Quote:
Code:
public boolean isTimedOut() {
return super.isTimedOut();
}
public void setTImeout(double timeout) {
super.setTimeout(timeout);
}
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();
}
|
|
#6
|
|||
|
|||
|
Re: Handling Exceptional Cases in a CommandGroup
Hi all -
We tested out a successful solution last night: as GeeTwo suggested, a command that requires the same subsystem(s) as a scheduled command will interrupt the scheduled commands. So in the original Command (within the CommandGroup) when we get a timeout, we schedule a new Command with (something like) Scheduler.Instance.Add(New StopAllMotors()); This StopAllMotors command requires all subsystems that we want to stop, thus interrupting any running commands. This works in practice for us - we can see running commands getting interrupted and canceled. I suppose if we wanted to extend this to do something other than stop all motors, we could try something like: Scheduler.Instance.Add(New InterruptAllCommands()); Scheduler.Instance.Add(New ExecutePlanB()); Where InterruptAllCommands is a command that just requires all the subsystems we want to reset and ExecutePlanB is our CommandGroup to execute an alternative autonomous plan. Thanks again for all your great suggestions. Hope someone else profits from this... mp |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|