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

Add jaxsim.mujoco package with resources to render a scene using the Mujoco viewer #83

Merged
merged 8 commits into from
Feb 12, 2024

Conversation

diegoferigo
Copy link
Member

@diegoferigo diegoferigo commented Feb 9, 2024

This PR introduces a new jaxsim.mujoco package for visualizing a simulated trajectory in the Mujoco viewer. The implementation uses the asynchronous (non-blocking) passive viewer, and it allows to both open a window and/or record a video -- assuming a proper configuration to exploit EGL on headless machines.

So far, only kinematics is visualized. A list of missing features that might be implemented in future PRs is the following:

  • Populate the scene with additional shapes through the user_scn member.
  • In this way, visualize the active contacts and active contact forces.
  • Allow to draw lines e.g. CoM trajectory.

Implementation details:

  • The implementation is based on ami/rod. We use this library to pre-process and validate the input URDF/SDF. Passing through sdformat has the advantage to fill data that might not be present in the original model description, simplifying the parsing later done by the new jaxsim.mujoco resources.
  • We remove the non-controlled joint by lumping their parent/child links together (this is actually done by sdformat).
  • Only the visual shapes are visualized. The collision shapes are rendered with alpha=0.

Therefore, we perform: URDF/SDF → in-memory ROD model → export to URDF → load into the Mujoco URDF parser → export the XML → postprocess the XML with additional elements.

# Convert URDF/SDF to MJCF
python -m jaxsim.mujoco --description /path/to/model.{urdf|sdf} --export /path/to/out.xml

# Visualize URDF/SDF
python -m jaxsim.mujoco --description /path/to/model.{urdf|sdf} --visualize

Full commandline:

jaxsim on  feature/mujoco_passive_viewer via 🐍 v3.11.7 🅒 /jaxsim
❯ python -m jaxsim.mujoco -h
usage: jaxsim.mujoco [-h] -d INPUT_FILE [-m NAME] [-e MJCF_FILE] [-f] [-p] [-v] [-b x y z] [-q w x y z]

Process URDF and SDF files for Mujoco usage.

options:
  -h, --help            show this help message and exit
  -d INPUT_FILE, --description INPUT_FILE
                        Path to the URDF or SDF file.
  -m NAME, --model-name NAME
                        The target model of a SDF description if multiple models exists.
  -e MJCF_FILE, --export MJCF_FILE
                        Path to the exported MJCF file.
  -f, --force           Override the output MJCF file if it already exists (default: False).
  -p, --print           Print in the stdout the exported MJCF string (default: False).
  -v, --visualize       Visualize the description in the Mujoco viewer (default: False).
  -b x y z, --base-position x y z
                        Override the base position (supports only floating-base models).
  -q w x y z, --base-quaternion w x y z
                        Override the base quaternion (supports only floating-base models).

For something similar to a tutorial on how to visualize a model, refer to the __main__ file that includes a handy command-line.

Partially addresses #11.


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

@diegoferigo diegoferigo self-assigned this Feb 9, 2024
@diegoferigo diegoferigo marked this pull request as ready for review February 12, 2024 08:56
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.

LGTM, thanks! I just wrote some minor comments

setup.cfg Outdated Show resolved Hide resolved
src/jaxsim/mujoco/loaders.py Outdated Show resolved Hide resolved
src/jaxsim/mujoco/loaders.py Outdated Show resolved Hide resolved
src/jaxsim/mujoco/loaders.py Outdated Show resolved Hide resolved
src/jaxsim/mujoco/loaders.py Outdated Show resolved Hide resolved
src/jaxsim/mujoco/__main__.py Outdated Show resolved Hide resolved
src/jaxsim/mujoco/__main__.py Outdated Show resolved Hide resolved
src/jaxsim/mujoco/__main__.py Show resolved Hide resolved
src/jaxsim/mujoco/__main__.py Outdated Show resolved Hide resolved
src/jaxsim/mujoco/__main__.py Outdated Show resolved Hide resolved
diegoferigo and others added 2 commits February 12, 2024 11:00
Co-authored-by: Filippo Luca Ferretti <filippo.ferretti@iit.it>
@diegoferigo diegoferigo merged commit 550fc44 into ami-iit:main Feb 12, 2024
11 checks passed
@diegoferigo diegoferigo deleted the feature/mujoco_passive_viewer branch February 12, 2024 11:21
@diegoferigo
Copy link
Member Author

As a reference, here the result of the visualization of the ergoCubSN001:

export GAZEBO_MODEL_PATH=/home/dferigo/git/ergocub-software/urdf
python -m jaxsim.mujoco -d ~/git/ergocub-software/urdf/ergoCub/robots/ergoCubSN001/model.urdf -v -b 0 0 1

image

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.

None yet

3 participants