UM-ARM-Lab / pytorch_kinematics

Robot kinematics implemented in pytorch
MIT License
447 stars 42 forks source link

The method of processing joint of "slide" type ? #9

Closed c4cld closed 1 year ago

c4cld commented 2 years ago

I try to use build_chain_from_mjcf function to read 'roboschool/mujoco_assets/hopper.xml'.

But I got error information as follows:

 File "/root/aliyun/mymirror/test.py", line 121, in test
    chain = pk.build_chain_from_mjcf(open(xml_path).read())
  File "/root/aliyun/pytorch_kinematics/pytorch_kinematics/mjcf.py", line 81, in build_chain_from_mjcf
    _build_chain_recurse(root_frame, root_body)
  File "/root/aliyun/pytorch_kinematics/pytorch_kinematics/mjcf.py", line 48, in _build_chain_recurse
    cur_frame, cur_base = add_composite_joint(root_frame, root_body.joint, base)
  File "/root/aliyun/pytorch_kinematics/pytorch_kinematics/mjcf.py", line 39, in add_composite_joint
    joint=joint_to_joint(joints[0], base)),)
  File "/root/aliyun/pytorch_kinematics/pytorch_kinematics/mjcf.py", line 32, in joint_to_joint
    joint_type=JOINT_TYPE_MAP[joint.type],
KeyError: 'slide'

In "/root/aliyun/pytorch_kinematics/pytorch_kinematics/mjcf.py", I notice that 'JOINT_TYPE_MAP' is defined as a dictionary {'hinge': 'revolute'} at the beginning of mjcf.py. So 'JOINT_TYPE_MAP' can only receive joint of 'hinge' type.

But in 'roboschool/mujoco_assets/hopper.xml' in following figure, there are some joints of "slide" type. 1652669456(1)

So how to process joint of "slide" type?

c4cld commented 2 years ago

@LemonPi @powertj Do you have any advice? Thanks for your help in advance ^_^

johannespitz commented 2 years ago

Should probably be enough to change this line https://github.com/UM-ARM-Lab/pytorch_kinematics/blob/6d2e813b3c46c2990f701f33909aa394f0298798/pytorch_kinematics/mjcf.py#L6 to:

JOINT_TYPE_MAP = {"hinge": "revolute", "slide": "prismatic"}

Though, I decided to convert my mujoco files to urdf using mjcf2urdf.

LemonPi commented 1 year ago

We are now using dm_control's mjcf parsing library so this should be resolved

LemonPi commented 1 year ago

Actually this is still a problem my bad; will be resolving this and adding a test for it. For now please consider the mjcf2urdf as johannespitz suggested

LemonPi commented 1 year ago

I could only ever find "slide" joints defined between the base link and the world (instead of between links), which are ignored by PK. e41f519 should fix their loading