diff --git a/plugin/libdeepbluesim/src/main/java/org/carlmontrobotics/libdeepbluesim/WebotsSimulator.java b/plugin/libdeepbluesim/src/main/java/org/carlmontrobotics/libdeepbluesim/WebotsSimulator.java index 1852586..555b60a 100644 --- a/plugin/libdeepbluesim/src/main/java/org/carlmontrobotics/libdeepbluesim/WebotsSimulator.java +++ b/plugin/libdeepbluesim/src/main/java/org/carlmontrobotics/libdeepbluesim/WebotsSimulator.java @@ -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"); @@ -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();