WPILibC++  2018.4.1-20180924003241-1198-g0c58a0a
 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 <hal/HAL.h>
13 #include <wpi/raw_ostream.h>
14 
15 #include "frc/Base.h"
16 
17 namespace frc {
18 
19 class DriverStation;
20 
21 template <class Robot>
22 int StartRobot() {
23  if (!HAL_Initialize(500, 0)) {
24  wpi::errs() << "FATAL ERROR: HAL could not be initialized\n";
25  return -1;
26  }
27  HAL_Report(HALUsageReporting::kResourceType_Language,
28  HALUsageReporting::kLanguage_CPlusPlus);
29  wpi::outs() << "\n********** Robot program starting **********\n";
30  static Robot robot;
31  robot.StartCompetition();
32 
33  return 0;
34 }
35 
36 #define START_ROBOT_CLASS(_ClassName_) \
37  WPI_DEPRECATED("Call frc::StartRobot<" #_ClassName_ \
38  ">() in your own main() instead of using the " \
39  "START_ROBOT_CLASS(" #_ClassName_ ") macro.") \
40  int StartRobotClassImpl() { return frc::StartRobot<_ClassName_>(); } \
41  int main() { return StartRobotClassImpl(); }
42 
53 class RobotBase {
54  public:
60  bool IsEnabled() const;
61 
67  bool IsDisabled() const;
68 
75  bool IsAutonomous() const;
76 
83  bool IsOperatorControl() const;
84 
91  bool IsTest() const;
92 
99  bool IsNewDataAvailable() const;
100 
104  static std::thread::id GetThreadId();
105 
106  virtual void StartCompetition() = 0;
107 
108  static constexpr bool IsReal() {
109 #ifdef __FRC_ROBORIO__
110  return true;
111 #else
112  return false;
113 #endif
114  }
115 
116  static constexpr bool IsSimulation() { return !IsReal(); }
117 
118  protected:
130  RobotBase();
131 
132  virtual ~RobotBase() = default;
133 
134  RobotBase(const RobotBase&) = delete;
135  RobotBase& operator=(const RobotBase&) = delete;
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.
int64_t HAL_Report(int32_t resource, int32_t instanceNumber, int32_t context, const char *feature)
Reports a hardware usage to the HAL.
bool IsEnabled() const
Determine if the Robot is currently enabled.
bool IsDisabled() const
Determine if the Robot is currently disabled.
raw_ostream & outs()
This returns a reference to a raw_ostream for standard output.
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:53
static std::thread::id GetThreadId()
Gets the ID of the main robot thread.
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
HAL_Bool HAL_Initialize(int32_t timeout, int32_t mode)
Call this to start up HAL.