WPILibC++  2019.1.1-beta-4-1-g6e8f8be
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
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 <wpi/raw_ostream.h>
13 
14 #include "frc/Base.h"
15 
16 namespace frc {
17 
18 class DriverStation;
19 
20 int RunHALInitialization();
21 
22 template <class Robot>
23 int StartRobot() {
24  int halInit = RunHALInitialization();
25  if (halInit != 0) {
26  return halInit;
27  }
28  static Robot robot;
29  robot.StartCompetition();
30 
31  return 0;
32 }
33 
34 #define START_ROBOT_CLASS(_ClassName_) \
35  WPI_DEPRECATED("Call frc::StartRobot<" #_ClassName_ \
36  ">() in your own main() instead of using the " \
37  "START_ROBOT_CLASS(" #_ClassName_ ") macro.") \
38  int StartRobotClassImpl() { return frc::StartRobot<_ClassName_>(); } \
39  int main() { return StartRobotClassImpl(); }
40 
51 class RobotBase {
52  public:
58  bool IsEnabled() const;
59 
65  bool IsDisabled() const;
66 
73  bool IsAutonomous() const;
74 
81  bool IsOperatorControl() const;
82 
89  bool IsTest() const;
90 
97  bool IsNewDataAvailable() const;
98 
102  static std::thread::id GetThreadId();
103 
104  virtual void StartCompetition() = 0;
105 
106  static constexpr bool IsReal() {
107 #ifdef __FRC_ROBORIO__
108  return true;
109 #else
110  return false;
111 #endif
112  }
113 
114  static constexpr bool IsSimulation() { return !IsReal(); }
115 
116  protected:
128  RobotBase();
129 
130  virtual ~RobotBase();
131 
132  // m_ds isn't moved in these because DriverStation is a singleton; every
133  // instance of RobotBase has a reference to the same object.
134  RobotBase(RobotBase&&);
135  RobotBase& operator=(RobotBase&&);
136 
137  DriverStation& m_ds;
138 
139  static std::thread::id m_threadId;
140 };
141 
142 } // namespace frc
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
bool IsTest() const
Determine if the robot is currently in Test mode.
bool IsAutonomous() const
Determine if the robot is currently in Autonomous mode.
bool IsOperatorControl() const
Determine if the robot is currently in Operator Control mode.
bool IsEnabled() const
Determine if the Robot is currently enabled.
bool IsDisabled() const
Determine if the Robot is currently disabled.
Provide access to the network communication data to / from the Driver Station.
Definition: DriverStation.h:33
bool IsNewDataAvailable() const
Indicates if new data is available from the driver station.
RobotBase()
Constructor for a generic robot program.
Implement a Robot Program framework.
Definition: RobotBase.h:51
static std::thread::id GetThreadId()
Gets the ID of the main robot thread.