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