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

Improve custom cameras support in MujocoVisualizer and MujocoVideoRecorder #206

Merged
merged 8 commits into from
Jul 15, 2024

Conversation

diegoferigo
Copy link
Member

@diegoferigo diegoferigo commented Jul 12, 2024

  • The MujocoVisualizer can now be opened with a configuration1 that initializes the camera towards a specific target. Then, the user is free to roam around interactively.
  • Users can now create more generic custom cameras from an extended set of parameters2.
  • The jaxsim.mujoco.RodModelToMjcf.convert function now accepts also MujocoCamera objects of a sequence of such objects, removing the need to serialize them to dictionary. However, for the most generic camera support, the method still accepts a plain dictionary or list of dictionaries.
  • The default track camera of the MujocoVideoRecorder is now more explicit as it is defined as default argument.

I found interesting the approach used to specify the initial viewpoint of the interactive viewer. It seemed to me much easier to setup than the parameters necessary to create a custom camera. We might think to understand what is the mapping logic between them, and provide a new MujocoCamera.build_from_target_view helper.

I eventually found the time to also implement this approach. Now having the recorder taking exactly the same image that is shown by default in the interactive viewer should be straightforward. Furthermore, we can now use the interactive viewer to find the desired view, and then use the resulting parameters in the recorder.

with viz.open(azimut=-180, distance=5, elevation=-30) as viewer:

    with viewer.lock():
        ...

    viz.sync(viewer=viewer)

    while viewer.is_running():
        time.sleep(0.500)
mjcf_string, assets = jaxsim.mujoco.RodModelToMjcf().convert(
    rod_model=model.built_from,
    heightmap=True,
    heightmap_samples_xy=(51, 51),
    cameras=jaxsim.mujoco.loaders.MujocoCamera.build(
        name="recorder_cam", mode="fixed", fovy="60", pos="0 0 10.0", quat="1 0 0 0"
    ),
)

[...]

recorder.record_frame(camera_name="recorder_cam")
mjcf_string, assets = jaxsim.mujoco.RodModelToMjcf().convert(
    rod_model=model.built_from,
    heightmap=True,
    heightmap_samples_xy=(51, 51),
    cameras=jaxsim.mujoco.loaders.MujocoCamera.build_from_target_view(
        camera_name="recorder_cam",
        lookat=jnp.zeros(3),
        distance=5,
        azimut=-180,
        elevation=-30,
        degrees=True,
    )
)

[...]

recorder.record_frame(camera_name="recorder_cam")

📚 Documentation preview 📚: https://jaxsim--206.org.readthedocs.build//206/

Footnotes

  1. https://mujoco.readthedocs.io/en/stable/XMLreference.html#visual-global

  2. https://mujoco.readthedocs.io/en/stable/XMLreference.html#body-camera

@diegoferigo diegoferigo self-assigned this Jul 12, 2024
@diegoferigo diegoferigo requested a review from flferretti as a code owner July 12, 2024 09:43
@diegoferigo diegoferigo force-pushed the update_cameras_in_recorder_and_interactive_viewer branch from d5744ad to 07094fd Compare July 12, 2024 10:11
Copy link
Collaborator

@flferretti flferretti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I left some comments

src/jaxsim/mujoco/loaders.py Show resolved Hide resolved
src/jaxsim/mujoco/loaders.py Show resolved Hide resolved
src/jaxsim/mujoco/loaders.py Outdated Show resolved Hide resolved
src/jaxsim/mujoco/loaders.py Show resolved Hide resolved
@diegoferigo diegoferigo force-pushed the update_cameras_in_recorder_and_interactive_viewer branch 3 times, most recently from 6b86a15 to f0e6f0c Compare July 15, 2024 08:43
@diegoferigo diegoferigo force-pushed the update_cameras_in_recorder_and_interactive_viewer branch from f0e6f0c to b25c338 Compare July 15, 2024 10:36
@diegoferigo
Copy link
Member Author

I spotted a bug in the computation of camera parameters from the desired view. Solved in https://github.com/ami-iit/jaxsim/compare/f0e6f0c1b075e664cfcbc1236729ba6035594d09..b25c33837794a796eda85e1121f6327b379e47c8.

@diegoferigo diegoferigo merged commit 13f4d6a into main Jul 15, 2024
24 checks passed
@diegoferigo diegoferigo deleted the update_cameras_in_recorder_and_interactive_viewer branch July 15, 2024 11:20
@@ -5,7 +5,7 @@ dependencies:
# ===========================
# Dependencies from setup.cfg
# ===========================
- python=3.11
- python >= 3.12.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just a maintenance dependecy bump. Since readthedocs built successfully, I thought why not updating to the latest python version. Did you have any reason to stay one version behind?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's okay to update the default Python version used in the build environment, I was just wondering if it was a constraint for scipy

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope no reason. I was just passing through the yaml file and I saw this pinning that could have been updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants