Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2008. All Rights Reserved. |
| 3 | */ |
| 4 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
| 5 | /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ |
| 6 | /*----------------------------------------------------------------------------*/ |
| 7 | #pragma once |
| 8 | |
| 9 | #include "Base.h" |
| 10 | #include "Task.h" |
| 11 | |
| 12 | class DriverStation; |
| 13 | |
| 14 | #define START_ROBOT_CLASS(_ClassName_) \ |
| 15 | int main() { \ |
| 16 | if (!HALInitialize()) { \ |
| 17 | std::cerr << "FATAL ERROR: HAL could not be initialized" << std::endl; \ |
| 18 | return -1; \ |
| 19 | } \ |
| 20 | HALReport(HALUsageReporting::kResourceType_Language, \ |
| 21 | HALUsageReporting::kLanguage_CPlusPlus); \ |
| 22 | _ClassName_ *robot = new _ClassName_(); \ |
| 23 | RobotBase::robotSetup(robot); \ |
| 24 | return 0; \ |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Implement a Robot Program framework. |
| 29 | * The RobotBase class is intended to be subclassed by a user creating a robot |
| 30 | * program. |
| 31 | * Overridden Autonomous() and OperatorControl() methods are called at the |
| 32 | * appropriate time |
| 33 | * as the match proceeds. In the current implementation, the Autonomous code |
| 34 | * will run to |
| 35 | * completion before the OperatorControl code could start. In the future the |
| 36 | * Autonomous code |
| 37 | * might be spawned as a task, then killed at the end of the Autonomous period. |
| 38 | */ |
| 39 | class RobotBase { |
| 40 | friend class RobotDeleter; |
| 41 | |
| 42 | public: |
| 43 | static RobotBase &getInstance(); |
| 44 | static void setInstance(RobotBase *robot); |
| 45 | |
| 46 | bool IsEnabled() const; |
| 47 | bool IsDisabled() const; |
| 48 | bool IsAutonomous() const; |
| 49 | bool IsOperatorControl() const; |
| 50 | bool IsTest() const; |
| 51 | bool IsNewDataAvailable() const; |
| 52 | static void startRobotTask(FUNCPTR factory); |
| 53 | static void robotTask(FUNCPTR factory, Task *task); |
| 54 | virtual void StartCompetition() = 0; |
| 55 | |
| 56 | static void robotSetup(RobotBase *robot); |
| 57 | |
| 58 | protected: |
| 59 | RobotBase(); |
| 60 | virtual ~RobotBase(); |
| 61 | |
| 62 | RobotBase(const RobotBase&) = delete; |
| 63 | RobotBase& operator=(const RobotBase&) = delete; |
| 64 | |
| 65 | Task *m_task = nullptr; |
| 66 | DriverStation &m_ds; |
| 67 | |
| 68 | private: |
| 69 | static RobotBase *m_instance; |
| 70 | }; |