Go to Post A world where lawyers and police don't get much work -- there's a goal to work toward. - Richard Wallace [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 19-02-2015, 19:59
shindigo shindigo is offline
Registered User
AKA: Mike Parker
FRC #0102
Team Role: Mentor
 
Join Date: Feb 2012
Rookie Year: 2009
Location: Somerville, NJ
Posts: 33
shindigo is an unknown quantity at this point
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
Reply With Quote
  #2   Spotlight this post!  
Unread 22-02-2015, 03:33
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,564
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Handling Exceptional Cases in a CommandGroup

Quote:
Originally Posted by shindigo View Post
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
I haven't tried to do this, but since it's been a couple of days, I'll throw out some possibly wild pitches:

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:
Any command in the main sequence .. that requires a subsystem in use by a parallel command will cause the parallel command to be canceled.
So, if you start a new command group that requires the same subsystems, it should (as I read the docs) effectively cancel and replace the original command group, which sounds like what you want.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
  #3   Spotlight this post!  
Unread 22-02-2015, 12:59
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is online now
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,713
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
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();
}
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.

Last edited by notmattlythgoe : 22-02-2015 at 13:10.
Reply With Quote
  #4   Spotlight this post!  
Unread 22-02-2015, 18:58
Fauge7 Fauge7 is offline
Head programmer
FRC #3019 (firebird robotics)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Scottsdale
Posts: 195
Fauge7 is a name known to allFauge7 is a name known to allFauge7 is a name known to allFauge7 is a name known to allFauge7 is a name known to allFauge7 is a name known to all
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;
}
its also fairly common to have a state based robot or state based anything really. Lots of video games and Robots are state based.

ps. If you need more help on setting this up just Pm me, Ill be glad to help!
Reply With Quote
  #5   Spotlight this post!  
Unread 24-02-2015, 08:40
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is online now
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,713
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: Handling Exceptional Cases in a CommandGroup

Quote:
Originally Posted by notmattlythgoe View Post
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();
}
Reply With Quote
  #6   Spotlight this post!  
Unread 26-02-2015, 15:53
shindigo shindigo is offline
Registered User
AKA: Mike Parker
FRC #0102
Team Role: Mentor
 
Join Date: Feb 2012
Rookie Year: 2009
Location: Somerville, NJ
Posts: 33
shindigo is an unknown quantity at this point
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
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 08:36.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi