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