WPILibC++  unspecified
RobotBase.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2017 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 
43 class RobotBase {
44  public:
45  bool IsEnabled() const;
46  bool IsDisabled() const;
47  bool IsAutonomous() const;
48  bool IsOperatorControl() const;
49  bool IsTest() const;
50  bool IsNewDataAvailable() const;
51  static std::thread::id GetThreadId();
52  virtual void StartCompetition() = 0;
53 
54  protected:
55  RobotBase();
56  virtual ~RobotBase() = default;
57 
58  RobotBase(const RobotBase&) = delete;
59  RobotBase& operator=(const RobotBase&) = delete;
60 
61  DriverStation& m_ds;
62 
63  static std::thread::id m_threadId;
64 };
65 
66 } // namespace frc
bool IsEnabled() const
Determine if the Robot is currently enabled.
Definition: RobotBase.cpp:73
Definition: Timer.cpp:18
bool IsAutonomous() const
Determine if the robot is currently in Autonomous mode.
Definition: RobotBase.cpp:86
bool IsDisabled() const
Determine if the Robot is currently disabled.
Definition: RobotBase.cpp:79
static std::thread::id GetThreadId()
Gets the ID of the main robot thread.
Definition: RobotBase.cpp:112
Provide access to the network communication data to / from the Driver Station.
Definition: DriverStation.h:28
bool IsNewDataAvailable() const
Indicates if new data is available from the driver station.
Definition: RobotBase.cpp:107
bool IsOperatorControl() const
Determine if the robot is currently in Operator Control mode.
Definition: RobotBase.cpp:93
Implement a Robot Program framework.
Definition: RobotBase.h:43
bool IsTest() const
Determine if the robot is currently in Test mode.
Definition: RobotBase.cpp:100
RobotBase()
Constructor for a generic robot program.
Definition: RobotBase.cpp:39