WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
RobotBase.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008-2016. 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 <cstdio>
11 #include <iostream>
12 #include <thread>
13 
14 #include "Base.h"
15 #include "HAL/HAL.h"
16 
17 namespace frc {
18 
19 class DriverStation;
20 
21 #define START_ROBOT_CLASS(_ClassName_) \
22  int main() { \
23  if (!HAL_Initialize(0)) { \
24  std::cerr << "FATAL ERROR: HAL could not be initialized" << std::endl; \
25  return -1; \
26  } \
27  HAL_Report(HALUsageReporting::kResourceType_Language, \
28  HALUsageReporting::kLanguage_CPlusPlus); \
29  static _ClassName_ robot; \
30  std::printf("\n********** Robot program starting **********\n"); \
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:59
bool IsAutonomous() const
Determine if the robot is currently in Autonomous mode.
Definition: RobotBase.cpp:72
bool IsDisabled() const
Determine if the Robot is currently disabled.
Definition: RobotBase.cpp:65
static std::thread::id GetThreadId()
Gets the ID of the main robot thread.
Definition: RobotBase.cpp:98
Provide access to the network communication data to / from the Driver Station.
Definition: DriverStation.h:29
bool IsNewDataAvailable() const
Indicates if new data is available from the driver station.
Definition: RobotBase.cpp:93
bool IsOperatorControl() const
Determine if the robot is currently in Operator Control mode.
Definition: RobotBase.cpp:79
Implement a Robot Program framework.
Definition: RobotBase.h:43
bool IsTest() const
Determine if the robot is currently in Test mode.
Definition: RobotBase.cpp:86
RobotBase()
Constructor for a generic robot program.
Definition: RobotBase.cpp:36