Skip to content

Commit

Permalink
Address review
Browse files Browse the repository at this point in the history
Co-authored-by: Filippo Luca Ferretti <[email protected]>
  • Loading branch information
diegoferigo and flferretti committed Feb 12, 2024
1 parent 5561c7c commit 4dcd4a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
11 changes: 6 additions & 5 deletions src/jaxsim/mujoco/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
import pathlib
import sys
import time

import numpy as np
Expand Down Expand Up @@ -105,7 +106,7 @@
if not pathlib.Path(args.description).is_file():
msg = f"The URDF/SDF file '{args.description}' does not exist."
parser.error(msg)
exit(1)
sys.exit(1)

# Expand the path of the output MJCF file if not absolute.
if args.export is not None:
Expand All @@ -122,7 +123,7 @@
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))
exit(1)
sys.exit(1)

# ================================================
# Load the URDF/SDF file and produce a MJCF string
Expand All @@ -141,7 +142,7 @@
case _:
msg = f"The file extension '{args.description.suffix}' is not supported."
parser.error(msg)
exit(1)
sys.exit(1)

if args.print:
print(mjcf_string, flush=True)
Expand All @@ -151,7 +152,7 @@
# ========================================

if args.export is not None:
with open(args.export, "w+") as file:
with open(args.export, "w+", encoding="utf-8") as file:
file.write(mjcf_string)

# =======================================
Expand Down Expand Up @@ -188,4 +189,4 @@
# Exit the program with success
# =============================

exit(0)
sys.exit(0)
17 changes: 6 additions & 11 deletions src/jaxsim/mujoco/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def convert(
joints_dict = {j.name: j for j in rod_model.joints()}

# Convert all the joints not considered to fixed joints.
for joint_name in set([j.name for j in rod_model.joints()]) - considered_joints:
for joint_name in set(j.name for j in rod_model.joints()) - considered_joints:
joints_dict[joint_name].type = "fixed"

# Convert the ROD model to URDF.
Expand Down Expand Up @@ -237,10 +237,8 @@ def convert(

# Get the joint names.
mj_joint_names = set(
[
mj.mj_id2name(mj_model, mj.mjtObj.mjOBJ_JOINT, idx)
for idx in range(mj_model.njnt)
]
mj.mj_id2name(mj_model, mj.mjtObj.mjOBJ_JOINT, idx)
for idx in range(mj_model.njnt)
)

# Check that the Mujoco model only has the considered joints.
Expand All @@ -267,8 +265,7 @@ def convert(
root: ET._Element = tree.getroot()

# Find the <mujoco> element (might be the root itself).
mujoco_elements = [e for e in root.iter("mujoco")]
mujoco_element: ET._Element = mujoco_elements[0]
mujoco_element: ET._Element = list(root.iter("mujoco"))[0]

# --------------
# Add the motors
Expand Down Expand Up @@ -403,10 +400,8 @@ def convert(
# <worldbody> elements inside <mujoco>.
for wb in mujoco_element.findall(".//worldbody"):
if all(
[
wb.find(f".//joint[@name='{j}']") is not None
for j in considered_joints
]
wb.find(f".//joint[@name='{j}']") is not None
for j in considered_joints
):
worldbody_element = wb
break
Expand Down

0 comments on commit 4dcd4a7

Please sign in to comment.