View Single Post
  #4   Spotlight this post!  
Unread 09-02-2015, 21:52
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?

Assuming you are following the CommandBased template and defining your buttons in OI you can't conditionally run commands in a command group. Why? The command group is only ever constructed once and reused when ever the button is pressed.

If you are needing to do this you might need to rethink the design and structure of you code. We typically do the core of our control logic in state machines in the Subsystems and then uses commands to change the state.

A less elegant way is to code your commands with a short circuit path. See the example below. We used this on our 30 pt climber in 2013. If the shooter was up we couldn't raise the arm as it would run into the shooter and cause damage. To prevent this if the RaiseArm command was called with the shooter up we finished the command instantly. It is important not to set a mechanism in motion in the initialize method or it will run regardless of the additional condition.
Code:
class RaiseArm : public CommandBase {
public:
	RaiseArm() {}
	void Initialize() {}
	void Execute() {
		arm->Raise();
	}
	bool IsFinished() {
		//Finish instantly if the shooter is up so the arm 
		//won't hit it.
		return arm->isUp() || shooter->isUp();
	}
	void End(){}
	void Interrupted() {}
};
If this solution is not adequate or too messy then perhaps you could post a specific example of what you are hoping to do in the command group.
__________________
"May the coms be with you"

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

Reply With Quote