WPILibC++  unspecified
RobotBase.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2018 FIRST. 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 <thread>
11 
12 #include <HAL/HAL.h>
13 #include <llvm/raw_ostream.h>
14 
15 #include "Base.h"
16 
17 namespace frc {
18 
19 class DriverStation;
20 
21 #define START_ROBOT_CLASS(_ClassName_) \
22  int main() { \
23  if (!HAL_Initialize(500, 0)) { \
24  llvm::errs() << "FATAL ERROR: HAL could not be initialized\n"; \
25  return -1; \
26  } \
27  HAL_Report(HALUsageReporting::kResourceType_Language, \
28  HALUsageReporting::kLanguage_CPlusPlus); \
29  llvm::outs() << "\n********** Robot program starting **********\n"; \
30  static _ClassName_ robot; \
31  robot.StartCompetition(); \
32  }
33 
44 class RobotBase {
45  public:
46  bool IsEnabled() const;
47  bool IsDisabled() const;
48  bool IsAutonomous() const;
49  bool IsOperatorControl() const;
50  bool IsTest() const;
51  bool IsNewDataAvailable() const;
52  static std::thread::id GetThreadId();
53  virtual void StartCompetition() = 0;
54 
55  static constexpr bool IsReal() {
56 #ifdef __FRC_ROBORIO__
57  return true;
58 #else
59  return false;
60 #endif
61  }
62 
63  static constexpr bool IsSimulation() { return !IsReal(); }
64 
65  protected:
66  RobotBase();
67  virtual ~RobotBase() = default;
68 
69  RobotBase(const RobotBase&) = delete;
70  RobotBase& operator=(const RobotBase&) = delete;
71 
72  DriverStation& m_ds;
73 
74  static std::thread::id m_threadId;
75 };
76 
77 } // namespace frc
bool IsEnabled() const
Determine if the Robot is currently enabled.
Definition: RobotBase.cpp:74
Definition: RobotController.cpp:14
bool IsAutonomous() const
Determine if the robot is currently in Autonomous mode.
Definition: RobotBase.cpp:89
bool IsDisabled() const
Determine if the Robot is currently disabled.
Definition: RobotBase.cpp:81
static std::thread::id GetThreadId()
Gets the ID of the main robot thread.
Definition: RobotBase.cpp:118
Provide access to the network communication data to / from the Driver Station.
Definition: DriverStation.h:34
bool IsNewDataAvailable() const
Indicates if new data is available from the driver station.
Definition: RobotBase.cpp:113
bool IsOperatorControl() const
Determine if the robot is currently in Operator Control mode.
Definition: RobotBase.cpp:97
Implement a Robot Program framework.
Definition: RobotBase.h:44
bool IsTest() const
Determine if the robot is currently in Test mode.
Definition: RobotBase.cpp:105
RobotBase()
Constructor for a generic robot program.
Definition: RobotBase.cpp:39