WPILib 2012
WPILibRoboticsLibraryforFRC
|
00001 /*----------------------------------------------------------------------------*/ 00002 /* Copyright (c) FIRST 2008. 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 ROBOT_H_ 00008 #define ROBOT_H_ 00009 00010 #include "Base.h" 00011 #include "Task.h" 00012 #include "Watchdog.h" 00013 00014 class DriverStation; 00015 00016 #define START_ROBOT_CLASS(_ClassName_) \ 00017 RobotBase *FRC_userClassFactory() \ 00018 { \ 00019 return new _ClassName_(); \ 00020 } \ 00021 extern "C" { \ 00022 INT32 FRC_UserProgram_StartupLibraryInit() \ 00023 { \ 00024 RobotBase::startRobotTask((FUNCPTR)FRC_userClassFactory); \ 00025 return 0; \ 00026 } \ 00027 } 00028 00037 class RobotBase { 00038 friend class RobotDeleter; 00039 public: 00040 static RobotBase &getInstance(); 00041 static void setInstance(RobotBase* robot); 00042 00043 bool IsEnabled(); 00044 bool IsDisabled(); 00045 bool IsAutonomous(); 00046 bool IsOperatorControl(); 00047 bool IsSystemActive(); 00048 bool IsNewDataAvailable(); 00049 Watchdog &GetWatchdog(); 00050 static void startRobotTask(FUNCPTR factory); 00051 static void robotTask(FUNCPTR factory, Task *task); 00052 00053 protected: 00054 virtual ~RobotBase(); 00055 virtual void StartCompetition() = 0; 00056 RobotBase(); 00057 00058 Task *m_task; 00059 Watchdog m_watchdog; 00060 DriverStation *m_ds; 00061 00062 private: 00063 static RobotBase *m_instance; 00064 DISALLOW_COPY_AND_ASSIGN(RobotBase); 00065 }; 00066 00067 #endif 00068