Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MuJoCo viewer doesn't allow to change parameters in the "Visualization" panel when launched in passive mode #2158

Open
2 tasks done
stepanove opened this issue Oct 20, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@stepanove
Copy link

stepanove commented Oct 20, 2024

Intro

Hi!

I'm just a robotics and software development enthusiast experimenting with MuJoCo.

My setup

MuJoCo 3.0.0-3.2.4, Python 3.12, Debian 12 (docker image "python:3.12-bookworm")

What's happening? What did you expect?

I noticed a strange behavior of the MuJoCo viewer in passive mode. I'm experimenting with an example from the docs. Initially I faced the problem that I can't change the scale of the model elements (joints, contact forces, etc). When I adjust the values in the Visualization/Scale panel, it changes for a moment and then resets. But it looks like all the parameters in the "Visualization" panel are affected. If I launch the viewer in active mode, it works as expected. I tried a few versions down to 3.0.0, the behavior the same.

passive_viewer_test.mp4

Steps for reproduction

  1. Run the code below.
  2. Try to change some parameters in the "Visualization" panel.

Minimal model for reproduction

No response

Code required for reproduction

import time
import mujoco
import mujoco.viewer


xml = """
<mujoco>
  <worldbody>
    <light name="top" pos="0 0 1"/>
    <body name="box_and_sphere" euler="0 0 -30">
      <joint name="swing" type="hinge" axis="1 -1 0" pos="-.2 -.2 -.2"/>
      <geom name="red_box" type="box" size=".2 .2 .2" rgba="1 0 0 1"/>
      <geom name="green_sphere" pos=".2 .2 .2" size=".1" rgba="0 1 0 1"/>
    </body>
  </worldbody>
</mujoco>
"""
model = mujoco.MjModel.from_xml_string(xml)
data = mujoco.MjData(model)


with mujoco.viewer.launch_passive(model, data) as viewer:
  # Close the viewer automatically after 30 wall-seconds.
  start = time.time()
  while viewer.is_running() and time.time() - start < 30:
    step_start = time.time()

    # mj_step can be replaced with code that also evaluates
    # a policy and applies a control signal before stepping the physics.
    mujoco.mj_step(model, data)

    # Example modification of a viewer option: toggle contact points every two seconds.
    with viewer.lock():
      viewer.opt.flags[mujoco.mjtVisFlag.mjVIS_CONTACTPOINT] = int(data.time % 2)

    # Pick up changes to the physics state, apply perturbations, update options from GUI.
    viewer.sync()

    # Rudimentary time keeping, will drift relative to wall clock.
    time_until_next_step = model.opt.timestep - (time.time() - step_start)
    if time_until_next_step > 0:
      time.sleep(time_until_next_step)

Confirmations

@stepanove stepanove added the bug Something isn't working label Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants