You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to add the allegro hand from mujoco-menagerie as a custom gripper. I created a simple tester, to verify the gripper model.
from robosuite.models.grippers import gripper_factory
from mujoco_py import MjSim, MjViewer
import os
# Set the gripper XML path and name
gripper_name = "AllegroLeftHand" # Use the correct gripper name
gripper_xml_path = os.path.join(suite.models.assets_root, "grippers", f"{gripper_name}.xml")
# Load the gripper
print(f"Loading gripper model: {gripper_name}")
gripper = gripper_factory(gripper_name)
# Create a simulation for the gripper
print("Creating simulation...")
sim = MjSim(gripper.mujoco_model)
viewer = MjViewer(sim)
# Run the simulation
print("Starting simulation. Use SPACEBAR to pause.")
while True:
sim.step()
viewer.render()
which results in: Loading gripper model: AllegroLeftHand Traceback (most recent call last): File "/home/johannes/Documents/master/robosuite/robosuite/scripts/tester.py", line 12, in <module> gripper = gripper_factory(gripper_name) File "/home/johannes/Documents/master/robosuite/robosuite/models/grippers/gripper_factory.py", line 32, in gripper_factory return GRIPPER_MAPPING[name](idn=idn) File "/home/johannes/Documents/master/robosuite/robosuite/models/grippers/allegro_hands.py", line 19, in __init__ super().__init__(xml_path_completion("grippers/left_hand.xml"), idn=idn) File "/home/johannes/Documents/master/robosuite/robosuite/models/grippers/gripper_model.py", line 21, in __init__ super().__init__(fname, idn=idn) File "/home/johannes/Documents/master/robosuite/robosuite/models/base.py", line 528, in __init__ super().__init__(fname) File "/home/johannes/Documents/master/robosuite/robosuite/models/base.py", line 47, in __init__ self._replace_defaults_inline(default_dic=default_classes) File "/home/johannes/Documents/master/robosuite/robosuite/models/base.py", line 254, in _replace_defaults_inline self._replace_defaults_inline(default_dic=default_dic, root=child) File "/home/johannes/Documents/master/robosuite/robosuite/models/base.py", line 254, in _replace_defaults_inline self._replace_defaults_inline(default_dic=default_dic, root=child) File "/home/johannes/Documents/master/robosuite/robosuite/models/base.py", line 254, in _replace_defaults_inline self._replace_defaults_inline(default_dic=default_dic, root=child) File "/home/johannes/Documents/master/robosuite/robosuite/models/base.py", line 247, in _replace_defaults_inline tag_attrs = default_dic[cls_name].get(root.tag, None) KeyError: 'visual'
the xml files and meshes are placed in the corresponding folders, the models are correctly working using the mujoco-viewer.
Also i created a gripper class:
Dexterous hands for the Wonik Allegro Hand.
"""
import numpy as np
from robosuite.models.grippers.gripper_model import GripperModel
from robosuite.utils.mjcf_utils import xml_path_completion
class AllegroLeftHand(GripperModel):
"""
Dexterous left hand of the Wonik Allegro Hand.
Args:
idn (int or str): Number or some other unique identification string for this gripper instance.
"""
def __init__(self, idn=0):
super().__init__(xml_path_completion("grippers/left_hand.xml"), idn=idn)
def format_action(self, action):
"""
Format the action to align with the actuator configuration of the Allegro Left Hand.
- Thumb has 4 actuated joints.
- Index, Middle, and Ring fingers each have 4 actuated joints.
"""
assert len(action) == self.dof, "Action dimension mismatch!"
return np.clip(action, self.action_range[0], self.action_range[1])
@property
def init_qpos(self):
"""
Initial joint positions for the Allegro Left Hand.
"""
return np.zeros(self.dof)
@property
def speed(self):
"""
Speed of the Allegro Left Hand actuators.
"""
return 0.15
@property
def dof(self):
"""
Degrees of freedom for the Allegro Left Hand.
- Thumb: 4 joints
- Index: 4 joints
- Middle: 4 joints
- Ring: 4 joints
"""
return 16
@property
def action_range(self):
"""
Define the valid range for actuator controls based on the XML joint limits.
"""
# Joint limits based on the XML file
return np.array([
-0.47, -0.196, -0.174, -0.227, # Ring finger
-0.47, -0.196, -0.174, -0.227, # Middle finger
-0.47, -0.196, -0.174, -0.227, # Index finger
0.263, -0.105, -0.189, -0.162 # Thumb
]), np.array([
0.47, 1.61, 1.709, 1.618, # Ring finger
0.47, 1.61, 1.709, 1.618, # Middle finger
0.47, 1.61, 1.709, 1.618, # Index finger
1.396, 1.163, 1.644, 1.719 # Thumb
])
@property
def _important_geoms(self):
"""
Define important geometries for collision and visualization.
"""
return {
"left_finger": [
"rf_proximal_collision",
"rf_medial_collision",
"rf_distal_collision",
"mf_proximal_collision",
"mf_medial_collision",
"mf_distal_collision",
"ff_proximal_collision",
"ff_medial_collision",
"ff_distal_collision",
"th_proximal_collision",
"th_medial_collision",
"th_distal_collision",
],
"left_fingerpad": [
"rf_tip_collision",
"mf_tip_collision",
"ff_tip_collision",
"th_tip_collision",
],
}
"""
Dexterous hands for the Wonik Allegro Hand (Right).
"""
class AllegroRightHand(GripperModel):
"""
Dexterous right hand of the Wonik Allegro Hand.
Args:
idn (int or str): Number or some other unique identification string for this gripper instance.
"""
def __init__(self, idn=0):
super().__init__(xml_path_completion("grippers/right_hand.xml"), idn=idn)
def format_action(self, action):
"""
Format the action to align with the actuator configuration of the Allegro Right Hand.
- Thumb has 4 actuated joints.
- Index, Middle, and Ring fingers each have 4 actuated joints.
"""
assert len(action) == self.dof, "Action dimension mismatch!"
return np.clip(action, self.action_range[0], self.action_range[1])
@property
def init_qpos(self):
"""
Initial joint positions for the Allegro Right Hand.
"""
return np.zeros(self.dof)
@property
def speed(self):
"""
Speed of the Allegro Right Hand actuators.
"""
return 0.15
@property
def dof(self):
"""
Degrees of freedom for the Allegro Right Hand.
- Thumb: 4 joints
- Index: 4 joints
- Middle: 4 joints
- Ring: 4 joints
"""
return 16
@property
def action_range(self):
"""
Define the valid range for actuator controls based on the XML joint limits.
"""
# Joint limits based on the XML file
return np.array([
-0.47, -0.196, -0.174, -0.227, # Index finger
-0.47, -0.196, -0.174, -0.227, # Middle finger
-0.47, -0.196, -0.174, -0.227, # Ring finger
0.263, -0.105, -0.189, -0.162 # Thumb
]), np.array([
0.47, 1.61, 1.709, 1.618, # Index finger
0.47, 1.61, 1.709, 1.618, # Middle finger
0.47, 1.61, 1.709, 1.618, # Ring finger
1.396, 1.163, 1.644, 1.719 # Thumb
])
@property
def _important_geoms(self):
"""
Define important geometries for collision and visualization.
"""
return {
"right_finger": [
"ff_proximal_collision",
"ff_medial_collision",
"ff_distal_collision",
"mf_proximal_collision",
"mf_medial_collision",
"mf_distal_collision",
"rf_proximal_collision",
"rf_medial_collision",
"rf_distal_collision",
"th_proximal_collision",
"th_medial_collision",
"th_distal_collision",
],
"right_fingerpad": [
"ff_tip_collision",
"mf_tip_collision",
"rf_tip_collision",
"th_tip_collision",
],
}
I'm not quiet sure how to resolve this and get the custom gripper to work as expected.
Reproduction
Steps to reproduce:
place the left and right hand .xml files as well as the assets folder under models/assets/grippers
add the allegrohands.py file under /models/grippers
run the tester script
Expected behavior
No response
The text was updated successfully, but these errors were encountered:
i think i managed implementing it by myself. However is there a way of verification? since the gripper tester is not really working on any dexterous hand, since the binary input is directly compared to dof (which most likely seem to fail everytime?)
Hey @JojoSim0n, sorry for delayed reply. Do you mind elaborating what your current issue with testing the gripper is? If you have some starter code that would be helpful for this.
System Info
Information
I'm trying to add the allegro hand from mujoco-menagerie as a custom gripper. I created a simple tester, to verify the gripper model.
which results in:
Loading gripper model: AllegroLeftHand Traceback (most recent call last): File "/home/johannes/Documents/master/robosuite/robosuite/scripts/tester.py", line 12, in <module> gripper = gripper_factory(gripper_name) File "/home/johannes/Documents/master/robosuite/robosuite/models/grippers/gripper_factory.py", line 32, in gripper_factory return GRIPPER_MAPPING[name](idn=idn) File "/home/johannes/Documents/master/robosuite/robosuite/models/grippers/allegro_hands.py", line 19, in __init__ super().__init__(xml_path_completion("grippers/left_hand.xml"), idn=idn) File "/home/johannes/Documents/master/robosuite/robosuite/models/grippers/gripper_model.py", line 21, in __init__ super().__init__(fname, idn=idn) File "/home/johannes/Documents/master/robosuite/robosuite/models/base.py", line 528, in __init__ super().__init__(fname) File "/home/johannes/Documents/master/robosuite/robosuite/models/base.py", line 47, in __init__ self._replace_defaults_inline(default_dic=default_classes) File "/home/johannes/Documents/master/robosuite/robosuite/models/base.py", line 254, in _replace_defaults_inline self._replace_defaults_inline(default_dic=default_dic, root=child) File "/home/johannes/Documents/master/robosuite/robosuite/models/base.py", line 254, in _replace_defaults_inline self._replace_defaults_inline(default_dic=default_dic, root=child) File "/home/johannes/Documents/master/robosuite/robosuite/models/base.py", line 254, in _replace_defaults_inline self._replace_defaults_inline(default_dic=default_dic, root=child) File "/home/johannes/Documents/master/robosuite/robosuite/models/base.py", line 247, in _replace_defaults_inline tag_attrs = default_dic[cls_name].get(root.tag, None) KeyError: 'visual'
the xml files and meshes are placed in the corresponding folders, the models are correctly working using the mujoco-viewer.
Also i created a gripper class:
I'm not quiet sure how to resolve this and get the custom gripper to work as expected.
Reproduction
Steps to reproduce:
Expected behavior
No response
The text was updated successfully, but these errors were encountered: