blob: ff9c0159420ee2959c6d2eee19946d59f8ec6436 [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001/*----------------------------------------------------------------------------*/
Brian Silverman1a675112016-02-20 20:42:49 -05002/* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
Brian Silverman26e4e522015-12-17 01:56:40 -05003/* Open Source Software - may be modified and shared by FRC teams. The code */
Brian Silverman1a675112016-02-20 20:42:49 -05004/* must be accompanied by the FIRST BSD license file in the root directory of */
5/* the project. */
Brian Silverman26e4e522015-12-17 01:56:40 -05006/*----------------------------------------------------------------------------*/
Brian Silverman1a675112016-02-20 20:42:49 -05007
Brian Silverman26e4e522015-12-17 01:56:40 -05008#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 */
30class RobotBase
31{
32 friend class RobotDeleter;
33public:
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
44protected:
45 RobotBase();
46 virtual ~RobotBase() = default;
47
48 RobotBase(const RobotBase&) = delete;
49 RobotBase& operator=(const RobotBase&) = delete;
50
51 DriverStation &m_ds;
Brian Silverman1a675112016-02-20 20:42:49 -050052 transport::SubscriberPtr time_sub;
Brian Silverman26e4e522015-12-17 01:56:40 -050053
54private:
55 static RobotBase *m_instance;
56};