Skip to content

Commit bb22ed8

Browse files
committed
Use simulation time in the Rerun logs
1 parent eaddd8b commit bb22ed8

File tree

2 files changed

+50
-9
lines changed

2 files changed

+50
-9
lines changed

isaac-rerun-logger/src/isaac_rerun_logger/__init__.py

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from datetime import datetime, timedelta
12
import os
23
from pathlib import Path
34

@@ -29,7 +30,7 @@ def initialize(
2930

3031
# Add random postfix to logger ID to avoid conflicts
3132
self._logger_id = f"{logger_id}_{np.random.randint(10000)}"
32-
rr.init(self._logger_id, spawn=True)
33+
rr.init(self._logger_id, spawn=spawn)
3334
if save_path is not None:
3435
# Ensure directory exists
3536
save_path.parent.mkdir(parents=True, exist_ok=True)
@@ -48,19 +49,55 @@ def stop(self):
4849
self._logged_meshes.clear()
4950
self._last_transforms.clear()
5051

51-
def log_stage(self, frame_idx: int = None):
52+
def set_time(
53+
self,
54+
sequence: int | None = None,
55+
duration: int | float | timedelta | np.timedelta64 | None = None,
56+
timestamp: int | float | datetime | np.datetime64 | None = None,
57+
) -> None:
5258
"""
53-
Log the entire USD stage to Rerun.
59+
Set the current time of the Rerun logger.
60+
61+
Used for all subsequent logging on the same thread, until the next call to
62+
[`rerun.set_time`][], [`rerun.reset_time`][] or [`rerun.disable_timeline`][].
63+
64+
For example: `set_time("frame_nr", sequence=frame_nr)`.
65+
66+
There is no requirement of monotonicity. You can move the time backwards if you like.
67+
68+
You are expected to set exactly ONE of the arguments `sequence`, `duration`, or `timestamp`.
69+
You may NOT change the type of a timeline, so if you use `duration` for a specific timeline,
70+
you must only use `duration` for that timeline going forward.
5471
55-
Args:
56-
frame_idx: Optional frame index for this log. If None, uses static data.
72+
Parameters
73+
----------
74+
sequence:
75+
Used for sequential indices, like `frame_nr`.
76+
Must be an integer.
77+
duration:
78+
Used for relative times, like `time_since_start`.
79+
Must either be in seconds, a [`datetime.timedelta`][], or [`numpy.timedelta64`][].
80+
For nanosecond precision, use `numpy.timedelta64(nanoseconds, 'ns')`.
81+
timestamp:
82+
Used for absolute time indices, like `capture_time`.
83+
Must either be in seconds since Unix epoch, a [`datetime.datetime`][], or [`numpy.datetime64`][].
84+
For nanosecond precision, use `numpy.datetime64(nanoseconds, 'ns')`.
85+
86+
"""
87+
rr.set_time(
88+
"clock",
89+
sequence=sequence,
90+
duration=duration,
91+
timestamp=timestamp,
92+
)
93+
94+
def log_stage(self):
95+
"""
96+
Log the entire USD stage to Rerun.
5797
"""
5898
if self.stage is None:
5999
print("Warning: USD stage is not initialized.")
60100
return
61-
# Set frame index if provided
62-
if frame_idx is not None:
63-
rr.set_time("frame_idx", sequence=frame_idx)
64101

65102
# Traverse all prims in the stage
66103
current_paths = set()

nodes/simulation/simulation/go2_scene.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ def __init__(
176176
window_size=200, update_interval=100
177177
) # 1-second window for 200Hz, update every 100 steps
178178
self.log_rtf = False
179+
self._simulation_time = 0.0
179180

180181
def initialize(self):
181182
self.world = World(
@@ -293,6 +294,8 @@ def reload_scene(self):
293294
self.load_scene(self.current_scene)
294295

295296
def on_physics_step(self, step_size) -> None:
297+
self._simulation_time += step_size
298+
296299
rtf = self._rtf_calculator.step(step_size)
297300
if rtf is not None and self.log_rtf:
298301
print(f"Real-Time Factor (RTF): {rtf:.2f}")
@@ -338,7 +341,8 @@ def step(self):
338341

339342
self.world.step(render=True)
340343
if self.rerun_logger:
341-
self.rerun_logger.log_stage(frame_idx=self.world.current_time_step_index)
344+
self.rerun_logger.set_time(duration=self._simulation_time)
345+
self.rerun_logger.log_stage()
342346

343347
self.follow_camera.update()
344348
self.waypoint_mission.update()

0 commit comments

Comments
 (0)