WPILib 2012
WPILibRoboticsLibraryforFRC
|
00001 /*----------------------------------------------------------------------------*/ 00002 /* Copyright (c) FIRST 2011. All Rights Reserved. */ 00003 /* Open Source Software - may be modified and shared by FRC teams. The code */ 00004 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ 00005 /*----------------------------------------------------------------------------*/ 00006 00007 #ifndef __COMMAND_H__ 00008 #define __COMMAND_H__ 00009 00010 #include "ErrorBase.h" 00011 #include "NetworkTables/NetworkTableChangeListener.h" 00012 #include "SmartDashboard/SmartDashboardNamedData.h" 00013 #include <set> 00014 #include <string> 00015 00016 class CommandGroup; 00017 class NetworkTable; 00018 class Subsystem; 00019 00045 class Command : public SmartDashboardNamedData, public NetworkTableChangeListener, public ErrorBase 00046 { 00047 friend class CommandGroup; 00048 friend class Scheduler; 00049 public: 00050 Command(); 00051 Command(const char *name); 00052 Command(double timeout); 00053 Command(const char *name, double timeout); 00054 virtual ~Command(); 00055 double TimeSinceInitialized(); 00056 void Requires(Subsystem *s); 00057 bool IsCanceled(); 00058 void Start(); 00059 bool Run(); 00060 void Cancel(); 00061 bool IsRunning(); 00062 bool IsInterruptible(); 00063 void SetInterruptible(bool interruptible); 00064 bool DoesRequire(Subsystem *subsystem); 00065 typedef std::set<Subsystem *> SubsystemSet; 00066 SubsystemSet GetRequirements(); 00067 CommandGroup *GetGroup(); 00068 void SetRunWhenDisabled(bool run); 00069 bool WillRunWhenDisabled(); 00070 00071 virtual std::string GetName(); 00072 virtual std::string GetType(); 00073 virtual NetworkTable *GetTable(); 00074 00075 virtual void ValueChanged(NetworkTable *table, const char *name, NetworkTables_Types type); 00076 virtual void ValueConfirmed(NetworkTable *table, const char *name, NetworkTables_Types type) {} 00077 00078 protected: 00079 void SetTimeout(double timeout); 00080 bool IsTimedOut(); 00081 bool AssertUnlocked(const char *message); 00082 void SetParent(CommandGroup *parent); 00087 virtual void Initialize() = 0; 00092 virtual void Execute() = 0; 00103 virtual bool IsFinished() = 0; 00109 virtual void End() = 0; 00122 virtual void Interrupted() = 0; 00123 virtual void _Initialize(); 00124 virtual void _Interrupted(); 00125 virtual void _Execute(); 00126 virtual void _End(); 00127 virtual void _Cancel(); 00128 00129 private: 00130 void InitCommand(const char *name, double timeout); 00131 void LockChanges(); 00132 /*synchronized*/ void Removed(); 00133 void StartRunning(); 00134 void StartTiming(); 00135 00137 std::string m_name; 00139 double m_startTime; 00141 double m_timeout; 00143 bool m_initialized; 00145 SubsystemSet m_requirements; 00147 bool m_running; 00149 bool m_interruptible; 00151 bool m_canceled; 00153 bool m_locked; 00155 bool m_runWhenDisabled; 00157 CommandGroup *m_parent; 00158 00159 NetworkTable *m_table; 00160 }; 00161 00162 #endif