Skip to content

Commit

Permalink
Move the creation of the time sync SimDevice to before the robot is e…
Browse files Browse the repository at this point in the history
…ven created.

This ensures that there is no way it is created after some robot code requests a HALSimWS connection.
  • Loading branch information
brettle committed Jul 18, 2024
1 parent 31850e6 commit 0673825
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -424,11 +424,6 @@ private void sendRobotTime() {
private void startTimeSync() {
LOG.log(Level.DEBUG, "In startTimeSync()");
ensureRobotTimingStarted();
timeSyncDevice = SimDevice.create("DBSTimeSync");
robotTimeSecSim = timeSyncDevice.createDouble("robotTimeSec",
SimDevice.Direction.kBidir, -1.0);
timeSyncDevice.createDouble("simTimeSec", SimDevice.Direction.kBidir,
-1.0);
LOG.log(Level.DEBUG, "Created SimDevice with name {0}",
timeSyncDevice.getName());
timeSyncDeviceSim = new SimDeviceSim("DBSTimeSync");
Expand Down Expand Up @@ -800,6 +795,12 @@ public void run() throws InstantiationException, IllegalAccessException,
HAL.initialize(500, 0);
waitForUserToStart(worldFile.getAbsolutePath());

timeSyncDevice = SimDevice.create("DBSTimeSync");
robotTimeSecSim = timeSyncDevice.createDouble("robotTimeSec",
SimDevice.Direction.kOutput, -1.0);
timeSyncDevice.createDouble("simTimeSec", SimDevice.Direction.kInput,
-1.0);

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

0 comments on commit 0673825

Please sign in to comment.