7 #include "Commands/Command.h"
8 #include "Commands/CommandGroup.h"
9 #include "Commands/Scheduler.h"
10 #include "DriverStation.h"
12 #include "WPIErrors.h"
14 static const char *kName =
"name";
15 static const char *kRunning =
"running";
16 static const char *kIsParented =
"isParented";
18 int Command::m_commandCounter = 0;
20 void Command::InitCommand(
const char *name,
double timeout)
22 m_commandID = m_commandCounter++;
26 m_initialized =
false;
28 m_interruptible =
true;
30 m_runWhenDisabled =
false;
36 snprintf(buf, 32,
"Command_%p",
this);
52 InitCommand(NULL, -1.0);
62 wpi_setWPIErrorWithContext(NullParameter,
"name");
63 InitCommand(name, -1.0);
74 wpi_setWPIErrorWithContext(ParameterOutOfRange,
"timeout < 0.0");
75 InitCommand(NULL, timeout);
87 wpi_setWPIErrorWithContext(NullParameter,
"name");
89 wpi_setWPIErrorWithContext(ParameterOutOfRange,
"timeout < 0.0");
90 InitCommand(name, timeout);
117 wpi_setWPIErrorWithContext(ParameterOutOfRange,
"timeout < 0.0");
129 if (m_startTime < 0.0)
132 return Timer::GetFPGATimestamp() - m_startTime;
149 if (subsystem != NULL)
150 m_requirements.insert(subsystem);
152 wpi_setWPIErrorWithContext(NullParameter,
"subsystem");
159 void Command::Removed()
174 m_initialized =
false;
189 if (m_parent != NULL)
190 wpi_setWPIErrorWithContext(CommandIllegalUse,
"Can not start a command that is part of a command group");
209 m_initialized =
true;
219 void Command::_Initialize()
223 void Command::_Interrupted()
227 void Command::_Execute()
240 void Command::StartTiming()
242 m_startTime = Timer::GetFPGATimestamp();
262 return m_requirements;
268 void Command::LockChanges()
283 snprintf(buf, 128,
"%s after being started or being added to a command group", message);
284 wpi_setWPIErrorWithContext(CommandIllegalUse, buf);
298 wpi_setWPIErrorWithContext(NullParameter,
"parent");
300 else if (m_parent != NULL)
302 wpi_setWPIErrorWithContext(CommandIllegalUse,
"Can not give command to a command group after already being put in a command group");
326 void Command::StartRunning()
355 if (m_parent != NULL)
356 wpi_setWPIErrorWithContext(CommandIllegalUse,
"Can not cancel a command that is part of a command group");
386 return m_interruptible;
395 m_interruptible = interruptible;
405 return m_requirements.count(system) > 0;
426 m_runWhenDisabled = run;
435 return m_runWhenDisabled;
456 m_table->
PutBoolean(kIsParented, m_parent != NULL);
void SetInterruptible(bool interruptible)
virtual void RemoveTableListener(ITableListener *listener)=0
bool AssertUnlocked(const char *message)
virtual void Interrupted()=0
virtual void AddTableListener(ITableListener *listener)=0
void Requires(Subsystem *s)
double TimeSinceInitialized()
void SetParent(CommandGroup *parent)
void AddCommand(Command *command)
virtual std::string GetName()
virtual void ValueChanged(ITable *source, const std::string &key, EntryValue value, bool isNew)
virtual void PutBoolean(std::string key, bool value)=0
virtual ITable * GetTable()
bool DoesRequire(Subsystem *subsystem)
bool WillRunWhenDisabled()
static DriverStation * GetInstance()
virtual void Initialize()=0
void SetTimeout(double timeout)
void SetRunWhenDisabled(bool run)
virtual void InitTable(ITable *table)
CommandGroup * GetGroup()
static Scheduler * GetInstance()
virtual bool IsFinished()=0
virtual void PutString(std::string key, std::string value)=0
virtual std::string GetSmartDashboardType()
SubsystemSet GetRequirements()