-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into flferretti-patch-1
- Loading branch information
Showing
11 changed files
with
1,286 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
FROM mcr.microsoft.com/devcontainers/base:ubuntu | ||
COPY environment.yml /opt/environment.yml | ||
|
||
# Enable by default the conda environment for all users. | ||
# The prefix is the one used by the micromamba feature. | ||
ENV CONDA_PREFIX_JAXSIM=/opt/conda/envs/jaxsim | ||
RUN echo 'function activate_conda() {' >> /etc/bash.bashrc &&\ | ||
echo ' eval "$(micromamba shell hook -s bash)"' >> /etc/bash.bashrc &&\ | ||
echo ' micromamba activate ${CONDA_PREFIX_JAXSIM-$CONDA_PREFIX}' >> /etc/bash.bashrc &&\ | ||
echo '}' >> /etc/bash.bashrc &&\ | ||
echo '[[ -x $(which micromamba) && -d ${CONDA_PREFIX_JAXSIM-$CONDA_PREFIX} ]] && activate_conda' >> /etc/bash.bashrc &&\ | ||
echo '[[ -x $(which micromamba) && ! -x $(which mamba) ]] && alias mamba="$(which micromamba)"' >> /etc/bash.bashrc &&\ | ||
echo '[[ -x $(which micromamba) && ! -x $(which conda) ]] && alias conda="$(which micromamba)"' >> /etc/bash.bashrc | ||
|
||
# Provide libGL.so.1 from the host OS | ||
RUN sudo apt-get update &&\ | ||
sudo apt-get install -y --no-install-recommends libgl1 &&\ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
# The Python extension in VSCode is not able to detect the interpreter installed with micromamba. | ||
# As documented as follows, we provide a suggestion through an environment variable. | ||
# https://code.visualstudio.com/docs/python/environments#_where-the-extension-looks-for-environments | ||
ENV WORKON_HOME=$CONDA_PREFIX_JAXSIM | ||
|
||
# Specify the workdir of the container | ||
WORKDIR /workspace/jaxsim |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the | ||
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu | ||
{ | ||
"name": "Ubuntu", | ||
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile | ||
"build": { | ||
"context": "..", | ||
"dockerfile": "Dockerfile", | ||
}, | ||
|
||
// Features to add to the dev container. More info: https://containers.dev/features. | ||
"features": { | ||
"ghcr.io/mamba-org/devcontainer-features/micromamba:1": { | ||
"envFile": "/opt/environment.yml", | ||
}, | ||
}, | ||
|
||
// Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
// "forwardPorts": [], | ||
|
||
// Use 'postCreateCommand' to run commands after the container is created. | ||
// "postCreateCommand": "uname -a", | ||
|
||
// Configure tool-specific properties. | ||
// "customizations": {}, | ||
|
||
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. | ||
// "remoteUser": "root" | ||
|
||
// VSCode extensions | ||
"extensions": [ | ||
"ms-python.python", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: jaxsim | ||
channels: | ||
- conda-forge | ||
dependencies: | ||
# Dependencies from setup.cfg | ||
- python=3.11 | ||
- coloredlogs | ||
- jax >= 0.4.13 | ||
- jaxlib | ||
- jaxlie >= 1.3.0 | ||
- jax-dataclasses >= 1.4.0 | ||
- pptree | ||
- rod | ||
# Optional dependencies from setup.cfg | ||
# [style] | ||
- black | ||
- isort | ||
# [testing] | ||
- idyntree | ||
- pytest | ||
- pytest-forked | ||
- pytest-icdiff | ||
- robot_descriptions | ||
# [viz] | ||
- mediapy | ||
- mujoco >= 3.0.0 | ||
# System dependencies to run the tests | ||
- gz-sim7 | ||
# Other packages | ||
- ipython | ||
# Documentation dependencies | ||
- cachecontrol | ||
- enum_tools | ||
- filecache | ||
- filelock | ||
- jinja2 | ||
- sphinx | ||
- sphinx-autodoc-typehints | ||
- sphinx-copybutton | ||
- sphinx_fontawesome | ||
- sphinx-jinja2-compat | ||
- sphinx-multiversion | ||
- sphinx_rtd_theme | ||
- sphinx-toolbox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .loaders import RodModelToMjcf, SdfToMjcf, UrdfToMjcf | ||
from .model import MujocoModelHelper | ||
from .visualizer import MujocoVisualizer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
import argparse | ||
import pathlib | ||
import sys | ||
import time | ||
|
||
import numpy as np | ||
|
||
from . import MujocoModelHelper, MujocoVisualizer, SdfToMjcf, UrdfToMjcf | ||
|
||
if __name__ == "__main__": | ||
|
||
parser = argparse.ArgumentParser( | ||
prog="jaxsim.mujoco", | ||
description="Process URDF and SDF files for Mujoco usage.", | ||
) | ||
|
||
parser.add_argument( | ||
"-d", | ||
"--description", | ||
required=True, | ||
metavar="INPUT_FILE", | ||
type=pathlib.Path, | ||
help="Path to the URDF or SDF file.", | ||
) | ||
|
||
parser.add_argument( | ||
"-m", | ||
"--model-name", | ||
metavar="NAME", | ||
type=str, | ||
default=None, | ||
help="The target model of a SDF description if multiple models exists.", | ||
) | ||
|
||
parser.add_argument( | ||
"-e", | ||
"--export", | ||
metavar="MJCF_FILE", | ||
type=pathlib.Path, | ||
default=None, | ||
help="Path to the exported MJCF file.", | ||
) | ||
|
||
parser.add_argument( | ||
"-f", | ||
"--force", | ||
action="store_true", | ||
default=False, | ||
help="Override the output MJCF file if it already exists (default: %(default)s).", | ||
) | ||
|
||
parser.add_argument( | ||
"-p", | ||
"--print", | ||
action="store_true", | ||
default=False, | ||
help="Print in the stdout the exported MJCF string (default: %(default)s).", | ||
) | ||
|
||
parser.add_argument( | ||
"-v", | ||
"--visualize", | ||
action="store_true", | ||
default=False, | ||
help="Visualize the description in the Mujoco viewer (default: %(default)s).", | ||
) | ||
|
||
parser.add_argument( | ||
"-b", | ||
"--base-position", | ||
metavar=("x", "y", "z"), | ||
nargs=3, | ||
type=float, | ||
default=None, | ||
help="Override the base position (supports only floating-base models).", | ||
) | ||
|
||
parser.add_argument( | ||
"-q", | ||
"--base-quaternion", | ||
metavar=("w", "x", "y", "z"), | ||
nargs=4, | ||
type=float, | ||
default=None, | ||
help="Override the base quaternion (supports only floating-base models).", | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
# ================== | ||
# Validate arguments | ||
# ================== | ||
|
||
# Expand the path of the URDF/SDF file if not absolute. | ||
if args.description is not None: | ||
args.description = ( | ||
( | ||
args.description | ||
if args.description.is_absolute() | ||
else pathlib.Path.cwd() / args.description | ||
) | ||
.expanduser() | ||
.absolute() | ||
) | ||
|
||
if not pathlib.Path(args.description).is_file(): | ||
msg = f"The URDF/SDF file '{args.description}' does not exist." | ||
parser.error(msg) | ||
sys.exit(1) | ||
|
||
# Expand the path of the output MJCF file if not absolute. | ||
if args.export is not None: | ||
args.export = ( | ||
( | ||
args.export | ||
if args.export.is_absolute() | ||
else pathlib.Path.cwd() / args.export | ||
) | ||
.expanduser() | ||
.absolute() | ||
) | ||
|
||
if pathlib.Path(args.export).is_file() and not args.force: | ||
msg = "The output file '{}' already exists, use '--force' to override." | ||
parser.error(msg.format(args.export)) | ||
sys.exit(1) | ||
|
||
# ================================================ | ||
# Load the URDF/SDF file and produce a MJCF string | ||
# ================================================ | ||
|
||
match args.description.suffix.lower()[1:]: | ||
|
||
case "urdf": | ||
mjcf_string, assets = UrdfToMjcf().convert(urdf=args.description) | ||
|
||
case "sdf": | ||
mjcf_string, assets = SdfToMjcf().convert( | ||
sdf=args.description, model_name=args.model_name | ||
) | ||
|
||
case _: | ||
msg = f"The file extension '{args.description.suffix}' is not supported." | ||
parser.error(msg) | ||
sys.exit(1) | ||
|
||
if args.print: | ||
print(mjcf_string, flush=True) | ||
|
||
# ======================================== | ||
# Write the MJCF string to the output file | ||
# ======================================== | ||
|
||
if args.export is not None: | ||
with open(args.export, "w+", encoding="utf-8") as file: | ||
file.write(mjcf_string) | ||
|
||
# ======================================= | ||
# Visualize the MJCF in the Mujoco viewer | ||
# ======================================= | ||
|
||
if args.visualize: | ||
|
||
mj_model_helper = MujocoModelHelper.build_from_xml( | ||
mjcf_description=mjcf_string, assets=assets | ||
) | ||
|
||
viz = MujocoVisualizer(model=mj_model_helper.model, data=mj_model_helper.data) | ||
|
||
with viz.open() as viewer: | ||
|
||
with viewer.lock(): | ||
if args.base_position is not None: | ||
mj_model_helper.set_base_position( | ||
position=np.array(args.base_position) | ||
) | ||
|
||
if args.base_quaternion is not None: | ||
mj_model_helper.set_base_orientation( | ||
orientation=np.array(args.base_quaternion) | ||
) | ||
|
||
viz.sync(viewer=viewer) | ||
|
||
while viewer.is_running(): | ||
time.sleep(0.500) | ||
|
||
# ============================= | ||
# Exit the program with success | ||
# ============================= | ||
|
||
sys.exit(0) |
Oops, something went wrong.