From 944d0e225e8cb46b2540ff74fbab3f4b480b054f Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 15 Aug 2024 22:57:28 +0200 Subject: [PATCH] Better clarification of WorldSnapshot - removed deprecated frame_count from example - also exposed WorldSnapshot.elapsed_seconds --- Docs/python_api.md | 2 ++ PythonAPI/docs/snapshot.yml | 5 +++++ PythonAPI/examples/V2XDemo.py | 6 +++--- PythonAPI/examples/automatic_control.py | 8 ++++---- PythonAPI/examples/manual_control.py | 7 ++++--- PythonAPI/examples/manual_control_carsim.py | 7 ++++--- PythonAPI/examples/manual_control_chrono.py | 7 ++++--- PythonAPI/examples/manual_control_steeringwheel.py | 7 ++++--- PythonAPI/examples/no_rendering_mode.py | 6 +++--- PythonAPI/examples/rss/manual_control_rss.py | 7 ++++--- 10 files changed, 37 insertions(+), 25 deletions(-) diff --git a/Docs/python_api.md b/Docs/python_api.md index 1237d7381f..8b1e00b006 100644 --- a/Docs/python_api.md +++ b/Docs/python_api.md @@ -3934,6 +3934,8 @@ This snapshot comprises all the information for every actor on scene at a certai A value unique for every snapshot to differentiate them. - **frame** (_int_) Simulation frame in which the snapshot was taken. +- **elapsed_seconds** (_float - seconds_) +Simulated seconds elapsed since the beginning of the current episode. - **timestamp** (_[carla.Timestamp](#carla.Timestamp) - seconds_) Precise moment in time when snapshot was taken. This class works in seconds as given by the operative system. diff --git a/PythonAPI/docs/snapshot.yml b/PythonAPI/docs/snapshot.yml index 9a9c7f2e66..bc5e72767d 100644 --- a/PythonAPI/docs/snapshot.yml +++ b/PythonAPI/docs/snapshot.yml @@ -17,6 +17,11 @@ type: int doc: > Simulation frame in which the snapshot was taken. + - var_name: elapsed_seconds + type: float + var_units: seconds + doc: > + Simulated seconds elapsed since the beginning of the current episode. - var_name: timestamp type: carla.Timestamp var_units: seconds diff --git a/PythonAPI/examples/V2XDemo.py b/PythonAPI/examples/V2XDemo.py index eedfae968e..0c4736ab51 100644 --- a/PythonAPI/examples/V2XDemo.py +++ b/PythonAPI/examples/V2XDemo.py @@ -685,11 +685,11 @@ def __init__(self, width, height): self._show_ackermann_info = False self._ackermann_control = carla.VehicleAckermannControl() - def on_world_tick(self, timestamp): + def on_world_tick(self, world_snapshot): self._server_clock.tick() self.server_fps = self._server_clock.get_fps() - self.frame = timestamp.frame - self.simulation_time = timestamp.elapsed_seconds + self.frame = world_snapshot.frame + self.simulation_time = world_snapshot.elapsed_seconds def tick(self, world, clock): self._notifications.tick(world, clock) diff --git a/PythonAPI/examples/automatic_control.py b/PythonAPI/examples/automatic_control.py index 330d9afe43..6950db4927 100755 --- a/PythonAPI/examples/automatic_control.py +++ b/PythonAPI/examples/automatic_control.py @@ -282,12 +282,12 @@ def __init__(self, width, height): self._info_text = [] self._server_clock = pygame.time.Clock() - def on_world_tick(self, timestamp): - """Gets informations from the world at every tick""" + def on_world_tick(self, world_snapshot): + """Gets information from the world at every tick""" self._server_clock.tick() self.server_fps = self._server_clock.get_fps() - self.frame = timestamp.frame_count - self.simulation_time = timestamp.elapsed_seconds + self.frame = world_snapshot.frame + self.simulation_time = world_snapshot.elapsed_seconds def tick(self, world, clock): """HUD method for every tick""" diff --git a/PythonAPI/examples/manual_control.py b/PythonAPI/examples/manual_control.py index c35019ecb6..7073d52890 100755 --- a/PythonAPI/examples/manual_control.py +++ b/PythonAPI/examples/manual_control.py @@ -685,11 +685,12 @@ def __init__(self, width, height): self._show_ackermann_info = False self._ackermann_control = carla.VehicleAckermannControl() - def on_world_tick(self, timestamp): + def on_world_tick(self, world_snapshot): + """Gets information from the world at every tick""" self._server_clock.tick() self.server_fps = self._server_clock.get_fps() - self.frame = timestamp.frame - self.simulation_time = timestamp.elapsed_seconds + self.frame = world_snapshot.frame + self.simulation_time = world_snapshot.elapsed_seconds def tick(self, world, clock): self._notifications.tick(world, clock) diff --git a/PythonAPI/examples/manual_control_carsim.py b/PythonAPI/examples/manual_control_carsim.py index bf476338f3..904664d946 100644 --- a/PythonAPI/examples/manual_control_carsim.py +++ b/PythonAPI/examples/manual_control_carsim.py @@ -575,11 +575,12 @@ def __init__(self, width, height): self._info_text = [] self._server_clock = pygame.time.Clock() - def on_world_tick(self, timestamp): + def on_world_tick(self, world_snapshot): + """Gets information from the world at every tick""" self._server_clock.tick() self.server_fps = self._server_clock.get_fps() - self.frame = timestamp.frame - self.simulation_time = timestamp.elapsed_seconds + self.frame = world_snapshot.frame + self.simulation_time = world_snapshot.elapsed_seconds def tick(self, world, clock): self._notifications.tick(world, clock) diff --git a/PythonAPI/examples/manual_control_chrono.py b/PythonAPI/examples/manual_control_chrono.py index f72bc7ecf0..54f0347560 100644 --- a/PythonAPI/examples/manual_control_chrono.py +++ b/PythonAPI/examples/manual_control_chrono.py @@ -594,11 +594,12 @@ def __init__(self, width, height): self._info_text = [] self._server_clock = pygame.time.Clock() - def on_world_tick(self, timestamp): + def on_world_tick(self, world_snapshot): + """Gets information from the world at every tick""" self._server_clock.tick() self.server_fps = self._server_clock.get_fps() - self.frame = timestamp.frame - self.simulation_time = timestamp.elapsed_seconds + self.frame = world_snapshot.frame + self.simulation_time = world_snapshot.elapsed_seconds def tick(self, world, clock): self._notifications.tick(world, clock) diff --git a/PythonAPI/examples/manual_control_steeringwheel.py b/PythonAPI/examples/manual_control_steeringwheel.py index 3977263ec6..fd109d48ac 100755 --- a/PythonAPI/examples/manual_control_steeringwheel.py +++ b/PythonAPI/examples/manual_control_steeringwheel.py @@ -399,11 +399,12 @@ def __init__(self, width, height): self._info_text = [] self._server_clock = pygame.time.Clock() - def on_world_tick(self, timestamp): + def on_world_tick(self, world_snapshot): + """Gets information from the world at every tick""" self._server_clock.tick() self.server_fps = self._server_clock.get_fps() - self.frame = timestamp.frame - self.simulation_time = timestamp.elapsed_seconds + self.frame = world_snapshot.frame + self.simulation_time = world_snapshot.elapsed_seconds def tick(self, world, clock): self._notifications.tick(world, clock) diff --git a/PythonAPI/examples/no_rendering_mode.py b/PythonAPI/examples/no_rendering_mode.py index 0752904119..4cfd01f4ef 100755 --- a/PythonAPI/examples/no_rendering_mode.py +++ b/PythonAPI/examples/no_rendering_mode.py @@ -993,7 +993,7 @@ def start(self, hud, input_control): # Register event for receiving server tick weak_self = weakref.ref(self) - self.world.on_tick(lambda timestamp: World.on_world_tick(weak_self, timestamp)) + self.world.on_tick(lambda world_snapshot: World.on_world_tick(weak_self, world_snapshot)) def select_hero_actor(self): """Selects only one hero actor if there are more than one. If there are not any, it will spawn one.""" @@ -1081,7 +1081,7 @@ def update_hud_info(self, clock): self._hud.add_info('HERO', hero_mode_text) @staticmethod - def on_world_tick(weak_self, timestamp): + def on_world_tick(weak_self, world_snapshot): """Updates the server tick""" self = weak_self() if not self: @@ -1089,7 +1089,7 @@ def on_world_tick(weak_self, timestamp): self.server_clock.tick() self.server_fps = self.server_clock.get_fps() - self.simulation_time = timestamp.elapsed_seconds + self.simulation_time = world_snapshot.elapsed_seconds def _show_nearby_vehicles(self, vehicles): """Shows nearby vehicles of the hero actor""" diff --git a/PythonAPI/examples/rss/manual_control_rss.py b/PythonAPI/examples/rss/manual_control_rss.py index ff0b7e1c5b..357685c02a 100755 --- a/PythonAPI/examples/rss/manual_control_rss.py +++ b/PythonAPI/examples/rss/manual_control_rss.py @@ -616,11 +616,12 @@ def __init__(self, width, height, world): self._server_clock = pygame.time.Clock() self.rss_state_visualizer = RssStateVisualizer(self.dim, self._font_mono, self._world) - def on_world_tick(self, timestamp): + def on_world_tick(self, world_snapshot): + """Gets information from the world at every tick""" self._server_clock.tick() self.server_fps = self._server_clock.get_fps() - self.frame = timestamp.frame - self.simulation_time = timestamp.elapsed_seconds + self.frame = world_snapshot.frame + self.simulation_time = world_snapshot.elapsed_seconds def tick(self, player, clock): self._notifications.tick(clock)