blob: 24e28981c0fe90bb5922cad6a1c1b90504472a48 [file] [log] [blame]
Parker Schuhd3b7a8872018-02-19 16:42:27 -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
Austin Schuhf6b94632019-02-02 22:11:27 -080014#include "hal/HAL.h"
Parker Schuhd3b7a8872018-02-19 16:42:27 -080015#include "frc971/wpilib/ahal/Base.h"
16
17namespace frc {
18
19class DriverStation;
20
21#ifdef WPILIB2017
22#define START_ROBOT_CLASS(_ClassName_) \
23 int main() { \
24 if (!HAL_Initialize(0)) { \
25 std::cerr << "FATAL ERROR: HAL could not be initialized" << std::endl; \
26 return -1; \
27 } \
28 HAL_Report(HALUsageReporting::kResourceType_Language, \
29 HALUsageReporting::kLanguage_CPlusPlus); \
30 static _ClassName_ robot; \
31 std::printf("\n********** Robot program starting **********\n"); \
32 robot.StartCompetition(); \
33 }
34#else
35#define START_ROBOT_CLASS(_ClassName_) \
James Kuszmaul5d3fe5a2019-12-22 14:55:33 -080036 int main(int argc, char *argv[]) { \
37 ::aos::InitGoogle(&argc, &argv); \
Parker Schuhd3b7a8872018-02-19 16:42:27 -080038 if (!HAL_Initialize(500, 0)) { \
39 std::cerr << "FATAL ERROR: HAL could not be initialized" << std::endl; \
40 return -1; \
41 } \
42 HAL_Report(HALUsageReporting::kResourceType_Language, \
43 HALUsageReporting::kLanguage_CPlusPlus); \
44 static _ClassName_ robot; \
45 std::printf("\n********** Robot program starting **********\n"); \
46 robot.StartCompetition(); \
47 }
48#endif
49
50/**
51 * Implement a Robot Program framework.
52 * The RobotBase class is intended to be subclassed by a user creating a robot
53 * program. Overridden Autonomous() and OperatorControl() methods are called at
54 * the appropriate time as the match proceeds. In the current implementation,
55 * the Autonomous code will run to completion before the OperatorControl code
56 * could start. In the future the Autonomous code might be spawned as a task,
57 * then killed at the end of the Autonomous period.
58 */
59class RobotBase {
60 public:
61 virtual void StartCompetition() = 0;
62
63 protected:
64 RobotBase();
65 virtual ~RobotBase() = default;
66
67 RobotBase(const RobotBase &) = delete;
68 RobotBase &operator=(const RobotBase &) = delete;
69
70 DriverStation &m_ds;
71};
72
73} // namespace frc