Skip to content

Commit

Permalink
Merge branch 'master' into complete-workaround-for-HALSimWS-SimDevice…
Browse files Browse the repository at this point in the history
…-deadlocks
  • Loading branch information
brettle committed Jul 17, 2024
2 parents c0ebd9a + 7500719 commit e77b9ba
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
13 changes: 12 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
"type": "cppdbg",
"request": "attach",
"program": "${env:HOME}/wpilib/2024/jdk/bin/java",
"windows": {
"program": "${env:PUBLIC}\\wpilib\\2024\\jdk\\bin\\java"
},
"sourceFileMap": {
"/work/": "${env:HOME}/git/allwpilib/"
"/work/": "${input:wpilibSrcPath}/"
},
"MIMode": "gdb",
"setupCommands": [
Expand Down Expand Up @@ -55,5 +58,13 @@
"args": "--no-robot-code",
"cwd": "${workspaceFolder}/example/Webots/controllers/DeepBlueSim"
}
],
"inputs": [
{
"id": "wpilibSrcPath",
"type": "promptString",
"description": "The path to the wpilib source code (no trailing slash)",
"default": "${workspaceFolder}/../allwpilib"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ private static void updateUsersSimulationSpeed(Supervisor robot) {

private static boolean gotSimMode;

private static final long minQuietTimeMs = 500;

private static final Timer delayer = new Timer();
private static volatile long lastMsgTimeMs = -1;

Expand Down Expand Up @@ -204,17 +206,15 @@ public void run() {
try (var p = requestTopic.publish(pubSubOptions)) {
requestTopic.setCached(false);
}
var requestSubscriber =
requestTopic.subscribe("", pubSubOptions);
var requestSubscriber = requestTopic.subscribe("", pubSubOptions);
inst.addListener(requestSubscriber,
EnumSet.of(Kind.kValueRemote, Kind.kImmediate), (event) -> {
var request = event.valueData.value.getString();
LOG.log(Level.DEBUG, "In listener, request = {0}",
request);
LOG.log(Level.DEBUG, "In listener, request = {0}", request);
if (request == null)
return;
var requestParts = request.split(" ", 2);
var requestVerb = requestParts[0];
var requestVerb = requestParts[0];
switch (requestVerb) {
case NTConstants.REQUEST_LOAD_VERB:
if (requestParts.length != 2) {
Expand Down Expand Up @@ -313,8 +313,8 @@ public void run() {
LOG.log(Level.DEBUG, "In connection listener");
if (event.is(Kind.kConnected)) {
queuedEvents.add(() -> {
var statusTopic = coordinator.getStringTopic(
NTConstants.STATUS_TOPIC_NAME);
var statusTopic = coordinator
.getStringTopic(NTConstants.STATUS_TOPIC_NAME);
statusTopic.setCached(false);
statusPublisher = statusTopic.publish(pubSubOptions);
sendCompletedOnceHALSimIsQuiet();
Expand Down Expand Up @@ -378,18 +378,14 @@ private static void handleLoadRequest(Supervisor robot, int basicTimeStep,
});
}

private static final long minQuietTimeMs = 500;

private static void sendCompletedOnceHALSimIsQuiet() {
// To workaround https://github.com/wpilibsuite/allwpilib/issues/6842, wait until HALSim has
// been quiet for a bit. We take that as a sign that any of the server's onConnect callbacks
// have run and it will be safe for the WebotsSimulator to create SimDevices.
var timeSinceLastMsgMs = getTimeSinceLastMessageMs();
if (statusPublisher != null
&& timeSinceLastMsgMs > minQuietTimeMs) {
if (statusPublisher != null && timeSinceLastMsgMs > minQuietTimeMs) {
LOG.log(Level.DEBUG, "Setting status to Completed");
statusPublisher
.set(NTConstants.STATUS_COMPLETED_VALUE);
statusPublisher.set(NTConstants.STATUS_COMPLETED_VALUE);
inst.flush();
} else {
LOG.log(Level.DEBUG,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ private void sendRobotTime() {
}

private SimDevice timeSyncDevice;
private SimDeviceSim timeSyncDeviceSim;
private SimDeviceSim timeSyncDeviceSim;

private void startTimeSync() {
LOG.log(Level.DEBUG, "In startTimeSync()");
Expand Down Expand Up @@ -767,7 +767,7 @@ public void run() throws InstantiationException, IllegalAccessException,
waitForUserToStart(worldFile.getAbsolutePath());

// Restart timing before robot is constructed to ensure that timed callbacks added during
// the constructor (and out own onRobotInit callback) work properly.
// the constructor (and our own onRobotInit callback) work properly.
SimHooks.restartTiming();
SimHooks.pauseTiming();
try (TimedRobot robot = robotConstructor.get();
Expand Down

0 comments on commit e77b9ba

Please sign in to comment.