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 "DriverStation.h" |
| 12 | #include "simulation/simTime.h" |
| 13 | #include "simulation/MainNode.h" |
| 14 | |
| 15 | #define START_ROBOT_CLASS(_ClassName_) \ |
| 16 | int main() \ |
| 17 | { \ |
| 18 | (new _ClassName_())->StartCompetition(); \ |
| 19 | return 0; \ |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Implement a Robot Program framework. |
| 24 | * The RobotBase class is intended to be subclassed by a user creating a robot program. |
| 25 | * Overridden Autonomous() and OperatorControl() methods are called at the appropriate time |
| 26 | * as the match proceeds. In the current implementation, the Autonomous code will run to |
| 27 | * completion before the OperatorControl code could start. In the future the Autonomous code |
| 28 | * might be spawned as a task, then killed at the end of the Autonomous period. |
| 29 | */ |
| 30 | class RobotBase |
| 31 | { |
| 32 | friend class RobotDeleter; |
| 33 | public: |
| 34 | static RobotBase &getInstance(); |
| 35 | static void setInstance(RobotBase* robot); |
| 36 | |
| 37 | bool IsEnabled() const; |
| 38 | bool IsDisabled() const; |
| 39 | bool IsAutonomous() const; |
| 40 | bool IsOperatorControl() const; |
| 41 | bool IsTest() const; |
| 42 | virtual void StartCompetition() = 0; |
| 43 | |
| 44 | protected: |
| 45 | RobotBase(); |
| 46 | virtual ~RobotBase() = default; |
| 47 | |
| 48 | RobotBase(const RobotBase&) = delete; |
| 49 | RobotBase& operator=(const RobotBase&) = delete; |
| 50 | |
| 51 | DriverStation &m_ds; |
Brian Silverman | 1a67511 | 2016-02-20 20:42:49 -0500 | [diff] [blame^] | 52 | transport::SubscriberPtr time_sub; |
Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame] | 53 | |
| 54 | private: |
| 55 | static RobotBase *m_instance; |
| 56 | }; |