Aligning physics stepping with real time?

Hello - I have been using Isaac Sim for few months for simulated teleoperation through ROS2 with haptic feedback. For this I would like to maintain a stable ~200 Hz publishing rate for the publishing and subscribing of the robot joint states. For my controller I am using an Action Graph with a On Physics Step trigger. This is because my machine is not capable of rendering full frames at the desired frequency however every physics step can run extremely quickly at sub ms rates. After scouring the NVIDIA forums it seems the most pertinent parameters for timestepping are numPhysicsSteps and a large number of frame rate parameters. I have set numPhysicsSteps=200 and minFrameRate=1 as stable graphics rendering is secondary to my goal. With these settings I am able to achieve stable frame-rates of 60-100Hz however the time-stepping is extremely inconsistent. In particular I notice that the time between physics steps varies from 0.5-20ms which is unmanageable for a real time haptic controller. I am trying to avoid these latency spikes and make sure that physics steps always run every ~5ms. I have tried getting this to work in extension mode and standalone mode using the asyncio library to no avail. It seems I have tried every combination of settings and still cannot get this to work. Moreover I have tried to set FixedTimeStepping to False to at least get the physics stepping aligned with real time and still get constant physics steps. Playing around with AsyncRendering and AsynchronousPhysics also seem to have negligible effect on this. I have included an image of the timing of my physics loop where you can see sudden latency spikes and general instability. I have also included an image of some of the settings I have been playing with in my custom extension. I am working with Isaac Sim 4.5 on Ubuntu 22. My machine has an Ada 4000 GPU with an 13th Gen Intel i9 processor.

I have struggled with this for a couple months now and would appreciate any help with this issue from the community or developers. I understand this is an unorthodox request and hope that this desired behavior is even achievable with Isaac Sim. Thank you!

Have you tried simplifying the scene to see if the inconsistency is related to the physics engine under load?

These measurements are for the scene in initial conditions (nothing is moving), so I don’t know why this would have an effect. I am wondering if there is any way to decouple the graphics and physics loops and have physics run on a high priority thread. To the best of my ability I have tried implementing this as a standalone script using asyncio and am getting some improvements. I am not that familiar with using asyncio so I am looking for suggestions or improvements. Again, my main goal is to get physics steps more or less consistent with real world time (~5ms).

import argparse
import asyncio
import sys
import time
from isaacsim import SimulationApp
import rclpy

# Simulation configuration
CONFIG = {
    "width": 1280,
    "height": 720,
    "sync_loads": True,
    "headless": False,
    "renderer": "RaytracedLighting",
    #"extra_args": ["--/app/useFabricSceneDelegate=1"]
}
PHYSICS_DT = 1/200.  # 200 Hz

# Command-line arguments
parser = argparse.ArgumentParser("USD Loader")
parser.add_argument("--usd_path", type=str, required=True)
parser.add_argument("--headless", action="store_true", default=False)
parser.add_argument("--test", action="store_true", default=False)
args, unknown = parser.parse_known_args()

CONFIG["headless"] = args.headless
simulation_app = SimulationApp(launch_config=CONFIG)

import carb
import omni
from isaacsim.storage.native import is_file
from isaacsim.core.utils.stage import is_stage_loading
#from isaacsim.core.api import SimulationContext
from isaacsim.core.api import World
import omni.graph.core as og


# Load USD stage
if not is_file(args.usd_path):
    carb.log_error(f"USD path invalid: {args.usd_path}")
    simulation_app.close()
    sys.exit()

carb.settings.get_settings().set_bool("/app/asyncRendering", True)
carb.settings.get_settings().set_bool("/app/player/useFixedTimeStepping", False)
carb.settings.get_settings().set_bool("/physics/updateToUsd", False)
carb.settings.get_settings().set_bool("/physics/updateVelocitiesToUsd", False)

omni.usd.get_context().open_stage(args.usd_path)
simulation_app.update()
simulation_app.update()

print("Loading stage...")
while is_stage_loading():
    simulation_app.update()
print("Loading Complete")
omni.timeline.get_timeline_interface().play()

# Simulation context setup
world = World(physics_dt=PHYSICS_DT)
world.initialize_physics()
world.play()

async def physics_loop():
    next_step = asyncio.get_event_loop().time()
    last_physics_time = time.perf_counter()
    while simulation_app.is_running():
        this_physics_time = time.perf_counter()
        print("dt_physics: ", this_physics_time - last_physics_time)
        last_physics_time = this_physics_time
        world.step(render=False)
        next_step += PHYSICS_DT
        await asyncio.sleep(max(0, next_step - asyncio.get_event_loop().time()))

async def render_loop():
    last_graphics_time = time.perf_counter()
    while simulation_app.is_running():
        # this_graphics_time = time.perf_counter()
        # print("dt_graphics: ", this_graphics_time - last_graphics_time )
        # last_graphics_time = this_graphics_time
        await world.render_async()  # explicitly render asynchronously
        await asyncio.sleep(0.)  # limit to ~60Hz

async def main():
    physics = asyncio.create_task(physics_loop())
    render = asyncio.create_task(render_loop())
    await asyncio.gather(physics, render)

simulation_app.run_coroutine(main(), run_until_complete=False)

while simulation_app.is_running():
    simulation_app.update()

world.stop()
simulation_app.close()

Hi @caligula ,

Thank you for the detailed investigation in post #3. I wanted to follow up with some clarification on why the asyncio approach doesn’t work and what the recommended solution is.

Why asyncio.sleep() Cannot Provide Real-Time Timing

The core issue is how Kit’s asyncio event loop is implemented. From the source (omni.kit.async_engine):

“It runs asyncio EventLoop every update for one iteration (all scheduled tasks).”

This means asyncio.sleep(0.005) doesn’t sleep for 5ms in wall-clock time – it means “resume at the next event loop iteration after 5ms has elapsed.” Since the event loop only ticks once per IApp.update() call, your physics timing becomes coupled to the rendering frame rate. If rendering takes 20ms, your physics coroutine won’t resume until that frame completes.

The Solution: OS Threads + time.sleep() with Busy-Wait

For real-time control applications like haptic feedback, you need to use OS-level threading with time.sleep() (which uses the kernel’s CLOCK_MONOTONIC), not asyncio:

import threading
import time
import carb
from isaacsim import SimulationApp
from isaacsim.core.api import World

# Disable Kit's automatic physics stepping
carb.settings.get_settings().set_bool("/app/player/playSimulations", False)

# Disable USD write-back for performance (you already have these)
carb.settings.get_settings().set_bool("/physics/updateToUsd", False)
carb.settings.get_settings().set_bool("/physics/updateVelocitiesToUsd", False)

PHYSICS_DT = 1/200.0  # 200 Hz

def physics_thread_func(world, stop_event):
    next_step_time = time.perf_counter()
    
    while not stop_event.is_set():
        # Step physics
        world._physics_context._step(current_time=world.current_time)
        
        # Schedule next step
        next_step_time += PHYSICS_DT
        
        # Coarse sleep (leave 0.5ms margin for busy-wait)
        sleep_time = next_step_time - time.perf_counter() - 0.0005
        if sleep_time > 0:
            time.sleep(sleep_time)
        
        # Busy-wait for final sub-millisecond precision
        while time.perf_counter() < next_step_time:
            pass

# Start physics in separate thread
stop_event = threading.Event()
physics_thread = threading.Thread(
    target=physics_thread_func, 
    args=(world, stop_event),
    daemon=True
)
physics_thread.start()

# Main thread handles rendering at whatever rate the GPU can manage
while simulation_app.is_running():
    simulation_app.update()

Empirical Results

We validated this approach on Isaac Sim 6.0.1 (headless, aarch64). Over a 30-second test:

Approach In Range (4-6ms) Max Spike Verdict
Threading + busy-wait 99.83% 14.8 ms Suitable for haptics
Asyncio + asyncio.sleep() 12.6% 90.8 ms Unsuitable

The threading approach achieves stable 200 Hz with only ~0.1% outliers (roughly one spike per 10 seconds).

For Strict 100% Compliance

The remaining ~0.1% of spikes are caused by Linux kernel scheduling (CFS preemption). To eliminate them entirely, you would need real-time scheduling:

# Option 1: Run with sudo
sudo python your_script.py

# Option 2: Set capabilities (once)
sudo setcap cap_sys_nice+ep /path/to/python3

# Then in your physics thread:
import os
os.sched_setscheduler(0, os.SCHED_FIFO, os.sched_param(80))

This is a Linux kernel limitation, not an Isaac Sim limitation. For most haptic applications, the 99.8%+ success rate should be sufficient – the occasional 10-15ms spike occurs roughly once per 10 seconds and may be imperceptible.

Summary

  1. Don’t use asyncio for real-time physics – Kit’s event loop is coupled to rendering
  2. Use threading.Thread + time.sleep() with busy-wait for sub-ms precision
  3. Set /app/player/playSimulations=False to disable Kit’s automatic physics stepping
  4. For strict real-time: Use SCHED_FIFO (requires elevated privileges)

I’m closing this topic as the question has been addressed. If you have follow-up questions or this solution doesn’t work for your use case, please open a new topic and reference this one.