View Single Post
  #6   Spotlight this post!  
Unread 10-02-2015, 11:36
kylelanman's Avatar
kylelanman kylelanman is offline
Programming Mentor
AKA: Kyle
FRC #2481 (Roboteers)
Team Role: Mentor
 
Join Date: Feb 2008
Rookie Year: 2007
Location: Tremont Il
Posts: 186
kylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to all
Re: Conditional Command Group?

I didn't even pay attention to the team number of the OP. But yes I do believe I know one of your mentors.

If I'm understanding why you want to skip a command correctly then personally I would code the command to finish instantly if it didn't need to run. This is easier if you have sensors/feedback on all your mechanisms.

Ex.

Code:
class IntakeToteCommand: public CommandGroup
{
public:
	IntakeToteCommand(){
		AddSequential(new StackerGoToTopCommand());
		AddSequential(new IntakeTurnOn());

	}
};
Code:
class StackerGoToTopCommand: public CommandBase
{
public:
	StackerGoToTopCommand() : CommandBase() {
		Requires(stacker);
	}
	void Initialize(){
		if (!IsFinished()){
			CommandBase::stacker->SetPosition(15);			
		}
 	}
	void Execute() {}
	bool IsFinished(){
		return (CommandBase::stacker->GetPosition() > 15);
	}
	void End(){
		CommandBase::stacker->Disable();
	}
	void Interrupted(){
		End();
	}
};
Our stacker has to be at it's top position to intake a tote. 99% of the time the Stacker is already at the top of the robot when we start to intake a tote. However we still fire off the StackerGoToTopCommand() as a safety precaution because if we don't we won't be able to pickup a tote. If it is already at the top then the command finishes instantly.

With this approach you can take everything into account that would ever need to occur for the given action to run without error. In doing so you can call the command group at anytime by itself and not have to think about wrapping the call of the command in additional logic.
__________________
"May the coms be with you"

Is this a "programming error" or a "programmer error"?

Reply With Quote