Skip to content

Commit f76ca29

Browse files
committed
Better clarification of WorldSnapshot
- removed deprecated frame_count from example - also exposed WorldSnapshot.elapsed_seconds
1 parent f0a427f commit f76ca29

File tree

10 files changed

+37
-25
lines changed

10 files changed

+37
-25
lines changed

Docs/python_api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3934,6 +3934,8 @@ This snapshot comprises all the information for every actor on scene at a certai
39343934
A value unique for every snapshot to differentiate them.
39353935
- <a name="carla.WorldSnapshot.frame"></a>**<font color="#f8805a">frame</font>** (_int_)
39363936
Simulation frame in which the snapshot was taken.
3937+
- <a name="carla.WorldSnapshot.elapsed_seconds"></a>**<font color="#f8805a">elapsed_seconds</font>** (_float<small> - seconds</small>_)
3938+
Simulated seconds elapsed since the beginning of the current episode.
39373939
- <a name="carla.WorldSnapshot.timestamp"></a>**<font color="#f8805a">timestamp</font>** (_[carla.Timestamp](#carla.Timestamp)<small> - seconds</small>_)
39383940
Precise moment in time when snapshot was taken. This class works in seconds as given by the operative system.
39393941

PythonAPI/docs/snapshot.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
type: int
1818
doc: >
1919
Simulation frame in which the snapshot was taken.
20+
- var_name: elapsed_seconds
21+
type: float
22+
var_units: seconds
23+
doc: >
24+
Simulated seconds elapsed since the beginning of the current episode.
2025
- var_name: timestamp
2126
type: carla.Timestamp
2227
var_units: seconds

PythonAPI/examples/V2XDemo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,11 +685,11 @@ def __init__(self, width, height):
685685
self._show_ackermann_info = False
686686
self._ackermann_control = carla.VehicleAckermannControl()
687687

688-
def on_world_tick(self, timestamp):
688+
def on_world_tick(self, world_snapshot):
689689
self._server_clock.tick()
690690
self.server_fps = self._server_clock.get_fps()
691-
self.frame = timestamp.frame
692-
self.simulation_time = timestamp.elapsed_seconds
691+
self.frame = world_snapshot.frame
692+
self.simulation_time = world_snapshot.elapsed_seconds
693693

694694
def tick(self, world, clock):
695695
self._notifications.tick(world, clock)

PythonAPI/examples/automatic_control.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,12 @@ def __init__(self, width, height):
282282
self._info_text = []
283283
self._server_clock = pygame.time.Clock()
284284

285-
def on_world_tick(self, timestamp):
286-
"""Gets informations from the world at every tick"""
285+
def on_world_tick(self, world_snapshot):
286+
"""Gets information from the world at every tick"""
287287
self._server_clock.tick()
288288
self.server_fps = self._server_clock.get_fps()
289-
self.frame = timestamp.frame_count
290-
self.simulation_time = timestamp.elapsed_seconds
289+
self.frame = world_snapshot.frame
290+
self.simulation_time = world_snapshot.elapsed_seconds
291291

292292
def tick(self, world, clock):
293293
"""HUD method for every tick"""

PythonAPI/examples/manual_control.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,11 +685,12 @@ def __init__(self, width, height):
685685
self._show_ackermann_info = False
686686
self._ackermann_control = carla.VehicleAckermannControl()
687687

688-
def on_world_tick(self, timestamp):
688+
def on_world_tick(self, world_snapshot):
689+
"""Gets information from the world at every tick"""
689690
self._server_clock.tick()
690691
self.server_fps = self._server_clock.get_fps()
691-
self.frame = timestamp.frame
692-
self.simulation_time = timestamp.elapsed_seconds
692+
self.frame = world_snapshot.frame
693+
self.simulation_time = world_snapshot.elapsed_seconds
693694

694695
def tick(self, world, clock):
695696
self._notifications.tick(world, clock)

PythonAPI/examples/manual_control_carsim.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -575,11 +575,12 @@ def __init__(self, width, height):
575575
self._info_text = []
576576
self._server_clock = pygame.time.Clock()
577577

578-
def on_world_tick(self, timestamp):
578+
def on_world_tick(self, world_snapshot):
579+
"""Gets information from the world at every tick"""
579580
self._server_clock.tick()
580581
self.server_fps = self._server_clock.get_fps()
581-
self.frame = timestamp.frame
582-
self.simulation_time = timestamp.elapsed_seconds
582+
self.frame = world_snapshot.frame
583+
self.simulation_time = world_snapshot.elapsed_seconds
583584

584585
def tick(self, world, clock):
585586
self._notifications.tick(world, clock)

PythonAPI/examples/manual_control_chrono.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -594,11 +594,12 @@ def __init__(self, width, height):
594594
self._info_text = []
595595
self._server_clock = pygame.time.Clock()
596596

597-
def on_world_tick(self, timestamp):
597+
def on_world_tick(self, world_snapshot):
598+
"""Gets information from the world at every tick"""
598599
self._server_clock.tick()
599600
self.server_fps = self._server_clock.get_fps()
600-
self.frame = timestamp.frame
601-
self.simulation_time = timestamp.elapsed_seconds
601+
self.frame = world_snapshot.frame
602+
self.simulation_time = world_snapshot.elapsed_seconds
602603

603604
def tick(self, world, clock):
604605
self._notifications.tick(world, clock)

PythonAPI/examples/manual_control_steeringwheel.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,12 @@ def __init__(self, width, height):
399399
self._info_text = []
400400
self._server_clock = pygame.time.Clock()
401401

402-
def on_world_tick(self, timestamp):
402+
def on_world_tick(self, world_snapshot):
403+
"""Gets information from the world at every tick"""
403404
self._server_clock.tick()
404405
self.server_fps = self._server_clock.get_fps()
405-
self.frame = timestamp.frame
406-
self.simulation_time = timestamp.elapsed_seconds
406+
self.frame = world_snapshot.frame
407+
self.simulation_time = world_snapshot.elapsed_seconds
407408

408409
def tick(self, world, clock):
409410
self._notifications.tick(world, clock)

PythonAPI/examples/no_rendering_mode.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ def start(self, hud, input_control):
993993

994994
# Register event for receiving server tick
995995
weak_self = weakref.ref(self)
996-
self.world.on_tick(lambda timestamp: World.on_world_tick(weak_self, timestamp))
996+
self.world.on_tick(lambda world_snapshot: World.on_world_tick(weak_self, world_snapshot))
997997

998998
def select_hero_actor(self):
999999
"""Selects only one hero actor if there are more than one. If there are not any, it will spawn one."""
@@ -1081,15 +1081,15 @@ def update_hud_info(self, clock):
10811081
self._hud.add_info('HERO', hero_mode_text)
10821082

10831083
@staticmethod
1084-
def on_world_tick(weak_self, timestamp):
1084+
def on_world_tick(weak_self, world_snapshot):
10851085
"""Updates the server tick"""
10861086
self = weak_self()
10871087
if not self:
10881088
return
10891089

10901090
self.server_clock.tick()
10911091
self.server_fps = self.server_clock.get_fps()
1092-
self.simulation_time = timestamp.elapsed_seconds
1092+
self.simulation_time = world_snapshot.elapsed_seconds
10931093

10941094
def _show_nearby_vehicles(self, vehicles):
10951095
"""Shows nearby vehicles of the hero actor"""

PythonAPI/examples/rss/manual_control_rss.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -616,11 +616,12 @@ def __init__(self, width, height, world):
616616
self._server_clock = pygame.time.Clock()
617617
self.rss_state_visualizer = RssStateVisualizer(self.dim, self._font_mono, self._world)
618618

619-
def on_world_tick(self, timestamp):
619+
def on_world_tick(self, world_snapshot):
620+
"""Gets information from the world at every tick"""
620621
self._server_clock.tick()
621622
self.server_fps = self._server_clock.get_fps()
622-
self.frame = timestamp.frame
623-
self.simulation_time = timestamp.elapsed_seconds
623+
self.frame = world_snapshot.frame
624+
self.simulation_time = world_snapshot.elapsed_seconds
624625

625626
def tick(self, player, clock):
626627
self._notifications.tick(clock)

0 commit comments

Comments
 (0)