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

Raise exception if root link is missing in URDF #28

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lorycontixd
Copy link

When no link named 'root' is present in the urdf loaded by mujoco, the following exception is automatically raised:

Traceback (most recent call last):
  File "/home/lconti-iit.local/Documents/elements/element_lower-leg-morphology-optimization/src/passive_walker/CMDWalker/minimal_sim.py", line 52, in <module>
    mujoco_instance.load_model(
  File "/home/lconti-iit.local/Documents/ami-forks/comodo/src/comodo/mujocoSimulator/mujocoSimulator.py", line 59, in load_model
    mujoco_xml = robot_model.get_mujoco_model(floor_opts=floor_opts, save_mjc_xml=False)
  File "/home/lconti-iit.local/Documents/ami-forks/comodo/src/comodo/robotModel/robotModel.py", line 367, in get_mujoco_model
    mujoco_model = mujoco.MjModel.from_xml_string(urdf_string)
ValueError: XML Error: URDF joint parent or child missing
Element 'joint', line 21

I think this error is missleading as it points towards a missing joint instead of a missing root link.

Therefore, I think it'd be best to search for a link named root as the model loads, and raise a custom exception if this link is not found.

@lorycontixd lorycontixd self-assigned this Dec 11, 2024
@lorycontixd
Copy link
Author

Resolving lines:

has_root_link = "root" in [l.attrib['name'] for l in root.findall(".//link")]
if not has_root_link:
    raise ValueError("The URDF file must have a link named 'root'")

@lorycontixd
Copy link
Author

Reference the second commit, not the first one

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.

1 participant