14 #include <wpi/condition_variable.h>
15 #include <wpi/mutex.h>
16 #include <wpi/raw_ostream.h>
24 int RunHALInitialization();
28 template <
class Robot>
29 void RunRobot(wpi::mutex& m, Robot** robot) {
30 static Robot theRobot;
32 std::scoped_lock lock{m};
35 theRobot.StartCompetition();
40 template <
class Robot>
42 int halInit = RunHALInitialization();
48 static wpi::condition_variable cv;
49 static Robot* robot =
nullptr;
50 static bool exited =
false;
55 impl::RunRobot<Robot>(m, &robot);
59 std::scoped_lock lock{m};
69 std::scoped_lock lock{m};
79 if (robot) robot->EndCompetition();
82 using namespace std::chrono_literals;
83 std::unique_lock lock{m};
84 if (cv.wait_for(lock, 1s, [] { return exited; }))
89 impl::RunRobot<Robot>(m, &robot);
95 #define START_ROBOT_CLASS(_ClassName_) \
96 WPI_DEPRECATED("Call frc::StartRobot<" #_ClassName_ \
97 ">() in your own main() instead of using the " \
98 "START_ROBOT_CLASS(" #_ClassName_ ") macro.") \
99 int StartRobotClassImpl() { return frc::StartRobot<_ClassName_>(); } \
100 int main() { return StartRobotClassImpl(); }
165 virtual void StartCompetition() = 0;
167 virtual void EndCompetition() = 0;
169 static constexpr
bool IsReal() {
170 #ifdef __FRC_ROBORIO__
177 static constexpr
bool IsSimulation() {
return !IsReal(); }
202 static std::thread::id m_threadId;
void HAL_ExitMain(void)
Causes HAL_RunMain() to exit.
void HAL_RunMain(void)
Runs the main function provided to HAL_SetMain().
bool IsEnabled() const
Determine if the Robot is currently enabled.
bool IsDisabled() const
Determine if the Robot is currently disabled.
bool IsAutonomous() const
Determine if the robot is currently in Autonomous mode.
RobotBase()
Constructor for a generic robot program.
bool IsTest() const
Determine if the robot is currently in Test mode.
HAL_Bool HAL_HasMain(void)
Returns true if HAL_SetMain() has been called.
static std::thread::id GetThreadId()
Gets the ID of the main robot thread.
A class that enforces constraints on the differential drive kinematics.
Definition: SPIAccelerometerSim.h:16
bool IsNewDataAvailable() const
Indicates if new data is available from the driver station.
Implement a Robot Program framework.
Definition: RobotBase.h:112
bool IsOperatorControl() const
Determine if the robot is currently in Operator Control mode.
Provide access to the network communication data to / from the Driver Station.
Definition: DriverStation.h:33