View Single Post
  #5   Spotlight this post!  
Unread 23-02-2013, 13:17
Itamar's Avatar
Itamar Itamar is offline
Registered User
FRC #1943 (NeatTeam) & FRC #4590 (GreenBlitz)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2010
Location: Israel
Posts: 83
Itamar is an unknown quantity at this point
Re: Command-Based robot button toggle question

Quote:
Originally Posted by Fifthparallel View Post
Are the two commands related in any way? (i.e., could you use one command for both actions?). If so, you may want to consider refactoring either your subsystem or command code so that you have this functionality.

OR, you could put them all inside a command group with a bool that holds state, and based on that run either of two commands. Just make sure your "state" variable inside of whatever subsystem is actually being toggled back to whatever is needs to be.

Code:
//In the CommandGroup foo, you could either have a state that is toggled from within one of your subsystems,
//ala GetterSetter pattern and use this state to make a decision.

//OI code
JoystickButton *xyz = new JoystickButton(stick1, 11);
xyz->WhenPressed(new foo());

//CommandGroup code

subsystemOne.ChangeStateOfFooBar();
if(subsystemOne.GetStateOfFooBar())
{
     AddSequential(new bar());
}
else
{
     AddSequential(new baz());
}
Don't forget that the calls to "AddSequential" should be in the CommandGroup's constructor, which means they run only when an instance is created (probably when the code first runs). The condition you put there will not have the effect you expect it to have. The created CommandGroup will always run either "bar" or "baz", depending on the value "GetStateOfFooBar" returned when the constructor was called.
Reply With Quote