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