WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
RobotBase.h
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 <thread>
11 
12 #include "Base.h"
13 #include "HAL/HAL.h"
14 #include "llvm/raw_ostream.h"
15 
16 namespace frc {
17 
18 class DriverStation;
19 
20 #define START_ROBOT_CLASS(_ClassName_) \
21  int main() { \
22  if (!HAL_Initialize(500, 0)) { \
23  llvm::errs() << "FATAL ERROR: HAL could not be initialized\n"; \
24  return -1; \
25  } \
26  HAL_Report(HALUsageReporting::kResourceType_Language, \
27  HALUsageReporting::kLanguage_CPlusPlus); \
28  llvm::outs() << "\n********** Robot program starting **********\n"; \
29  static _ClassName_ robot; \
30  robot.StartCompetition(); \
31  }
32 
42 class RobotBase {
43  public:
44  bool IsEnabled() const;
45  bool IsDisabled() const;
46  bool IsAutonomous() const;
47  bool IsOperatorControl() const;
48  bool IsTest() const;
49  bool IsNewDataAvailable() const;
50  static std::thread::id GetThreadId();
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  static std::thread::id m_threadId;
63 };
64 
65 } // namespace frc
bool IsEnabled() const
Determine if the Robot is currently enabled.
Definition: RobotBase.cpp:70
bool IsAutonomous() const
Determine if the robot is currently in Autonomous mode.
Definition: RobotBase.cpp:83
bool IsDisabled() const
Determine if the Robot is currently disabled.
Definition: RobotBase.cpp:76
static std::thread::id GetThreadId()
Gets the ID of the main robot thread.
Definition: RobotBase.cpp:109
Provide access to the network communication data to / from the Driver Station.
Definition: DriverStation.h:27
bool IsNewDataAvailable() const
Indicates if new data is available from the driver station.
Definition: RobotBase.cpp:104
bool IsOperatorControl() const
Determine if the robot is currently in Operator Control mode.
Definition: RobotBase.cpp:90
Implement a Robot Program framework.
Definition: RobotBase.h:42
bool IsTest() const
Determine if the robot is currently in Test mode.
Definition: RobotBase.cpp:97
RobotBase()
Constructor for a generic robot program.
Definition: RobotBase.cpp:38