mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Add ability to end startCompetition() main loop (#2032)
This is useful for both cleanly exiting from simulation and for unit testing at a framework level. This change required removing move constructor/assignment from IterativeRobot.
This commit is contained in:
@@ -32,7 +32,7 @@ void Robot::StartCompetition() {
|
||||
// Tell the DS that the robot is ready to be enabled
|
||||
HAL_ObserveUserProgramStarting();
|
||||
|
||||
while (true) {
|
||||
while (!m_exit) {
|
||||
if (IsDisabled()) {
|
||||
m_ds.InDisabled(true);
|
||||
Disabled();
|
||||
@@ -61,6 +61,8 @@ void Robot::StartCompetition() {
|
||||
}
|
||||
}
|
||||
|
||||
void Robot::EndCompetition() { m_exit = true; }
|
||||
|
||||
#ifndef RUNNING_FRC_TESTS
|
||||
int main() { return frc::StartRobot<Robot>(); }
|
||||
#endif
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
|
||||
#include <frc/RobotBase.h>
|
||||
|
||||
class Robot : public frc::RobotBase {
|
||||
@@ -18,4 +20,8 @@ class Robot : public frc::RobotBase {
|
||||
void Test();
|
||||
|
||||
void StartCompetition() override;
|
||||
void EndCompetition() override;
|
||||
|
||||
private:
|
||||
std::atomic<bool> m_exit{false};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user