Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 1 | /*----------------------------------------------------------------------------*/ |
| 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 Kuszmaul | 57c2baa | 2020-01-19 14:52:52 -0800 | [diff] [blame^] | 14 | #include "aos/realtime.h" |
Austin Schuh | f6b9463 | 2019-02-02 22:11:27 -0800 | [diff] [blame] | 15 | #include "hal/HAL.h" |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 16 | #include "frc971/wpilib/ahal/Base.h" |
| 17 | |
| 18 | namespace frc { |
| 19 | |
| 20 | class 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 Kuszmaul | 5d3fe5a | 2019-12-22 14:55:33 -0800 | [diff] [blame] | 37 | int main(int argc, char *argv[]) { \ |
James Kuszmaul | 57c2baa | 2020-01-19 14:52:52 -0800 | [diff] [blame^] | 38 | 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 Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 42 | if (!HAL_Initialize(500, 0)) { \ |
| 43 | std::cerr << "FATAL ERROR: HAL could not be initialized" << std::endl; \ |
| 44 | return -1; \ |
| 45 | } \ |
James Kuszmaul | 57c2baa | 2020-01-19 14:52:52 -0800 | [diff] [blame^] | 46 | aos::UnsetCurrentThreadRealtimePriority(); \ |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 47 | 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 | */ |
| 64 | class 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 |