Skip to content

Commit

Permalink
Better clarification of WorldSnapshot
Browse files Browse the repository at this point in the history
- removed deprecated frame_count from example
- also exposed WorldSnapshot.elapsed_seconds
  • Loading branch information
Daraan committed Sep 23, 2024
1 parent cdb2664 commit 944d0e2
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 25 deletions.
2 changes: 2 additions & 0 deletions Docs/python_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
5 changes: 5 additions & 0 deletions PythonAPI/docs/snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions PythonAPI/examples/V2XDemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions PythonAPI/examples/automatic_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
7 changes: 4 additions & 3 deletions PythonAPI/examples/manual_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions PythonAPI/examples/manual_control_carsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions PythonAPI/examples/manual_control_chrono.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions PythonAPI/examples/manual_control_steeringwheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions PythonAPI/examples/no_rendering_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -1081,15 +1081,15 @@ 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:
return

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"""
Expand Down
7 changes: 4 additions & 3 deletions PythonAPI/examples/rss/manual_control_rss.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 944d0e2

Please sign in to comment.