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

Allow building a MJCF without user-defined cameras #216

Merged
merged 1 commit into from
Jul 26, 2024
Merged

Conversation

flferretti
Copy link
Collaborator

@flferretti flferretti commented Jul 25, 2024

This PR fixes a bug for which the MJCF could not be built without passing a user-defined camera.

Testing Script

import rod
from rod.builder.primitives import SphereBuilder

from jaxsim.mujoco import UrdfToMjcf

model_sdf_string = rod.Sdf(
    version="1.7",
    model=SphereBuilder(radius=0.10, mass=1.0, name="sphere")
    .build_model()
    .add_link()
    .add_inertial()
    .add_visual()
    .add_collision()
    .build(),
).serialize(pretty=True)

mjcf_string, assets = UrdfToMjcf.convert(
    urdf=model_sdf_string,
)

Error Log

File ~/jaxsim/src/jaxsim/mujoco/loaders.py:496, in RodModelToMjcf.convert(rod_model, considered_joints, plane_normal, heightmap, heightmap_samples_xy, cameras)
    490 # Add user-defined camera.
    491 for camera in cameras if isinstance(cameras, Sequence) else [cameras]:
    493     mj_camera = (
    494         camera
    495         if isinstance(camera, MujocoCamera)
--> 496         else MujocoCamera.build(**camera)
    497     )
    499     _ = ET.SubElement(worldbody_element, "camera", mj_camera.asdict())
    501 # ------------------------------------------------
    502 # Add a light following the  CoM of the first link
    503 # ------------------------------------------------

TypeError: jaxsim.mujoco.loaders.MujocoCamera.build() argument after ** must be a mapping, not NoneType


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

@flferretti flferretti self-assigned this Jul 25, 2024
@flferretti flferretti requested a review from diegoferigo as a code owner July 25, 2024 07:58
@diegoferigo
Copy link
Member

This PR is implementing a workaround when no camera is specified, but I think that the root problem is elsewhere. When I updated the cameras argument, I just realized that I didn't align also the UrdfToMjcf.convert method. Can you please update this PR such that in that method cameras=() instead of =None by default?

@flferretti
Copy link
Collaborator Author

You're right! Fixed with rebase

Copy link
Member

@diegoferigo diegoferigo left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks for the fix.

@flferretti flferretti merged commit 14b401c into main Jul 26, 2024
24 checks passed
@flferretti flferretti deleted the patch-camera branch July 26, 2024 07:27
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