[wpilib] Don't do wait on init for ExHub in sim (#8865)

Closes #8859
This commit is contained in:
Thad House
2026-05-07 09:58:14 -07:00
committed by GitHub
parent b10bc0a674
commit 63a82dccb2
2 changed files with 16 additions and 10 deletions

View File

@@ -8,6 +8,7 @@
#include <memory>
#include <thread>
#include "wpi/framework/RobotBase.hpp"
#include "wpi/hal/UsageReporting.hpp"
#include "wpi/hardware/expansionhub/ExpansionHubCRServo.hpp"
#include "wpi/hardware/expansionhub/ExpansionHubMotor.hpp"
@@ -33,12 +34,14 @@ class ExpansionHub::DataStore {
// Wait up to half a second for connected to come up, using a poll loop to
// ensure we don't block.
auto startTime = Timer::GetMonotonicTimestamp();
while (Timer::GetMonotonicTimestamp() - startTime < 0.5_s) {
if (m_hubConnectedSubscriber.Get(false)) {
break;
if constexpr (RobotBase::IsReal()) {
auto startTime = Timer::GetMonotonicTimestamp();
while (Timer::GetMonotonicTimestamp() - startTime < 0.5_s) {
if (m_hubConnectedSubscriber.Get(false)) {
break;
}
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
}

View File

@@ -4,6 +4,7 @@
package org.wpilib.hardware.expansionhub;
import org.wpilib.framework.RobotBase;
import org.wpilib.hardware.hal.HAL;
import org.wpilib.networktables.BooleanSubscriber;
import org.wpilib.networktables.NetworkTableInstance;
@@ -32,12 +33,14 @@ public class ExpansionHub implements AutoCloseable {
// Wait up to half a second for connected to come up, using a poll loop to
// ensure we don't block.
double startTime = Timer.getMonotonicTimestamp();
while (Timer.getMonotonicTimestamp() - startTime < 0.5) {
if (m_hubConnectedSubscriber.get(false)) {
break;
if (RobotBase.isReal()) {
double startTime = Timer.getMonotonicTimestamp();
while (Timer.getMonotonicTimestamp() - startTime < 0.5) {
if (m_hubConnectedSubscriber.get(false)) {
break;
}
Timer.delay(0.01);
}
Timer.delay(0.01);
}
}