mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +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:
@@ -473,6 +473,13 @@ double DriverStation::GetBatteryVoltage() const {
|
||||
return voltage;
|
||||
}
|
||||
|
||||
void DriverStation::WakeupWaitForData() {
|
||||
std::scoped_lock waitLock(m_waitForDataMutex);
|
||||
// Nofify all threads
|
||||
m_waitForDataCounter++;
|
||||
m_waitForDataCond.notify_all();
|
||||
}
|
||||
|
||||
void DriverStation::GetData() {
|
||||
{
|
||||
// Compute the pressed and released buttons
|
||||
@@ -494,13 +501,7 @@ void DriverStation::GetData() {
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
std::scoped_lock waitLock(m_waitForDataMutex);
|
||||
// Nofify all threads
|
||||
m_waitForDataCounter++;
|
||||
m_waitForDataCond.notify_all();
|
||||
}
|
||||
|
||||
WakeupWaitForData();
|
||||
SendMatchData();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,13 @@ void IterativeRobot::StartCompetition() {
|
||||
while (true) {
|
||||
// Wait for driver station data so the loop doesn't hog the CPU
|
||||
DriverStation::GetInstance().WaitForData();
|
||||
if (m_exit) break;
|
||||
|
||||
LoopFunc();
|
||||
}
|
||||
}
|
||||
|
||||
void IterativeRobot::EndCompetition() {
|
||||
m_exit = true;
|
||||
DriverStation::GetInstance().WakeupWaitForData();
|
||||
}
|
||||
|
||||
@@ -43,6 +43,11 @@ void TimedRobot::StartCompetition() {
|
||||
}
|
||||
}
|
||||
|
||||
void TimedRobot::EndCompetition() {
|
||||
int32_t status = 0;
|
||||
HAL_StopNotifier(m_notifier, &status);
|
||||
}
|
||||
|
||||
units::second_t TimedRobot::GetPeriod() const {
|
||||
return units::second_t(m_period);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user