mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user