Skip to content

Commit 84f286d

Browse files
committed
fix delta step calculation to control the simulation speed
Signed-off-by: Maxime CLEMENT <maxime.clement@tier4.jp>
1 parent 97815cd commit 84f286d

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

simulator/carla_autoware/src/carla_autoware/carla_autoware.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ def __init__(self):
6060
self.world = None
6161
self.sensor_wrapper = None
6262
self.ego_vehicle = None
63-
self.timestamp_last_run = 0.0
64-
self.delta_step = 0.0
63+
self.prev_tick_wall_time = 0.0
6564

6665
# Parameter for Initializing Carla World
6766
self.local_host = self.param_["host"]
@@ -167,11 +166,11 @@ def run_bridge(self):
167166
if snapshot:
168167
timestamp = snapshot.timestamp
169168
if timestamp:
170-
self.delta_step = timestamp.elapsed_seconds - self.timestamp_last_run
171-
if self.delta_step < self.max_real_delta_seconds:
169+
delta_step = time.time() - self.prev_tick_wall_time
170+
if delta_step <= self.max_real_delta_seconds:
172171
# Add a wait to match the max_real_delta_seconds
173-
time.sleep(self.max_real_delta_seconds - self.delta_step)
174-
self.timestamp_last_run = timestamp.elapsed_seconds
172+
time.sleep(self.max_real_delta_seconds - delta_step)
173+
self.prev_tick_wall_time = time.time()
175174
self.bridge_loop._tick_sensor(timestamp)
176175

177176
def _stop_loop(self, signum, frame):

0 commit comments

Comments
 (0)