From 12074e083786ea8d53c345b89ed1131e15b908f5 Mon Sep 17 00:00:00 2001 From: Yu Fang Date: Thu, 21 Nov 2024 17:57:51 -0800 Subject: [PATCH] Adjust based on reviews --- .../robots/default_gr1_fixed_lower_body.json | 4 +-- robosuite/devices/device.py | 3 +-- robosuite/devices/spacemouse.py | 26 +++++++++---------- .../default_mink_ik_gr1.json | 4 +-- .../assets/grippers/inspire_left_hand.xml | 8 +++--- .../assets/grippers/inspire_right_hand.xml | 8 +++--- robosuite/models/grippers/inspire_hands.py | 12 ++++----- 7 files changed, 34 insertions(+), 31 deletions(-) diff --git a/robosuite/controllers/config/robots/default_gr1_fixed_lower_body.json b/robosuite/controllers/config/robots/default_gr1_fixed_lower_body.json index eb678b0cb5..e9e395f5a5 100644 --- a/robosuite/controllers/config/robots/default_gr1_fixed_lower_body.json +++ b/robosuite/controllers/config/robots/default_gr1_fixed_lower_body.json @@ -12,8 +12,8 @@ "ik_input_rotation_repr": "axis_angle", "verbose": false, "ik_posture_weights": { - "robot0_torso_waist_yaw": 30.0, - "robot0_torso_waist_pitch": 100.0, + "robot0_torso_waist_yaw": 20.0, + "robot0_torso_waist_pitch": 20.0, "robot0_torso_waist_roll": 100.0, "robot0_l_shoulder_pitch": 4.0, "robot0_r_shoulder_pitch": 4.0, diff --git a/robosuite/devices/device.py b/robosuite/devices/device.py index 0fdf4e02f0..43ec49a9ce 100644 --- a/robosuite/devices/device.py +++ b/robosuite/devices/device.py @@ -163,8 +163,7 @@ def input2action(self, mirror_actions=False) -> Optional[Dict]: ) ac_dict[f"{active_arm}_abs"] = arm_action["abs"] ac_dict[f"{active_arm}_delta"] = arm_action["delta"] - # ac_dict[f"{active_arm}_gripper"] = np.array([grasp] * gripper_dof) - ac_dict[f"{active_arm}_gripper"] = [1, 0.45 * grasp, grasp, grasp, grasp, grasp] + ac_dict[f"{active_arm}_gripper"] = np.array([grasp] * gripper_dof) # clip actions between -1 and 1 for k, v in ac_dict.items(): diff --git a/robosuite/devices/spacemouse.py b/robosuite/devices/spacemouse.py index fe559448d4..1e3cacf9fb 100644 --- a/robosuite/devices/spacemouse.py +++ b/robosuite/devices/spacemouse.py @@ -102,7 +102,7 @@ def convert(b1, b2): return scale_to_control(to_int16(b1, b2)) -class SpaceMouseSdkWrapper: +class SpaceMouseListener: """ A wrapper for interfacing with SpaceMouse devices using the HID library. @@ -329,9 +329,9 @@ def __init__( product_id_path_pairs.add((device["product_id"], device["path"])) product_id_path_pairs = sorted(list(product_id_path_pairs)) - self.devices = [] + self.listeners = [] for product_id, path in product_id_path_pairs: - self.devices.append(SpaceMouseSdkWrapper(product_id, path, pos_sensitivity, rot_sensitivity)) + self.listeners.append(SpaceMouseListener(product_id, path, pos_sensitivity, rot_sensitivity)) # also add a keyboard for aux controls self.listener = Listener(on_press=self.on_press, on_release=self.on_release) @@ -368,8 +368,8 @@ def _reset_internal_state(self): """ super()._reset_internal_state() - for device in self.devices: - device._reset_internal_state() + for listener in self.listeners: + listener._reset_internal_state() def start_control(self): """ @@ -377,8 +377,8 @@ def start_control(self): start receiving commands. """ self._reset_internal_state() - for device in self.devices: - device.start_control() + for listener in self.listeners: + listener.start_control() def get_controller_state(self): """ @@ -387,7 +387,7 @@ def get_controller_state(self): Returns: dict: A dictionary containing dpos, orn, unmodified orn, grasp, and reset """ - controller_state = self.devices[self.active_arm_index % len(self.devices)].get_controller_state() + controller_state = self.listeners[self.active_arm_index % len(self.listeners)].get_controller_state() controller_state.update({"base_mode": int(self.base_mode)}) return controller_state @@ -404,12 +404,12 @@ def input2action(self, mirror_actions=False) -> Optional[Dict]: """ final_ac = None original_arm_index = self.active_arm_index - for i in range(len(self.devices)): + for i in range(len(self.listeners)): ac_dict = super().input2action(mirror_actions) if ac_dict is None: # reset from any space mouse - for device in self.devices: - device._reset_state = 1 - device._enabled = False + for listener in self.listeners: + listener._reset_state = 1 + listener._enabled = False self._reset_internal_state() return None elif final_ac is None: @@ -469,7 +469,7 @@ def _postprocess_device_outputs(self, dpos, drotation): for device in hid.enumerate(): if device["vendor_id"] == vendor_id and device["path"] not in device_pathes: space_mice.append( - SpaceMouseSdkWrapper(device["product_id"], device["path"], pos_sensitivity, rot_sensitivity) + SpaceMouseListener(device["product_id"], device["path"], pos_sensitivity, rot_sensitivity) ) device_pathes.add(device["path"]) diff --git a/robosuite/examples/third_party_controller/default_mink_ik_gr1.json b/robosuite/examples/third_party_controller/default_mink_ik_gr1.json index 739390fe87..680043c7fa 100644 --- a/robosuite/examples/third_party_controller/default_mink_ik_gr1.json +++ b/robosuite/examples/third_party_controller/default_mink_ik_gr1.json @@ -12,8 +12,8 @@ "ik_input_rotation_repr": "axis_angle", "verbose": false, "ik_posture_weights": { - "robot0_torso_waist_yaw": 30.0, - "robot0_torso_waist_pitch": 100.0, + "robot0_torso_waist_yaw": 20.0, + "robot0_torso_waist_pitch": 20.0, "robot0_torso_waist_roll": 100.0, "robot0_l_shoulder_pitch": 4.0, "robot0_r_shoulder_pitch": 4.0, diff --git a/robosuite/models/assets/grippers/inspire_left_hand.xml b/robosuite/models/assets/grippers/inspire_left_hand.xml index 74ccf973a6..6aedc35f13 100644 --- a/robosuite/models/assets/grippers/inspire_left_hand.xml +++ b/robosuite/models/assets/grippers/inspire_left_hand.xml @@ -79,7 +79,7 @@ - + @@ -94,8 +94,10 @@ - - + + + + diff --git a/robosuite/models/assets/grippers/inspire_right_hand.xml b/robosuite/models/assets/grippers/inspire_right_hand.xml index ad6ba709f5..e067aaf067 100644 --- a/robosuite/models/assets/grippers/inspire_right_hand.xml +++ b/robosuite/models/assets/grippers/inspire_right_hand.xml @@ -76,7 +76,7 @@ - + @@ -91,8 +91,10 @@ - - + + + + diff --git a/robosuite/models/grippers/inspire_hands.py b/robosuite/models/grippers/inspire_hands.py index 26f61887ab..ff7f020ff4 100644 --- a/robosuite/models/grippers/inspire_hands.py +++ b/robosuite/models/grippers/inspire_hands.py @@ -23,9 +23,9 @@ def format_action(self, action): # however the tag makes finger movement laggy, so manually copy the value for finger joints # 0 is thumb rot, no copying. Thumb bend has 3 joints, so copy 3 times. Other fingers has 2 joints, so copy 2 times. assert len(action) == self.dof - action = np.array(action) - indices = np.array([0, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) - return action[indices] + vel = np.array([1, 0.45 * action[0], action[0]]) + indices = np.array([0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2]) + return vel[indices] @property def init_qpos(self): @@ -93,9 +93,9 @@ def format_action(self, action): # however the tag makes finger movement laggy, so manually copy the value for finger joints # 0 is thumb rot, no copying. Thumb bend has 3 joints, so copy 3 times. Other fingers has 2 joints, so copy 2 times. assert len(action) == self.dof - action = np.array(action) - indices = np.array([0, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) - return action[indices] + vel = np.array([1, 0.45 * action[0], action[0]]) + indices = np.array([0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2]) + return vel[indices] @property def init_qpos(self):