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 "Base.h"
11 #include "Task.h"
12 
13 class DriverStation;
14 
15 #define START_ROBOT_CLASS(_ClassName_) \
16  int main() { \
17  if (!HALInitialize()) { \
18  std::cerr << "FATAL ERROR: HAL could not be initialized" << std::endl; \
19  return -1; \
20  } \
21  HALReport(HALUsageReporting::kResourceType_Language, \
22  HALUsageReporting::kLanguage_CPlusPlus); \
23  _ClassName_ *robot = new _ClassName_(); \
24  RobotBase::robotSetup(robot); \
25  return 0; \
26  }
27 
40 class RobotBase {
41  friend class RobotDeleter;
42 
43  public:
44  static RobotBase &getInstance();
45  static void setInstance(RobotBase *robot);
46 
47  bool IsEnabled() const;
48  bool IsDisabled() const;
49  bool IsAutonomous() const;
50  bool IsOperatorControl() const;
51  bool IsTest() const;
52  bool IsNewDataAvailable() const;
53  static void startRobotTask(FUNCPTR factory);
54  static void robotTask(FUNCPTR factory, Task *task);
55  virtual void StartCompetition() = 0;
56 
57  static void robotSetup(RobotBase *robot);
58 
59  protected:
60  RobotBase();
61  virtual ~RobotBase();
62 
63  RobotBase(const RobotBase&) = delete;
64  RobotBase& operator=(const RobotBase&) = delete;
65 
66  Task *m_task = nullptr;
67  DriverStation &m_ds;
68 
69  private:
70  static RobotBase *m_instance;
71 };
bool IsTest() const
Determine if the robot is currently in Test mode.
Definition: RobotBase.cpp:108
bool IsNewDataAvailable() const
Indicates if new data is available from the driver station.
Definition: RobotBase.cpp:115
bool IsEnabled() const
Determine if the Robot is currently enabled.
Definition: RobotBase.cpp:81
bool IsDisabled() const
Determine if the Robot is currently disabled.
Definition: RobotBase.cpp:87
bool IsOperatorControl() const
Determine if the robot is currently in Operator Control mode.
Definition: RobotBase.cpp:101
Implement a Robot Program framework.
Definition: RobotBase.h:40
RobotBase()
Constructor for a generic robot program.
Definition: RobotBase.cpp:46
This class exists for the sole purpose of getting its destructor called when the module unloads...
Definition: RobotBase.cpp:126
bool IsAutonomous() const
Determine if the robot is currently in Autonomous mode.
Definition: RobotBase.cpp:94
virtual ~RobotBase()
Free the resources for a RobotBase class.
Definition: RobotBase.cpp:70
Wrapper class around std::thread that allows changing thread priority.
Definition: Task.h:19
Provide access to the network communication data to / from the Driver Station.
Definition: DriverStation.h:27