From d7cdbdd90e698434079ef208989f227bee0fb109 Mon Sep 17 00:00:00 2001 From: Divye Pratap Jain Date: Fri, 17 May 2019 13:09:53 -0700 Subject: [PATCH 1/4] Added get_pixel support in mujoco_env and proprioception in all envs --- mj_envs/hand_manipulation_suite/door_v0.py | 13 +++++++++++++ mj_envs/hand_manipulation_suite/hammer_v0.py | 13 +++++++++++++ mj_envs/hand_manipulation_suite/pen_v0.py | 12 ++++++++++++ mj_envs/hand_manipulation_suite/relocate_v0.py | 13 ++++++++++++- mj_envs/mujoco_env.py | 8 ++++++++ 5 files changed, 58 insertions(+), 1 deletion(-) diff --git a/mj_envs/hand_manipulation_suite/door_v0.py b/mj_envs/hand_manipulation_suite/door_v0.py index 061707cb..2eabb0d5 100644 --- a/mj_envs/hand_manipulation_suite/door_v0.py +++ b/mj_envs/hand_manipulation_suite/door_v0.py @@ -57,6 +57,19 @@ def _step(self, a): return ob, reward, False, {} + def get_proprioception(self, use_tactile): + # return self._get_obs() + robot_jnt = self.data.qpos.ravel()[:-2] + robot_vel = self.data.qvel.ravel()[:-2] + palm_pos = self.data.site_xpos[self.grasp_sid].ravel() + sensordata = [] + if use_tactile: + sensordata = self.data.sensordata.ravel().copy()[:41] + sensordata = np.clip(sensordata, -5.0, 5.0) + + res = np.concatenate([robot_jnt, robot_vel, palm_pos, sensordata]) + return res + def _get_obs(self): # qpos for hand # xpos for obj diff --git a/mj_envs/hand_manipulation_suite/hammer_v0.py b/mj_envs/hand_manipulation_suite/hammer_v0.py index 42ba06f0..3ff72a3c 100644 --- a/mj_envs/hand_manipulation_suite/hammer_v0.py +++ b/mj_envs/hand_manipulation_suite/hammer_v0.py @@ -78,6 +78,19 @@ def _get_obs(self): nail_impact = np.clip(self.sim.data.sensordata[self.sim.model.sensor_name2id('S_nail')], -1.0, 1.0) return np.concatenate([qp[:-6], qv[-6:], palm_pos, obj_pos, obj_rot, target_pos, np.array([nail_impact])]) + def get_proprioception(self, use_tactile): + # return self._get_obs() + robot_jnt = self.data.qpos.ravel()[:-6] + robot_vel = self.data.qvel.ravel()[:-6] + palm_pos = self.data.site_xpos[self.S_grasp_sid].ravel() + sensordata = [] + if use_tactile: + sensordata = self.data.sensordata.ravel().copy()[:41] + sensordata = np.clip(sensordata, -5.0, 5.0) + + res = np.concatenate([robot_jnt, robot_vel, palm_pos, sensordata]) + return res + def reset_model(self): self.sim.reset() target_bid = self.model.body_name2id('nail_board') diff --git a/mj_envs/hand_manipulation_suite/pen_v0.py b/mj_envs/hand_manipulation_suite/pen_v0.py index 8cceba60..f7480884 100644 --- a/mj_envs/hand_manipulation_suite/pen_v0.py +++ b/mj_envs/hand_manipulation_suite/pen_v0.py @@ -85,6 +85,18 @@ def _get_obs(self): return np.concatenate([qp[:-6], obj_pos, obj_vel, obj_orien, desired_orien, obj_pos-desired_pos, obj_orien-desired_orien]) + def get_proprioception(self, use_tactile): + # return self._get_obs() + robot_jnt = self.data.qpos.ravel()[:-6] + robot_vel = self.data.qvel.ravel()[:-6] + palm_pos = self.data.site_xpos[self.S_grasp_sid].ravel() + sensordata = [] + if use_tactile: + sensordata = self.data.sensordata.ravel().copy()[20:41] + + res = np.concatenate([robot_jnt, robot_vel, palm_pos, sensordata]) + return res + def reset_model(self): qp = self.init_qpos.copy() qv = self.init_qvel.copy() diff --git a/mj_envs/hand_manipulation_suite/relocate_v0.py b/mj_envs/hand_manipulation_suite/relocate_v0.py index f1c351c5..d66fa7e5 100644 --- a/mj_envs/hand_manipulation_suite/relocate_v0.py +++ b/mj_envs/hand_manipulation_suite/relocate_v0.py @@ -58,7 +58,18 @@ def _get_obs(self): palm_pos = self.data.site_xpos[self.S_grasp_sid].ravel() target_pos = self.data.site_xpos[self.target_obj_sid].ravel() return np.concatenate([qp[:-6], palm_pos-obj_pos, palm_pos-target_pos, obj_pos-target_pos]) - + + def get_proprioception(self, use_tactile): + # return self._get_obs() + robot_pos = self.data.qpos.ravel()[:-6] + palm_pos = self.data.site_xpos[self.S_grasp_sid].ravel() + sensordata = [] + if use_tactile: + sensordata = self.data.sensordata.ravel().copy()[20:41] + res = np.concatenate([robot_pos, palm_pos, sensordata]) + self.robot_info_dim = len(res) + return res + def reset_model(self): qp = self.init_qpos.copy() qv = self.init_qvel.copy() diff --git a/mj_envs/mujoco_env.py b/mj_envs/mujoco_env.py index 9425e802..31934b69 100644 --- a/mj_envs/mujoco_env.py +++ b/mj_envs/mujoco_env.py @@ -82,6 +82,8 @@ def viewer_setup(self): pass # ----------------------------- + def get_body_com(self, body_name): + return self.sim.data.get_body_xpos(body_name) def _reset(self): self.sim.reset() @@ -129,6 +131,12 @@ def state_vector(self): state.qpos.flat, state.qvel.flat]) # ----------------------------- + def get_pixels(self, frame_size=(128, 128), camera_name=None, device_id=0): + pixels = self.sim.render(width=frame_size[0], height=frame_size[1], + mode='offscreen', camera_name=camera_name, device_id=device_id) + + pixels = pixels[::-1, :, :] + return pixels def visualize_policy(self, policy, horizon=1000, num_episodes=1, mode='exploration'): self.mujoco_render_frames = True From cd01107709dab69775844b4cfb045951dafd7255 Mon Sep 17 00:00:00 2001 From: Divye Pratap Jain Date: Fri, 17 May 2019 13:52:36 -0700 Subject: [PATCH 2/4] added propioception in mujoco_env, to be overridden --- mj_envs/mujoco_env.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mj_envs/mujoco_env.py b/mj_envs/mujoco_env.py index 31934b69..bd1dda4e 100644 --- a/mj_envs/mujoco_env.py +++ b/mj_envs/mujoco_env.py @@ -81,6 +81,12 @@ def viewer_setup(self): """ pass + def get_proprioception(self, use_tactile): + """ + For the VIL paper + """ + pass + # ----------------------------- def get_body_com(self, body_name): return self.sim.data.get_body_xpos(body_name) From 0767ac6485409b187caa9159fbfe6c3dd38fe298 Mon Sep 17 00:00:00 2001 From: Divye Pratap Jain Date: Fri, 17 May 2019 15:42:16 -0700 Subject: [PATCH 3/4] NIT --- mj_envs/hand_manipulation_suite/relocate_v0.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mj_envs/hand_manipulation_suite/relocate_v0.py b/mj_envs/hand_manipulation_suite/relocate_v0.py index d66fa7e5..6381ec14 100644 --- a/mj_envs/hand_manipulation_suite/relocate_v0.py +++ b/mj_envs/hand_manipulation_suite/relocate_v0.py @@ -67,7 +67,6 @@ def get_proprioception(self, use_tactile): if use_tactile: sensordata = self.data.sensordata.ravel().copy()[20:41] res = np.concatenate([robot_pos, palm_pos, sensordata]) - self.robot_info_dim = len(res) return res def reset_model(self): From 8957c3bd7ff1446af3afcb13d50af2b236b2ff51 Mon Sep 17 00:00:00 2001 From: Divye Pratap Jain Date: Thu, 27 Jun 2019 15:49:43 -0700 Subject: [PATCH 4/4] remove body cam function --- mj_envs/mujoco_env.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/mj_envs/mujoco_env.py b/mj_envs/mujoco_env.py index bd1dda4e..8290ad3c 100644 --- a/mj_envs/mujoco_env.py +++ b/mj_envs/mujoco_env.py @@ -88,9 +88,6 @@ def get_proprioception(self, use_tactile): pass # ----------------------------- - def get_body_com(self, body_name): - return self.sim.data.get_body_xpos(body_name) - def _reset(self): self.sim.reset() self.sim.forward()