Better clarification of WorldSnapshot

- removed deprecated frame_count from example
- also exposed WorldSnapshot.elapsed_seconds
This commit is contained in:
Daniel 2024-08-15 22:57:28 +02:00 committed by Daraan
parent cdb2664350
commit 944d0e225e
10 changed files with 37 additions and 25 deletions

View File

@ -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.
- <a name="carla.WorldSnapshot.frame"></a>**<font color="#f8805a">frame</font>** (_int_)
Simulation frame in which the snapshot was taken.
- <a name="carla.WorldSnapshot.elapsed_seconds"></a>**<font color="#f8805a">elapsed_seconds</font>** (_float<small> - seconds</small>_)
Simulated seconds elapsed since the beginning of the current episode.
- <a name="carla.WorldSnapshot.timestamp"></a>**<font color="#f8805a">timestamp</font>** (_[carla.Timestamp](#carla.Timestamp)<small> - seconds</small>_)
Precise moment in time when snapshot was taken. This class works in seconds as given by the operative system.

View File

@ -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

View File

@ -685,11 +685,11 @@ class HUD(object):
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)

View File

@ -282,12 +282,12 @@ class HUD(object):
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"""

View File

@ -685,11 +685,12 @@ class HUD(object):
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)

View File

@ -575,11 +575,12 @@ class HUD(object):
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)

View File

@ -594,11 +594,12 @@ class HUD(object):
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)

View File

@ -399,11 +399,12 @@ class HUD(object):
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)

View File

@ -993,7 +993,7 @@ class World(object):
# 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 @@ class World(object):
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 @@ class World(object):
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"""

View File

@ -616,11 +616,12 @@ class HUD(object):
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)