Skip to content

Best practice to reduce real-time latency when syncing control loop with MuJoCo simulation #2578

Discussion options

You must be logged in to vote

I ran into a similar issue while simulating a custom bipedal robot with a 1kHz control loop. Here are a few things that helped me reduce latency significantly:

I switched from mj_step() to using mj_step1() and mj_step2() in a split-thread setup. That allowed us to send controls and read sensors with finer control over the timing. Basically:

# Thread 1: Physics
while running:
    with lock:
        mj_step1(model, data)
    do_other_stuff()
    with lock:
        mj_step2(model, data)

# Thread 2: Control
while running:
    with lock:
        update_ctrl(data)
        read_sensors(data)
    time.sleep(0.001)

This way, physics and control run in parallel but synced safely via locking. Huge d…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@yuvaltassa
Comment options

Answer selected by notestechme
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants