Skip to content

Commit

Permalink
Make camera setting more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
flferretti committed Apr 3, 2024
1 parent 82015ab commit 0599808
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/jaxsim/mujoco/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def convert(
# Add user-defined camera
cameras = cameras if cameras is not None else {}
for camera in cameras if isinstance(cameras, list) else [cameras]:
_ = ET.SubElement(worldbody_element, "camera", **camera)
_ = ET.SubElement(worldbody_element, "camera", **_Camera(**camera))

# ------------------------------------------------
# Add a light following the CoM of the first link
Expand Down Expand Up @@ -593,3 +593,26 @@ def convert(
heightmap=heightmap,
cameras=cameras,
)

class _Camera:
def __init__(self, name: str, mode: str, pos: str, xyaxes: str, fovy: str):
self.name = name
self.mode = mode
self.pos = pos
self.xyaxes = xyaxes
self.fovy = fovy

def __iter__(self):
if not all(key in camera for key in self.__annotations__.keys()):
raise ValueError("Missing keys in camera dictionary")

if not all(isinstance(self.key, str) for key in self.__annotations__.keys()):
raise ValueError("Values must be strings")

if len(self.pos.split()) != 3:
raise ValueError("pos must have three values separated by space")

if len(self.xyaxes.split()) != 6:
raise ValueError("xyaxes must have six values separated by space")

return tuple(self.key for key in self.__annotations__.keys())

0 comments on commit 0599808

Please sign in to comment.