View Single Post
  #4   Spotlight this post!  
Unread 28-04-2016, 22:56
euhlmann's Avatar
euhlmann euhlmann is offline
CTO, Programmer
AKA: Erik Uhlmann
FRC #2877 (LigerBots)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2015
Location: United States
Posts: 312
euhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud of
Re: How simple should commands be? And how should they be structured?

Quote:
Originally Posted by jreneew2 View Post
For example, lets say I want to open and close a solenoid. Should I make a command that opens it, and a command that closes it, or just have a single command that gets passed a value to tell which valve I want to open?
I think it makes more sense to have a single command. The way we threw together commands like this was something like
Code:
class SomethingToggleCommand: CommandBase {
int m_mode;
public:
SomethingToggleCommand(){ // default action: toggle
  m_mode = 2;
}
SomethingToggleCommand(bool isOpen){ // explicitly set open or closed
  m_mode = isOpen;
}
void Execute(){
  if(m_mode == 2) { 
    somethingSubsystem->setSomething(!somethingSubsystem->isSomethingOpen());
  } else {
    somethingSubsystem->setSomething(m_mode);
  }
}
bool IsFinished(){
  return true;
}
// etc
}
I don't think it's the best way in terms of design, but it works ¯\_(ツ)_/¯
Reply With Quote