From 4ba0749d10d7bbb61aff801714378c52d90e10bf Mon Sep 17 00:00:00 2001 From: Cheryl Wang <90352960+cherylwang20@users.noreply.github.com> Date: Tue, 29 Oct 2024 11:13:08 -0400 Subject: [PATCH 1/4] BUGFIX: Manipulation ENV Increase to 10 seconds (1000 timesteps). Bug fix for trajectory evaluation Bug fix for ENV contact evaluation --- myosuite/envs/myo/myochallenge/__init__.py | 2 +- myosuite/envs/myo/myochallenge/bimanual_v0.py | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/myosuite/envs/myo/myochallenge/__init__.py b/myosuite/envs/myo/myochallenge/__init__.py index a34b6633..0ef2185c 100644 --- a/myosuite/envs/myo/myochallenge/__init__.py +++ b/myosuite/envs/myo/myochallenge/__init__.py @@ -33,7 +33,7 @@ def register_env_with_variants(id, entry_point, max_episode_steps, kwargs): register_env_with_variants(id='myoChallengeBimanual-v0', entry_point='myosuite.envs.myo.myochallenge.bimanual_v0:BimanualEnvV1', - max_episode_steps=300, + max_episode_steps=1000, kwargs={ 'model_path': curr_dir + '/../assets/arm/myoarm_bionic_bimanual.xml', 'normalize_act': True, diff --git a/myosuite/envs/myo/myochallenge/bimanual_v0.py b/myosuite/envs/myo/myochallenge/bimanual_v0.py index 7bf225ee..c90f8fa9 100644 --- a/myosuite/envs/myo/myochallenge/bimanual_v0.py +++ b/myosuite/envs/myo/myochallenge/bimanual_v0.py @@ -18,6 +18,7 @@ from myosuite.envs.myo.base_v0 import BaseV0 CONTACT_TRAJ_MIN_LENGTH = 100 +GOAL_CONTACT = 10 class BimanualEnvV1(BaseV0): @@ -116,7 +117,7 @@ def _setup(self, self.over_max = False self.max_force = 0 self.goal_touch = 0 - self.TARGET_GOAL_TOUCH = 5 + self.TARGET_GOAL_TOUCH = GOAL_CONTACT self.touch_history = [] @@ -291,10 +292,10 @@ def get_reward_dict(self, obs_dict): return rwd_dict def _get_done(self, z): - if self.obs_dict['time'] > 3.0: + if self.obs_dict['time'] > 10.0: return 1 elif z < 0.3: - self.obs_dict['time'] = 3.0 + self.obs_dict['time'] = 10.0 return 1 elif self.rwd_dict and self.rwd_dict['solved']: return 1 @@ -448,9 +449,9 @@ def get_touching_objects(model: mujoco.MjModel, data: mujoco.MjData, id_info: Id def body_id_to_label(body_id, id_info: IdInfo): - if id_info.myo_body_range[0] < body_id < id_info.myo_body_range[1]: + if id_info.myo_body_range[0] <= body_id <= id_info.myo_body_range[1]: return ObjLabels.MYO - elif id_info.prosth_body_range[0] < body_id < id_info.prosth_body_range[1]: + elif id_info.prosth_body_range[0] <= body_id <= id_info.prosth_body_range[1]: return ObjLabels.PROSTH elif body_id == id_info.start_id: return ObjLabels.START @@ -474,5 +475,5 @@ def evaluate_contact_trajectory(contact_trajectory: List[set]): return ContactTrajIssue.PROSTH_SHORT # Check if only goal was touching object for the last CONTACT_TRAJ_MIN_LENGTH frames - elif not np.all([{ObjLabels.GOAL} == s for s in contact_trajectory[-CONTACT_TRAJ_MIN_LENGTH:]]): + elif not np.all([{ObjLabels.GOAL} == s for s in contact_trajectory[-GOAL_CONTACT + 2:]]): return ContactTrajIssue.NO_GOAL From ddbbd000c36b3e498906071645d70edd76daeb0a Mon Sep 17 00:00:00 2001 From: Cheryl Wang <90352960+cherylwang20@users.noreply.github.com> Date: Tue, 29 Oct 2024 11:20:03 -0400 Subject: [PATCH 2/4] Uploaded script for hard-coded policy --- myosuite/envs/myo/myochallenge/bimanual_v0.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/myosuite/envs/myo/myochallenge/bimanual_v0.py b/myosuite/envs/myo/myochallenge/bimanual_v0.py index c90f8fa9..656e8ff2 100644 --- a/myosuite/envs/myo/myochallenge/bimanual_v0.py +++ b/myosuite/envs/myo/myochallenge/bimanual_v0.py @@ -304,12 +304,24 @@ def _get_done(self, z): def step(self, a, **kwargs): # We unnormalize robotic actuators, muscle ones are handled in the parent implementation processed_controls = a.copy() + ''' + We provided a hard-corded way of handling the MPL for your reference, simply uncomment all the lines. + ''' + #processed_controls[30] = 1 + #if self.time > 1.3: + # processed_controls[32:40] = 0 + # processed_controls[40:49] = 1 if self.normalize_act: robotic_act_ind = self.sim.model.actuator_dyntype != mujoco.mjtDyn.mjDYN_MUSCLE processed_controls[robotic_act_ind] = (np.mean(self.sim.model.actuator_ctrlrange[robotic_act_ind], axis=-1) + processed_controls[robotic_act_ind] * (self.sim.model.actuator_ctrlrange[robotic_act_ind, 1] - self.sim.model.actuator_ctrlrange[robotic_act_ind, 0]) / 2.0) + #processed_controls[robotic_act_ind] = np.array([-0.0155, 0, 0.24681, 1.89, 1.45, 0.181, -0.28, 0.126, 0.625, 0.077, -0.0248, 0.0139, 0.044, 0.06, 0.0568, 0.0867, 0.656]) + #if self.time > 2.5: + # processed_controls[robotic_act_ind] = np.array([0.376, 0, -0.508, 1.61, 1.45, 0.276, -0.28, 0.126, 0.625, 0.077, -0.0248, 0.0139, 0.044, 0.06, 0.0568, 0.0867, 0.0656]) + #if self.time > 3.5: + # processed_controls[robotic_act_ind] = np.array([0.376, 0, -0.508, 1.61, 0.614, 0.276, -0.28, 0.126, 0.625, 0.077, -0.0248, 0.0139, 0.044, 0.06, 0.0568, 0.0867, 0.0656]) return super().step(processed_controls, **kwargs) From 9e55f36709af895774f151bca3ad790b0a2803dd Mon Sep 17 00:00:00 2001 From: Cheryl Wang <90352960+cherylwang20@users.noreply.github.com> Date: Tue, 29 Oct 2024 17:43:02 -0400 Subject: [PATCH 3/4] Deleting hard-coded solution --- myosuite/envs/myo/myochallenge/bimanual_v0.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/myosuite/envs/myo/myochallenge/bimanual_v0.py b/myosuite/envs/myo/myochallenge/bimanual_v0.py index 656e8ff2..c90f8fa9 100644 --- a/myosuite/envs/myo/myochallenge/bimanual_v0.py +++ b/myosuite/envs/myo/myochallenge/bimanual_v0.py @@ -304,24 +304,12 @@ def _get_done(self, z): def step(self, a, **kwargs): # We unnormalize robotic actuators, muscle ones are handled in the parent implementation processed_controls = a.copy() - ''' - We provided a hard-corded way of handling the MPL for your reference, simply uncomment all the lines. - ''' - #processed_controls[30] = 1 - #if self.time > 1.3: - # processed_controls[32:40] = 0 - # processed_controls[40:49] = 1 if self.normalize_act: robotic_act_ind = self.sim.model.actuator_dyntype != mujoco.mjtDyn.mjDYN_MUSCLE processed_controls[robotic_act_ind] = (np.mean(self.sim.model.actuator_ctrlrange[robotic_act_ind], axis=-1) + processed_controls[robotic_act_ind] * (self.sim.model.actuator_ctrlrange[robotic_act_ind, 1] - self.sim.model.actuator_ctrlrange[robotic_act_ind, 0]) / 2.0) - #processed_controls[robotic_act_ind] = np.array([-0.0155, 0, 0.24681, 1.89, 1.45, 0.181, -0.28, 0.126, 0.625, 0.077, -0.0248, 0.0139, 0.044, 0.06, 0.0568, 0.0867, 0.656]) - #if self.time > 2.5: - # processed_controls[robotic_act_ind] = np.array([0.376, 0, -0.508, 1.61, 1.45, 0.276, -0.28, 0.126, 0.625, 0.077, -0.0248, 0.0139, 0.044, 0.06, 0.0568, 0.0867, 0.0656]) - #if self.time > 3.5: - # processed_controls[robotic_act_ind] = np.array([0.376, 0, -0.508, 1.61, 0.614, 0.276, -0.28, 0.126, 0.625, 0.077, -0.0248, 0.0139, 0.044, 0.06, 0.0568, 0.0867, 0.0656]) return super().step(processed_controls, **kwargs) From 01a4adc3eff40d6944f4c5fc34ac16ff9d4f4ef6 Mon Sep 17 00:00:00 2001 From: Cheryl Wang <90352960+cherylwang20@users.noreply.github.com> Date: Wed, 30 Oct 2024 15:34:49 -0400 Subject: [PATCH 4/4] Added comment and change MAX time to global --- myosuite/envs/myo/myochallenge/bimanual_v0.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/myosuite/envs/myo/myochallenge/bimanual_v0.py b/myosuite/envs/myo/myochallenge/bimanual_v0.py index c90f8fa9..31ab7cf2 100644 --- a/myosuite/envs/myo/myochallenge/bimanual_v0.py +++ b/myosuite/envs/myo/myochallenge/bimanual_v0.py @@ -19,6 +19,7 @@ CONTACT_TRAJ_MIN_LENGTH = 100 GOAL_CONTACT = 10 +MAX_TIME = 10.0 class BimanualEnvV1(BaseV0): @@ -292,10 +293,10 @@ def get_reward_dict(self, obs_dict): return rwd_dict def _get_done(self, z): - if self.obs_dict['time'] > 10.0: + if self.obs_dict['time'] > MAX_TIME: return 1 elif z < 0.3: - self.obs_dict['time'] = 10.0 + self.obs_dict['time'] = MAX_TIME return 1 elif self.rwd_dict and self.rwd_dict['solved']: return 1 @@ -475,5 +476,5 @@ def evaluate_contact_trajectory(contact_trajectory: List[set]): return ContactTrajIssue.PROSTH_SHORT # Check if only goal was touching object for the last CONTACT_TRAJ_MIN_LENGTH frames - elif not np.all([{ObjLabels.GOAL} == s for s in contact_trajectory[-GOAL_CONTACT + 2:]]): + elif not np.all([{ObjLabels.GOAL} == s for s in contact_trajectory[-GOAL_CONTACT + 2:]]): # Subtract 2 from the calculation to maintain a buffer zone around trajectory boundaries for safety/accuracy. return ContactTrajIssue.NO_GOAL