Skip to content

Synchronous mode: fixed_delta_seconds ignored mid-session #174

@LMU-EMaeding

Description

@LMU-EMaeding

Hi everyone,

I’m encountering a critical issue that prevents us from running a study in synchronous mode with the Python API. Although CARLA initially respects the fixed_delta_seconds setting (e.g. 0.05 s for 20 FPS), after a few minutes it stops waiting for the Python tick and runs uncapped— even though synchronous mode remains enabled and external frame limiters (e.g. RTSS) have no effect.

Helper Method:

    @staticmethod
    def set_simulation_mode(client, synchronous_mode=True, tm_synchronous_mode=True, tm_port=8000, fixed_delta_seconds=0.05):
        # Setting simulation mode
        settings = client.get_world().get_settings()
        if synchronous_mode:
            settings.synchronous_mode = True
            settings.fixed_delta_seconds = fixed_delta_seconds
        else:
            settings.synchronous_mode = False
            settings.fixed_delta_seconds = fixed_delta_seconds
        client.get_world().apply_settings(settings)

        # Setting Traffic Manager parameters
        traffic_manager = client.get_trafficmanager(tm_port)
        traffic_manager.set_synchronous_mode(tm_synchronous_mode)

Ticker Thread:

class WorldTicker(threading.Thread):
    def __init__(self, world_obj, client_obj, config_path, tick_interval=0.05):
        super().__init__()
        self.world_obj = world_obj
        self.client_obj = client_obj
        self.config_path = config_path
        self.tick_interval = tick_interval
        self._stop_event = threading.Event()
        self.daemon = True
        logger.debug(f"WorldTicker thread __init__ called. Interval: {self.tick_interval}")

    def run(self):
        logger.info("Global WorldTicker thread started.")
        try:
            logger.critical("[WorldTicker] RUN METHOD ENTERED")
            while not self._stop_event.is_set():
                if self.world_obj:
                    custom_world_tick(self.world_obj, self.client_obj, self.config_path,
                                      current_block_idx_for_tick_global, reason="Global Ticker")
                    
                time.sleep(self.tick_interval) 
        except Exception as e:
            logger.error(f"Exception in WorldTicker thread: {e}", exc_info=True)
        finally:
            logger.info("Global WorldTicker thread finished.")

    def stop(self):
        logger.info("Stopping Global WorldTicker thread.")
        self._stop_event.set()

Observed Behavior:

  • Initial phase: Frame times correctly(?) hover around 50 ms (20 Hz), and CARLA stalls as expected to maintain the fixed delta.
  • After some minutes: The engine abruptly stops waiting for the next Python tick? Frame times now no longer fluctuate and can drop below the target which results in the CARLA Simulation to advance faster than real time. Python script still ticks consistently as before.

Any insights on why fixed_delta_seconds would stop being enforced mid-session, or how to reliably lock the tick rate?

Thanks in advance for any help!

Image

Image

Town06_Opt_MOD_4-Windows-10-10.11.15.ue4stats.txt
Town06_Opt_MOD_4-Windows-10-10.16.57.ue4stats.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions