From 5cbe198dc7edd019f1fe614c783f638d89617628 Mon Sep 17 00:00:00 2001 From: Yuming-Lee24 Date: Tue, 14 Jul 2026 11:47:50 +0200 Subject: [PATCH 1/2] Add warning for controller execution time exceeding loop frequency in sim --- scripts/sim.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/sim.py b/scripts/sim.py index 03998112b..0b77a643d 100644 --- a/scripts/sim.py +++ b/scripts/sim.py @@ -10,6 +10,7 @@ from __future__ import annotations import logging +import time from pathlib import Path from typing import TYPE_CHECKING @@ -81,13 +82,19 @@ def simulate( while True: curr_time = i / config.env.freq + t_start = time.perf_counter() action = controller.compute_control(obs, info) + control_time = time.perf_counter() - t_start obs, reward, terminated, truncated, info = env.step(action) # Update the controller internal state and models. + t_start = time.perf_counter() controller_finished = controller.step_callback( action, obs, reward, terminated, truncated, info ) + control_time += time.perf_counter() - t_start + if (exc := control_time - 1 / config.env.freq) > 0: + logger.warning(f"Controller execution time exceeded loop frequency by {exc:.3f}s.") # Add up reward, collisions if terminated or truncated or controller_finished: break From 59fffa064b4e25dca367c8f47d4663e150b50c85 Mon Sep 17 00:00:00 2001 From: Yuming Li <141678040+Yuming-Lee24@users.noreply.github.com> Date: Tue, 14 Jul 2026 15:24:08 +0200 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Marcel Rath <75042654+ratheron@users.noreply.github.com> --- scripts/sim.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/sim.py b/scripts/sim.py index 0b77a643d..c1ba42a34 100644 --- a/scripts/sim.py +++ b/scripts/sim.py @@ -82,18 +82,17 @@ def simulate( while True: curr_time = i / config.env.freq - t_start = time.perf_counter() + t_loop = time.perf_counter() action = controller.compute_control(obs, info) - control_time = time.perf_counter() - t_start + control_time = time.perf_counter() - t_loop obs, reward, terminated, truncated, info = env.step(action) # Update the controller internal state and models. - t_start = time.perf_counter() + t_callback = time.perf_counter() controller_finished = controller.step_callback( action, obs, reward, terminated, truncated, info ) - control_time += time.perf_counter() - t_start - if (exc := control_time - 1 / config.env.freq) > 0: + if (exc := time.perf_counter() - t_callback + control_time - 1 / config.env.freq) > 0: logger.warning(f"Controller execution time exceeded loop frequency by {exc:.3f}s.") # Add up reward, collisions if terminated or truncated or controller_finished: