blob: 5b4ce5bf0c07708f2ffc0b8dd2c322db0cb5487f [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
Parker Schuhd3b7a8872018-02-19 16:42:27 -080022#define START_ROBOT_CLASS(_ClassName_) \
James Kuszmaul5d3fe5a2019-12-22 14:55:33 -080023 int main(int argc, char *argv[]) { \
James Kuszmaul57c2baa2020-01-19 14:52:52 -080024 aos::InitGoogle(&argc, &argv); \
25 /* HAL_Initialize spawns several threads, including the CAN drivers. */ \
26 /* Go to realtime so that the child threads are RT. */ \
27 aos::SetCurrentThreadRealtimePriority(10); \
Parker Schuhd3b7a8872018-02-19 16:42:27 -080028 if (!HAL_Initialize(500, 0)) { \
29 std::cerr << "FATAL ERROR: HAL could not be initialized" << std::endl; \
30 return -1; \
31 } \
James Kuszmaul57c2baa2020-01-19 14:52:52 -080032 aos::UnsetCurrentThreadRealtimePriority(); \
Parker Schuhd3b7a8872018-02-19 16:42:27 -080033 HAL_Report(HALUsageReporting::kResourceType_Language, \
34 HALUsageReporting::kLanguage_CPlusPlus); \
35 static _ClassName_ robot; \
36 std::printf("\n********** Robot program starting **********\n"); \
37 robot.StartCompetition(); \
38 }
Parker Schuhd3b7a8872018-02-19 16:42:27 -080039
40/**
41 * Implement a Robot Program framework.
42 * The RobotBase class is intended to be subclassed by a user creating a robot
43 * program. Overridden Autonomous() and OperatorControl() methods are called at
44 * the appropriate time as the match proceeds. In the current implementation,
45 * the Autonomous code will run to completion before the OperatorControl code
46 * could start. In the future the Autonomous code might be spawned as a task,
47 * then killed at the end of the Autonomous period.
48 */
49class RobotBase {
50 public:
51 virtual void StartCompetition() = 0;
52
53 protected:
54 RobotBase();
55 virtual ~RobotBase() = default;
56
57 RobotBase(const RobotBase &) = delete;
58 RobotBase &operator=(const RobotBase &) = delete;
59
60 DriverStation &m_ds;
61};
62
63} // namespace frc