blob: 26a0c9198326bc905df506d5cb30f3745dd41a47 [file] [log] [blame]
Brian Silvermanf7f267a2017-02-04 16:16:08 -08001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2008-2017. 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 the root directory of */
5/* the project. */
6/*----------------------------------------------------------------------------*/
7
8#pragma once
9
10#include <cstdio>
11#include <iostream>
12#include <thread>
13
14#include "Base.h"
15#include "HAL/HAL.h"
16
17namespace frc {
18
19class DriverStation;
20
21#define START_ROBOT_CLASS(_ClassName_) \
22 int main() { \
23 if (!HAL_Initialize(0)) { \
24 std::cerr << "FATAL ERROR: HAL could not be initialized" << std::endl; \
25 return -1; \
26 } \
27 HAL_Report(HALUsageReporting::kResourceType_Language, \
28 HALUsageReporting::kLanguage_CPlusPlus); \
29 static _ClassName_ robot; \
30 std::printf("\n********** Robot program starting **********\n"); \
31 robot.StartCompetition(); \
32 }
33
34/**
35 * Implement a Robot Program framework.
36 * The RobotBase class is intended to be subclassed by a user creating a robot
37 * program. Overridden Autonomous() and OperatorControl() methods are called at
38 * the appropriate time as the match proceeds. In the current implementation,
39 * the Autonomous code will run to completion before the OperatorControl code
40 * could start. In the future the Autonomous code might be spawned as a task,
41 * then killed at the end of the Autonomous period.
42 */
43class RobotBase {
44 public:
45 bool IsEnabled() const;
46 bool IsDisabled() const;
47 bool IsAutonomous() const;
48 bool IsOperatorControl() const;
49 bool IsTest() const;
50 bool IsNewDataAvailable() const;
51 static std::thread::id GetThreadId();
52 virtual void StartCompetition() = 0;
53
54 protected:
55 RobotBase();
56 virtual ~RobotBase() = default;
57
58 RobotBase(const RobotBase&) = delete;
59 RobotBase& operator=(const RobotBase&) = delete;
60
61 DriverStation& m_ds;
62
63 static std::thread::id m_threadId;
64};
65
66} // namespace frc