Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- Metaworld/metaworld/policies/__pycache__/action.cpython-38.pyc +0 -0
- Metaworld/metaworld/policies/__pycache__/policy.cpython-38.pyc +0 -0
- Metaworld/metaworld/policies/__pycache__/sawyer_assembly_v1_policy.cpython-38.pyc +0 -0
- Metaworld/metaworld/policies/__pycache__/sawyer_assembly_v2_policy.cpython-38.pyc +0 -0
- Metaworld/metaworld/policies/__pycache__/sawyer_basketball_v1_policy.cpython-38.pyc +0 -0
- Metaworld/metaworld/policies/__pycache__/sawyer_box_close_v2_policy.cpython-38.pyc +0 -0
- Metaworld/metaworld/policies/__pycache__/sawyer_button_press_topdown_wall_v1_policy.cpython-38.pyc +0 -0
- Metaworld/metaworld/policies/__pycache__/sawyer_button_press_topdown_wall_v2_policy.cpython-38.pyc +0 -0
- Metaworld/metaworld/policies/__pycache__/sawyer_coffee_button_v1_policy.cpython-38.pyc +0 -0
- Metaworld/metaworld/policies/__pycache__/sawyer_coffee_pull_v1_policy.cpython-38.pyc +0 -0
- Metaworld/metaworld/policies/__pycache__/sawyer_coffee_push_v1_policy.cpython-38.pyc +0 -0
- Metaworld/metaworld/policies/__pycache__/sawyer_dial_turn_v2_policy.cpython-38.pyc +0 -0
- Metaworld/metaworld/policies/__pycache__/sawyer_door_open_v1_policy.cpython-38.pyc +0 -0
- Metaworld/metaworld/policies/__pycache__/sawyer_drawer_close_v1_policy.cpython-38.pyc +0 -0
- Metaworld/metaworld/policies/__pycache__/sawyer_faucet_close_v2_policy.cpython-38.pyc +0 -0
- Metaworld/metaworld/policies/__pycache__/sawyer_faucet_open_v1_policy.cpython-38.pyc +0 -0
- Metaworld/metaworld/policies/__pycache__/sawyer_hand_insert_v1_policy.cpython-38.pyc +0 -0
- Metaworld/metaworld/policies/__pycache__/sawyer_hand_insert_v2_policy.cpython-38.pyc +0 -0
- Metaworld/metaworld/policies/__pycache__/sawyer_handle_press_side_v2_policy.cpython-38.pyc +0 -0
- Metaworld/metaworld/policies/__pycache__/sawyer_handle_pull_side_v1_policy.cpython-38.pyc +0 -0
- Metaworld/metaworld/policies/__pycache__/sawyer_handle_pull_side_v2_policy.cpython-38.pyc +0 -0
- Metaworld/metaworld/policies/__pycache__/sawyer_peg_unplug_side_v1_policy.cpython-38.pyc +0 -0
- Metaworld/metaworld/policies/__pycache__/sawyer_plate_slide_back_v1_policy.cpython-38.pyc +0 -0
- Metaworld/metaworld/policies/__pycache__/sawyer_plate_slide_side_v2_policy.cpython-38.pyc +0 -0
- Metaworld/metaworld/policies/__pycache__/sawyer_plate_slide_v2_policy.cpython-38.pyc +0 -0
- Metaworld/metaworld/policies/__pycache__/sawyer_reach_v2_policy.cpython-38.pyc +0 -0
- Metaworld/metaworld/policies/__pycache__/sawyer_soccer_v1_policy.cpython-38.pyc +0 -0
- Metaworld/metaworld/policies/__pycache__/sawyer_window_open_v2_policy.cpython-38.pyc +0 -0
- Metaworld/metaworld/policies/policy.py +71 -0
- Metaworld/metaworld/policies/sawyer_box_close_v1_policy.py +60 -0
- Metaworld/metaworld/policies/sawyer_button_press_topdown_v2_policy.py +40 -0
- Metaworld/metaworld/policies/sawyer_button_press_topdown_wall_v2_policy.py +40 -0
- Metaworld/metaworld/policies/sawyer_button_press_v2_policy.py +49 -0
- Metaworld/metaworld/policies/sawyer_button_press_wall_v1_policy.py +54 -0
- Metaworld/metaworld/policies/sawyer_button_press_wall_v2_policy.py +55 -0
- Metaworld/metaworld/policies/sawyer_coffee_button_v2_policy.py +40 -0
- Metaworld/metaworld/policies/sawyer_coffee_push_v2_policy.py +56 -0
- Metaworld/metaworld/policies/sawyer_dial_turn_v1_policy.py +39 -0
- Metaworld/metaworld/policies/sawyer_dial_turn_v2_policy.py +41 -0
- Metaworld/metaworld/policies/sawyer_disassemble_v1_policy.py +59 -0
- Metaworld/metaworld/policies/sawyer_disassemble_v2_policy.py +57 -0
- Metaworld/metaworld/policies/sawyer_door_close_v2_policy.py +54 -0
- Metaworld/metaworld/policies/sawyer_drawer_close_v1_policy.py +49 -0
- Metaworld/metaworld/policies/sawyer_drawer_close_v2_policy.py +50 -0
- Metaworld/metaworld/policies/sawyer_drawer_open_v1_policy.py +48 -0
- Metaworld/metaworld/policies/sawyer_faucet_close_v1_policy.py +41 -0
- Metaworld/metaworld/policies/sawyer_faucet_open_v2_policy.py +42 -0
- Metaworld/metaworld/policies/sawyer_hand_insert_v2_policy.py +59 -0
- Metaworld/metaworld/policies/sawyer_handle_press_side_v2_policy.py +40 -0
- Metaworld/metaworld/policies/sawyer_handle_pull_side_v1_policy.py +43 -0
Metaworld/metaworld/policies/__pycache__/action.cpython-38.pyc
ADDED
|
Binary file (1.64 kB). View file
|
|
|
Metaworld/metaworld/policies/__pycache__/policy.cpython-38.pyc
ADDED
|
Binary file (2.69 kB). View file
|
|
|
Metaworld/metaworld/policies/__pycache__/sawyer_assembly_v1_policy.cpython-38.pyc
ADDED
|
Binary file (2.18 kB). View file
|
|
|
Metaworld/metaworld/policies/__pycache__/sawyer_assembly_v2_policy.cpython-38.pyc
ADDED
|
Binary file (2.15 kB). View file
|
|
|
Metaworld/metaworld/policies/__pycache__/sawyer_basketball_v1_policy.cpython-38.pyc
ADDED
|
Binary file (2.03 kB). View file
|
|
|
Metaworld/metaworld/policies/__pycache__/sawyer_box_close_v2_policy.cpython-38.pyc
ADDED
|
Binary file (2.08 kB). View file
|
|
|
Metaworld/metaworld/policies/__pycache__/sawyer_button_press_topdown_wall_v1_policy.cpython-38.pyc
ADDED
|
Binary file (1.56 kB). View file
|
|
|
Metaworld/metaworld/policies/__pycache__/sawyer_button_press_topdown_wall_v2_policy.cpython-38.pyc
ADDED
|
Binary file (1.59 kB). View file
|
|
|
Metaworld/metaworld/policies/__pycache__/sawyer_coffee_button_v1_policy.cpython-38.pyc
ADDED
|
Binary file (1.52 kB). View file
|
|
|
Metaworld/metaworld/policies/__pycache__/sawyer_coffee_pull_v1_policy.cpython-38.pyc
ADDED
|
Binary file (1.91 kB). View file
|
|
|
Metaworld/metaworld/policies/__pycache__/sawyer_coffee_push_v1_policy.cpython-38.pyc
ADDED
|
Binary file (1.97 kB). View file
|
|
|
Metaworld/metaworld/policies/__pycache__/sawyer_dial_turn_v2_policy.cpython-38.pyc
ADDED
|
Binary file (1.59 kB). View file
|
|
|
Metaworld/metaworld/policies/__pycache__/sawyer_door_open_v1_policy.cpython-38.pyc
ADDED
|
Binary file (1.57 kB). View file
|
|
|
Metaworld/metaworld/policies/__pycache__/sawyer_drawer_close_v1_policy.cpython-38.pyc
ADDED
|
Binary file (1.58 kB). View file
|
|
|
Metaworld/metaworld/policies/__pycache__/sawyer_faucet_close_v2_policy.cpython-38.pyc
ADDED
|
Binary file (1.61 kB). View file
|
|
|
Metaworld/metaworld/policies/__pycache__/sawyer_faucet_open_v1_policy.cpython-38.pyc
ADDED
|
Binary file (1.56 kB). View file
|
|
|
Metaworld/metaworld/policies/__pycache__/sawyer_hand_insert_v1_policy.cpython-38.pyc
ADDED
|
Binary file (1.99 kB). View file
|
|
|
Metaworld/metaworld/policies/__pycache__/sawyer_hand_insert_v2_policy.cpython-38.pyc
ADDED
|
Binary file (2 kB). View file
|
|
|
Metaworld/metaworld/policies/__pycache__/sawyer_handle_press_side_v2_policy.cpython-38.pyc
ADDED
|
Binary file (1.55 kB). View file
|
|
|
Metaworld/metaworld/policies/__pycache__/sawyer_handle_pull_side_v1_policy.cpython-38.pyc
ADDED
|
Binary file (1.68 kB). View file
|
|
|
Metaworld/metaworld/policies/__pycache__/sawyer_handle_pull_side_v2_policy.cpython-38.pyc
ADDED
|
Binary file (1.87 kB). View file
|
|
|
Metaworld/metaworld/policies/__pycache__/sawyer_peg_unplug_side_v1_policy.cpython-38.pyc
ADDED
|
Binary file (1.9 kB). View file
|
|
|
Metaworld/metaworld/policies/__pycache__/sawyer_plate_slide_back_v1_policy.cpython-38.pyc
ADDED
|
Binary file (1.72 kB). View file
|
|
|
Metaworld/metaworld/policies/__pycache__/sawyer_plate_slide_side_v2_policy.cpython-38.pyc
ADDED
|
Binary file (1.68 kB). View file
|
|
|
Metaworld/metaworld/policies/__pycache__/sawyer_plate_slide_v2_policy.cpython-38.pyc
ADDED
|
Binary file (1.67 kB). View file
|
|
|
Metaworld/metaworld/policies/__pycache__/sawyer_reach_v2_policy.cpython-38.pyc
ADDED
|
Binary file (1.18 kB). View file
|
|
|
Metaworld/metaworld/policies/__pycache__/sawyer_soccer_v1_policy.cpython-38.pyc
ADDED
|
Binary file (1.63 kB). View file
|
|
|
Metaworld/metaworld/policies/__pycache__/sawyer_window_open_v2_policy.cpython-38.pyc
ADDED
|
Binary file (1.61 kB). View file
|
|
|
Metaworld/metaworld/policies/policy.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import abc
|
| 2 |
+
import warnings
|
| 3 |
+
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def assert_fully_parsed(func):
|
| 8 |
+
"""Decorator function to ensure observations are fully parsed
|
| 9 |
+
|
| 10 |
+
Args:
|
| 11 |
+
func (Callable): The function to check
|
| 12 |
+
|
| 13 |
+
Returns:
|
| 14 |
+
(Callable): The input function, decorated to assert full parsing
|
| 15 |
+
"""
|
| 16 |
+
def inner(obs):
|
| 17 |
+
obs_dict = func(obs)
|
| 18 |
+
assert len(obs) == sum(
|
| 19 |
+
[len(i) if isinstance(i, np.ndarray) else 1 for i in obs_dict.values()]
|
| 20 |
+
), 'Observation not fully parsed'
|
| 21 |
+
return obs_dict
|
| 22 |
+
return inner
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def move(from_xyz, to_xyz, p):
|
| 26 |
+
"""Computes action components that help move from 1 position to another
|
| 27 |
+
|
| 28 |
+
Args:
|
| 29 |
+
from_xyz (np.ndarray): The coordinates to move from (usually current position)
|
| 30 |
+
to_xyz (np.ndarray): The coordinates to move to
|
| 31 |
+
p (float): constant to scale response
|
| 32 |
+
|
| 33 |
+
Returns:
|
| 34 |
+
(np.ndarray): Response that will decrease abs(to_xyz - from_xyz)
|
| 35 |
+
|
| 36 |
+
"""
|
| 37 |
+
error = to_xyz - from_xyz
|
| 38 |
+
response = p * error
|
| 39 |
+
|
| 40 |
+
if np.any(np.absolute(response) > 1.):
|
| 41 |
+
warnings.warn('Constant(s) may be too high. Environments clip response to [-1, 1]')
|
| 42 |
+
|
| 43 |
+
return response
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
class Policy(abc.ABC):
|
| 47 |
+
|
| 48 |
+
@staticmethod
|
| 49 |
+
@abc.abstractmethod
|
| 50 |
+
def _parse_obs(obs):
|
| 51 |
+
"""Pulls pertinent information out of observation and places in a dict.
|
| 52 |
+
|
| 53 |
+
Args:
|
| 54 |
+
obs (np.ndarray): Observation which conforms to env.observation_space
|
| 55 |
+
|
| 56 |
+
Returns:
|
| 57 |
+
dict: Dictionary which contains information from the observation
|
| 58 |
+
"""
|
| 59 |
+
pass
|
| 60 |
+
|
| 61 |
+
@abc.abstractmethod
|
| 62 |
+
def get_action(self, obs):
|
| 63 |
+
"""Gets an action in response to an observation.
|
| 64 |
+
|
| 65 |
+
Args:
|
| 66 |
+
obs (np.ndarray): Observation which conforms to env.observation_space
|
| 67 |
+
|
| 68 |
+
Returns:
|
| 69 |
+
np.ndarray: Array (usually 4 elements) representing the action to take
|
| 70 |
+
"""
|
| 71 |
+
pass
|
Metaworld/metaworld/policies/sawyer_box_close_v1_policy.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from metaworld.policies.action import Action
|
| 4 |
+
from metaworld.policies.policy import Policy, assert_fully_parsed, move
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class SawyerBoxCloseV1Policy(Policy):
|
| 8 |
+
|
| 9 |
+
@staticmethod
|
| 10 |
+
@assert_fully_parsed
|
| 11 |
+
def _parse_obs(obs):
|
| 12 |
+
return {
|
| 13 |
+
'hand_pos': obs[:3],
|
| 14 |
+
'lid_pos': obs[3:6],
|
| 15 |
+
'box_pos': obs[9:11],
|
| 16 |
+
'extra_info': obs[[6, 7, 8, 11]],
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
def get_action(self, obs):
|
| 20 |
+
o_d = self._parse_obs(obs)
|
| 21 |
+
|
| 22 |
+
action = Action({
|
| 23 |
+
'delta_pos': np.arange(3),
|
| 24 |
+
'grab_effort': 3
|
| 25 |
+
})
|
| 26 |
+
|
| 27 |
+
action['delta_pos'] = move(o_d['hand_pos'], to_xyz=self._desired_pos(o_d), p=25.)
|
| 28 |
+
action['grab_effort'] = self._grab_effort(o_d)
|
| 29 |
+
|
| 30 |
+
return action.array
|
| 31 |
+
|
| 32 |
+
@staticmethod
|
| 33 |
+
def _desired_pos(o_d):
|
| 34 |
+
pos_curr = o_d['hand_pos']
|
| 35 |
+
pos_lid = o_d['lid_pos'] + np.array([-.04, .0, -.06])
|
| 36 |
+
pos_box = np.array([*o_d['box_pos'], 0.15]) + np.array([-.04, .0, .0])
|
| 37 |
+
|
| 38 |
+
# If error in the XY plane is greater than 0.02, place end effector above the puck
|
| 39 |
+
if np.linalg.norm(pos_curr[:2] - pos_lid[:2]) > 0.01:
|
| 40 |
+
return pos_lid + np.array([0., 0., 0.1])
|
| 41 |
+
# Once XY error is low enough, drop end effector down on top of puck
|
| 42 |
+
elif abs(pos_curr[2] - pos_lid[2]) > 0.05:
|
| 43 |
+
return pos_lid
|
| 44 |
+
# If not at the same Z height as the goal, move up to that plane
|
| 45 |
+
elif abs(pos_curr[2] - pos_box[2]) > 0.04:
|
| 46 |
+
return np.array([pos_curr[0], pos_curr[1], pos_box[2]])
|
| 47 |
+
# Move to the goal
|
| 48 |
+
else:
|
| 49 |
+
return pos_box
|
| 50 |
+
|
| 51 |
+
@staticmethod
|
| 52 |
+
def _grab_effort(o_d):
|
| 53 |
+
pos_curr = o_d['hand_pos']
|
| 54 |
+
pos_puck = o_d['lid_pos'] + np.array([-.04, .0, -.06])
|
| 55 |
+
|
| 56 |
+
if np.linalg.norm(pos_curr[:2] - pos_puck[:2]) > 0.01 or abs(pos_curr[2] - pos_puck[2]) > 0.13:
|
| 57 |
+
return 0.
|
| 58 |
+
# While end effector is moving down toward the puck, begin closing the grabber
|
| 59 |
+
else:
|
| 60 |
+
return .8
|
Metaworld/metaworld/policies/sawyer_button_press_topdown_v2_policy.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from metaworld.policies.action import Action
|
| 4 |
+
from metaworld.policies.policy import Policy, assert_fully_parsed, move
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class SawyerButtonPressTopdownV2Policy(Policy):
|
| 8 |
+
|
| 9 |
+
@staticmethod
|
| 10 |
+
@assert_fully_parsed
|
| 11 |
+
def _parse_obs(obs):
|
| 12 |
+
return {
|
| 13 |
+
'hand_pos': obs[:3],
|
| 14 |
+
'hand_closed': obs[3],
|
| 15 |
+
'button_pos': obs[4:7],
|
| 16 |
+
'unused_info': obs[7:],
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
def get_action(self, obs):
|
| 20 |
+
o_d = self._parse_obs(obs)
|
| 21 |
+
|
| 22 |
+
action = Action({
|
| 23 |
+
'delta_pos': np.arange(3),
|
| 24 |
+
'grab_effort': 3
|
| 25 |
+
})
|
| 26 |
+
|
| 27 |
+
action['delta_pos'] = move(o_d['hand_pos'], to_xyz=self._desired_pos(o_d), p=25.)
|
| 28 |
+
action['grab_effort'] = 1.
|
| 29 |
+
|
| 30 |
+
return action.array
|
| 31 |
+
|
| 32 |
+
@staticmethod
|
| 33 |
+
def _desired_pos(o_d):
|
| 34 |
+
pos_curr = o_d['hand_pos']
|
| 35 |
+
pos_button = o_d['button_pos']
|
| 36 |
+
|
| 37 |
+
if np.linalg.norm(pos_curr[:2] - pos_button[:2]) > 0.04:
|
| 38 |
+
return pos_button + np.array([0., 0., 0.1])
|
| 39 |
+
else:
|
| 40 |
+
return pos_button
|
Metaworld/metaworld/policies/sawyer_button_press_topdown_wall_v2_policy.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from metaworld.policies.action import Action
|
| 4 |
+
from metaworld.policies.policy import Policy, assert_fully_parsed, move
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class SawyerButtonPressTopdownWallV2Policy(Policy):
|
| 8 |
+
|
| 9 |
+
@staticmethod
|
| 10 |
+
@assert_fully_parsed
|
| 11 |
+
def _parse_obs(obs):
|
| 12 |
+
return {
|
| 13 |
+
'hand_pos': obs[:3],
|
| 14 |
+
'hand_closed': obs[3],
|
| 15 |
+
'button_pos': obs[4:7],
|
| 16 |
+
'unused_info': obs[7:],
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
def get_action(self, obs):
|
| 20 |
+
o_d = self._parse_obs(obs)
|
| 21 |
+
|
| 22 |
+
action = Action({
|
| 23 |
+
'delta_pos': np.arange(3),
|
| 24 |
+
'grab_effort': 3
|
| 25 |
+
})
|
| 26 |
+
|
| 27 |
+
action['delta_pos'] = move(o_d['hand_pos'], to_xyz=self._desired_pos(o_d), p=25.)
|
| 28 |
+
action['grab_effort'] = -1.
|
| 29 |
+
|
| 30 |
+
return action.array
|
| 31 |
+
|
| 32 |
+
@staticmethod
|
| 33 |
+
def _desired_pos(o_d):
|
| 34 |
+
pos_curr = o_d['hand_pos']
|
| 35 |
+
pos_button = o_d['button_pos'] + np.array([.0, -.06, .0])
|
| 36 |
+
|
| 37 |
+
if np.linalg.norm(pos_curr[:2] - pos_button[:2]) > 0.04:
|
| 38 |
+
return pos_button + np.array([0., 0., 0.1])
|
| 39 |
+
else:
|
| 40 |
+
return pos_button
|
Metaworld/metaworld/policies/sawyer_button_press_v2_policy.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from metaworld.policies.action import Action
|
| 4 |
+
from metaworld.policies.policy import Policy, move
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class SawyerButtonPressV2Policy(Policy):
|
| 8 |
+
|
| 9 |
+
@staticmethod
|
| 10 |
+
def _parse_obs(obs):
|
| 11 |
+
return {
|
| 12 |
+
'hand_pos': obs[:3],
|
| 13 |
+
'hand_closed': obs[3],
|
| 14 |
+
'button_pos': obs[4:7],
|
| 15 |
+
'unused_info': obs[7:],
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
def get_action(self, obs):
|
| 19 |
+
o_d = self._parse_obs(obs)
|
| 20 |
+
|
| 21 |
+
action = Action({
|
| 22 |
+
'delta_pos': np.arange(3),
|
| 23 |
+
'grab_effort': 3
|
| 24 |
+
})
|
| 25 |
+
|
| 26 |
+
action['delta_pos'] = move(o_d['hand_pos'], to_xyz=self.desired_pos(o_d), p=25.)
|
| 27 |
+
action['grab_effort'] = 0.
|
| 28 |
+
|
| 29 |
+
return action.array
|
| 30 |
+
|
| 31 |
+
@staticmethod
|
| 32 |
+
def desired_pos(o_d):
|
| 33 |
+
pos_curr = o_d['hand_pos']
|
| 34 |
+
pos_button = o_d['button_pos'] + np.array([0., 0., -0.07])
|
| 35 |
+
|
| 36 |
+
# align the gripper with the button if the gripper does not have
|
| 37 |
+
# the same x and z position as the button.
|
| 38 |
+
hand_x, hand_y, hand_z = pos_curr
|
| 39 |
+
button_initial_x, button_initial_y, button_initial_z = pos_button
|
| 40 |
+
if not np.all(np.isclose(np.array([hand_x, hand_z]),
|
| 41 |
+
np.array([button_initial_x, button_initial_z]),
|
| 42 |
+
atol=0.02)):
|
| 43 |
+
pos_button[1] = pos_curr[1] - .1
|
| 44 |
+
return pos_button
|
| 45 |
+
# if the hand is aligned with the button, push the button in, by
|
| 46 |
+
# increasing the hand's y position
|
| 47 |
+
pos_button[1] += 0.02
|
| 48 |
+
|
| 49 |
+
return pos_button
|
Metaworld/metaworld/policies/sawyer_button_press_wall_v1_policy.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from metaworld.policies.action import Action
|
| 4 |
+
from metaworld.policies.policy import Policy, move
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class SawyerButtonPressWallV1Policy(Policy):
|
| 8 |
+
|
| 9 |
+
@staticmethod
|
| 10 |
+
def _parse_obs(obs):
|
| 11 |
+
return {
|
| 12 |
+
'hand_pos': obs[:3],
|
| 13 |
+
'button_pos': obs[3:6],
|
| 14 |
+
'unused_info': obs[6:],
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
def get_action(self, obs):
|
| 18 |
+
o_d = self._parse_obs(obs)
|
| 19 |
+
|
| 20 |
+
action = Action({
|
| 21 |
+
'delta_pos': np.arange(3),
|
| 22 |
+
'grab_effort': 3
|
| 23 |
+
})
|
| 24 |
+
|
| 25 |
+
action['delta_pos'] = move(o_d['hand_pos'], to_xyz=self._desired_pos(o_d), p=15.)
|
| 26 |
+
action['grab_effort'] = self._grab_effort(o_d)
|
| 27 |
+
|
| 28 |
+
return action.array
|
| 29 |
+
|
| 30 |
+
@staticmethod
|
| 31 |
+
def _desired_pos(o_d):
|
| 32 |
+
pos_curr = o_d['hand_pos']
|
| 33 |
+
pos_button = o_d['button_pos'] + np.array([.0, .0, .04])
|
| 34 |
+
|
| 35 |
+
if abs(pos_curr[0] - pos_button[0]) > 0.02:
|
| 36 |
+
return np.array([pos_button[0], pos_curr[1], .3])
|
| 37 |
+
elif pos_button[1] - pos_curr[1] > 0.09:
|
| 38 |
+
return np.array([pos_button[0], pos_button[1], .3])
|
| 39 |
+
elif abs(pos_curr[2] - pos_button[2]) > 0.02:
|
| 40 |
+
return pos_button + np.array([.0, -.05, .0])
|
| 41 |
+
else:
|
| 42 |
+
return pos_button + np.array([.0, -.02, .0])
|
| 43 |
+
|
| 44 |
+
@staticmethod
|
| 45 |
+
def _grab_effort(o_d):
|
| 46 |
+
pos_curr = o_d['hand_pos']
|
| 47 |
+
pos_button = o_d['button_pos'] + np.array([.0, .0, .04])
|
| 48 |
+
|
| 49 |
+
if abs(pos_curr[0] - pos_button[0]) > 0.02 or \
|
| 50 |
+
pos_button[1] - pos_curr[1] > 0.09 or \
|
| 51 |
+
abs(pos_curr[2] - pos_button[2]) > 0.02:
|
| 52 |
+
return 1.
|
| 53 |
+
else:
|
| 54 |
+
return -1.
|
Metaworld/metaworld/policies/sawyer_button_press_wall_v2_policy.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from metaworld.policies.action import Action
|
| 4 |
+
from metaworld.policies.policy import Policy, move
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class SawyerButtonPressWallV2Policy(Policy):
|
| 8 |
+
|
| 9 |
+
@staticmethod
|
| 10 |
+
def _parse_obs(obs):
|
| 11 |
+
return {
|
| 12 |
+
'hand_pos': obs[:3],
|
| 13 |
+
'hand_closed': obs[3],
|
| 14 |
+
'button_pos': obs[4:7],
|
| 15 |
+
'unused_info': obs[7:],
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
def get_action(self, obs):
|
| 19 |
+
o_d = self._parse_obs(obs)
|
| 20 |
+
|
| 21 |
+
action = Action({
|
| 22 |
+
'delta_pos': np.arange(3),
|
| 23 |
+
'grab_effort': 3
|
| 24 |
+
})
|
| 25 |
+
|
| 26 |
+
action['delta_pos'] = move(o_d['hand_pos'], to_xyz=self._desired_pos(o_d), p=15.)
|
| 27 |
+
action['grab_effort'] = self._grab_effort(o_d)
|
| 28 |
+
|
| 29 |
+
return action.array
|
| 30 |
+
|
| 31 |
+
@staticmethod
|
| 32 |
+
def _desired_pos(o_d):
|
| 33 |
+
pos_curr = o_d['hand_pos']
|
| 34 |
+
pos_button = o_d['button_pos'] + np.array([.0, .0, .04])
|
| 35 |
+
|
| 36 |
+
if abs(pos_curr[0] - pos_button[0]) > 0.02:
|
| 37 |
+
return np.array([pos_button[0], pos_curr[1], .3])
|
| 38 |
+
elif pos_button[1] - pos_curr[1] > 0.09:
|
| 39 |
+
return np.array([pos_button[0], pos_button[1], .3])
|
| 40 |
+
elif abs(pos_curr[2] - pos_button[2]) > 0.02:
|
| 41 |
+
return pos_button + np.array([.0, -.05, .0])
|
| 42 |
+
else:
|
| 43 |
+
return pos_button + np.array([.0, -.02, .0])
|
| 44 |
+
|
| 45 |
+
@staticmethod
|
| 46 |
+
def _grab_effort(o_d):
|
| 47 |
+
pos_curr = o_d['hand_pos']
|
| 48 |
+
pos_button = o_d['button_pos'] + np.array([.0, .0, .04])
|
| 49 |
+
|
| 50 |
+
if abs(pos_curr[0] - pos_button[0]) > 0.02 or \
|
| 51 |
+
pos_button[1] - pos_curr[1] > 0.09 or \
|
| 52 |
+
abs(pos_curr[2] - pos_button[2]) > 0.02:
|
| 53 |
+
return 1.
|
| 54 |
+
else:
|
| 55 |
+
return -1.
|
Metaworld/metaworld/policies/sawyer_coffee_button_v2_policy.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from metaworld.policies.action import Action
|
| 4 |
+
from metaworld.policies.policy import Policy, assert_fully_parsed, move
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class SawyerCoffeeButtonV2Policy(Policy):
|
| 8 |
+
|
| 9 |
+
@staticmethod
|
| 10 |
+
@assert_fully_parsed
|
| 11 |
+
def _parse_obs(obs):
|
| 12 |
+
return {
|
| 13 |
+
'hand_pos': obs[:3],
|
| 14 |
+
'gripper': obs[3],
|
| 15 |
+
'button_pos': obs[4:7],
|
| 16 |
+
'unused_info': obs[7:],
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
def get_action(self, obs):
|
| 20 |
+
o_d = self._parse_obs(obs)
|
| 21 |
+
|
| 22 |
+
action = Action({
|
| 23 |
+
'delta_pos': np.arange(3),
|
| 24 |
+
'grab_effort': 3
|
| 25 |
+
})
|
| 26 |
+
|
| 27 |
+
action['delta_pos'] = move(o_d['hand_pos'], to_xyz=self._desired_pos(o_d), p=10.)
|
| 28 |
+
action['grab_effort'] = -1.
|
| 29 |
+
|
| 30 |
+
return action.array
|
| 31 |
+
|
| 32 |
+
@staticmethod
|
| 33 |
+
def _desired_pos(o_d):
|
| 34 |
+
pos_curr = o_d['hand_pos']
|
| 35 |
+
pos_button = o_d['button_pos'] + np.array([.0, .0, -.07])
|
| 36 |
+
|
| 37 |
+
if np.linalg.norm(pos_curr[[0, 2]] - pos_button[[0, 2]]) > 0.02:
|
| 38 |
+
return np.array([pos_button[0], pos_curr[1], pos_button[2]])
|
| 39 |
+
else:
|
| 40 |
+
return pos_button + np.array([.0, .2, .0])
|
Metaworld/metaworld/policies/sawyer_coffee_push_v2_policy.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from metaworld.policies.action import Action
|
| 4 |
+
from metaworld.policies.policy import Policy, assert_fully_parsed, move
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class SawyerCoffeePushV2Policy(Policy):
|
| 8 |
+
|
| 9 |
+
@staticmethod
|
| 10 |
+
@assert_fully_parsed
|
| 11 |
+
def _parse_obs(obs):
|
| 12 |
+
return {
|
| 13 |
+
'hand_pos': obs[:3],
|
| 14 |
+
'gripper': obs[3],
|
| 15 |
+
'mug_pos': obs[4:7],
|
| 16 |
+
'goal_xy': obs[-3:-1],
|
| 17 |
+
'unused_info_1': obs[7:-3],
|
| 18 |
+
'unused_info_2': obs[-1],
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
def get_action(self, obs):
|
| 22 |
+
o_d = self._parse_obs(obs)
|
| 23 |
+
|
| 24 |
+
action = Action({
|
| 25 |
+
'delta_pos': np.arange(3),
|
| 26 |
+
'grab_effort': 3
|
| 27 |
+
})
|
| 28 |
+
|
| 29 |
+
action['delta_pos'] = move(o_d['hand_pos'], to_xyz=self._desired_pos(o_d), p=10.)
|
| 30 |
+
action['grab_effort'] = self._grab_effort(o_d)
|
| 31 |
+
|
| 32 |
+
return action.array
|
| 33 |
+
|
| 34 |
+
@staticmethod
|
| 35 |
+
def _desired_pos(o_d):
|
| 36 |
+
pos_curr = o_d['hand_pos']
|
| 37 |
+
pos_mug = o_d['mug_pos'] + np.array([.01, .0, .05])
|
| 38 |
+
pos_goal = o_d['goal_xy']
|
| 39 |
+
|
| 40 |
+
if np.linalg.norm(pos_curr[:2] - pos_mug[:2]) > 0.06:
|
| 41 |
+
return pos_mug + np.array([.0, .0, .2])
|
| 42 |
+
elif abs(pos_curr[2] - pos_mug[2]) > 0.02:
|
| 43 |
+
return pos_mug
|
| 44 |
+
else:
|
| 45 |
+
return np.array([pos_goal[0], pos_goal[1], .1])
|
| 46 |
+
|
| 47 |
+
@staticmethod
|
| 48 |
+
def _grab_effort(o_d):
|
| 49 |
+
pos_curr = o_d['hand_pos']
|
| 50 |
+
pos_mug = o_d['mug_pos'] + np.array([.01, .0, .05])
|
| 51 |
+
|
| 52 |
+
if np.linalg.norm(pos_curr[:2] - pos_mug[:2]) > 0.06 or \
|
| 53 |
+
abs(pos_curr[2] - pos_mug[2]) > 0.1:
|
| 54 |
+
return -1.
|
| 55 |
+
else:
|
| 56 |
+
return .5
|
Metaworld/metaworld/policies/sawyer_dial_turn_v1_policy.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from metaworld.policies.action import Action
|
| 4 |
+
from metaworld.policies.policy import Policy, assert_fully_parsed, move
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class SawyerDialTurnV1Policy(Policy):
|
| 8 |
+
|
| 9 |
+
@staticmethod
|
| 10 |
+
@assert_fully_parsed
|
| 11 |
+
def _parse_obs(obs):
|
| 12 |
+
return {
|
| 13 |
+
'hand_pos': obs[:3],
|
| 14 |
+
'dial_pos': obs[3:6],
|
| 15 |
+
'goal_pos': obs[6:],
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
def get_action(self, obs):
|
| 19 |
+
o_d = self._parse_obs(obs)
|
| 20 |
+
|
| 21 |
+
action = Action({
|
| 22 |
+
'delta_pos': np.arange(3),
|
| 23 |
+
'grab_pow': 3
|
| 24 |
+
})
|
| 25 |
+
|
| 26 |
+
action['delta_pos'] = move(o_d['hand_pos'], to_xyz=self._desired_xyz(o_d), p=5.)
|
| 27 |
+
action['grab_pow'] = 0.
|
| 28 |
+
|
| 29 |
+
return action.array
|
| 30 |
+
|
| 31 |
+
@staticmethod
|
| 32 |
+
def _desired_xyz(o_d):
|
| 33 |
+
hand_pos = o_d['hand_pos']
|
| 34 |
+
dial_pos = o_d['dial_pos'] + np.array([0.0, -0.028, 0.0])
|
| 35 |
+
if abs(hand_pos[2] - dial_pos[2]) > 0.02:
|
| 36 |
+
return np.array([hand_pos[0], hand_pos[1], dial_pos[2]])
|
| 37 |
+
elif abs(hand_pos[1] - dial_pos[1]) > 0.02:
|
| 38 |
+
return np.array([dial_pos[0]+0.20, dial_pos[1], dial_pos[2]])
|
| 39 |
+
return np.array([dial_pos[0]-0.10, dial_pos[1], dial_pos[2]])
|
Metaworld/metaworld/policies/sawyer_dial_turn_v2_policy.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from metaworld.policies.action import Action
|
| 4 |
+
from metaworld.policies.policy import Policy, assert_fully_parsed, move
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class SawyerDialTurnV2Policy(Policy):
|
| 8 |
+
|
| 9 |
+
@staticmethod
|
| 10 |
+
@assert_fully_parsed
|
| 11 |
+
def _parse_obs(obs):
|
| 12 |
+
return {
|
| 13 |
+
'hand_pos': obs[:3],
|
| 14 |
+
'unused_gripper_open': obs[3],
|
| 15 |
+
'dial_pos': obs[4:7],
|
| 16 |
+
'extra_info': obs[7:],
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
def get_action(self, obs):
|
| 20 |
+
o_d = self._parse_obs(obs)
|
| 21 |
+
|
| 22 |
+
action = Action({
|
| 23 |
+
'delta_pos': np.arange(3),
|
| 24 |
+
'grab_pow': 3
|
| 25 |
+
})
|
| 26 |
+
|
| 27 |
+
action['delta_pos'] = move(o_d['hand_pos'], to_xyz=self._desired_pos(o_d), p=10.)
|
| 28 |
+
action['grab_pow'] = 1.
|
| 29 |
+
|
| 30 |
+
return action.array
|
| 31 |
+
|
| 32 |
+
@staticmethod
|
| 33 |
+
def _desired_pos(o_d):
|
| 34 |
+
hand_pos = o_d['hand_pos']
|
| 35 |
+
dial_pos = o_d['dial_pos'] + np.array([0.05, 0.02, 0.09])
|
| 36 |
+
|
| 37 |
+
if np.linalg.norm(hand_pos[:2] - dial_pos[:2]) > 0.02:
|
| 38 |
+
return np.array([*dial_pos[:2], 0.2])
|
| 39 |
+
if abs(hand_pos[2] - dial_pos[2]) > 0.02:
|
| 40 |
+
return dial_pos
|
| 41 |
+
return dial_pos + np.array([-.05, .005, .0])
|
Metaworld/metaworld/policies/sawyer_disassemble_v1_policy.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from metaworld.policies.action import Action
|
| 4 |
+
from metaworld.policies.policy import Policy, assert_fully_parsed, move
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class SawyerDisassembleV1Policy(Policy):
|
| 8 |
+
|
| 9 |
+
@staticmethod
|
| 10 |
+
@assert_fully_parsed
|
| 11 |
+
def _parse_obs(obs):
|
| 12 |
+
return {
|
| 13 |
+
'hand_pos': obs[:3],
|
| 14 |
+
'wrench_pos': obs[3:6],
|
| 15 |
+
'peg_pos': obs[9:],
|
| 16 |
+
'unused_info': obs[6:9],
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
def get_action(self, obs):
|
| 20 |
+
o_d = self._parse_obs(obs)
|
| 21 |
+
|
| 22 |
+
action = Action({
|
| 23 |
+
'delta_pos': np.arange(3),
|
| 24 |
+
'grab_effort': 3
|
| 25 |
+
})
|
| 26 |
+
|
| 27 |
+
action['delta_pos'] = move(o_d['hand_pos'], to_xyz=self._desired_pos(o_d), p=10.)
|
| 28 |
+
action['grab_effort'] = self._grab_effort(o_d)
|
| 29 |
+
|
| 30 |
+
return action.array
|
| 31 |
+
|
| 32 |
+
@staticmethod
|
| 33 |
+
def _desired_pos(o_d):
|
| 34 |
+
pos_curr = o_d['hand_pos']
|
| 35 |
+
pos_wrench = o_d['wrench_pos'] + np.array([.01, -.01, .01])
|
| 36 |
+
pos_peg = o_d['peg_pos'] + np.array([.07, .0, .15])
|
| 37 |
+
|
| 38 |
+
# If XY error is greater than 0.02, place end effector above the wrench
|
| 39 |
+
if np.linalg.norm(pos_curr[:2] - pos_wrench[:2]) > 0.02:
|
| 40 |
+
return pos_wrench + np.array([0., 0., 0.12])
|
| 41 |
+
# Once XY error is low enough, drop end effector down on top of wrench
|
| 42 |
+
elif abs(pos_curr[2] - pos_wrench[2]) > 0.03:
|
| 43 |
+
return pos_wrench
|
| 44 |
+
# If still hooked on peg, move upwards
|
| 45 |
+
elif pos_wrench[2] < 0.12:
|
| 46 |
+
return pos_peg + np.array([.0, .0, .1])
|
| 47 |
+
# Move away from peg
|
| 48 |
+
else:
|
| 49 |
+
return pos_curr + np.array([.0, -.1, .0])
|
| 50 |
+
|
| 51 |
+
@staticmethod
|
| 52 |
+
def _grab_effort(o_d):
|
| 53 |
+
pos_curr = o_d['hand_pos']
|
| 54 |
+
pos_wrench = o_d['wrench_pos'] + np.array([.01, .0, .0])
|
| 55 |
+
|
| 56 |
+
if np.linalg.norm(pos_curr[:2] - pos_wrench[:2]) > 0.02 or abs(pos_curr[2] - pos_wrench[2]) > 0.08:
|
| 57 |
+
return 0.
|
| 58 |
+
else:
|
| 59 |
+
return 0.8
|
Metaworld/metaworld/policies/sawyer_disassemble_v2_policy.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from metaworld.policies.action import Action
|
| 4 |
+
from metaworld.policies.policy import Policy, assert_fully_parsed, move
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class SawyerDisassembleV2Policy(Policy):
|
| 8 |
+
|
| 9 |
+
@staticmethod
|
| 10 |
+
@assert_fully_parsed
|
| 11 |
+
def _parse_obs(obs):
|
| 12 |
+
return {
|
| 13 |
+
'hand_pos': obs[:3],
|
| 14 |
+
'gripper': obs[3],
|
| 15 |
+
'wrench_pos': obs[4:7],
|
| 16 |
+
'peg_pos': obs[-3:],
|
| 17 |
+
'unused_info': obs[7:-3],
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
def get_action(self, obs):
|
| 21 |
+
o_d = self._parse_obs(obs)
|
| 22 |
+
|
| 23 |
+
action = Action({
|
| 24 |
+
'delta_pos': np.arange(3),
|
| 25 |
+
'grab_effort': 3
|
| 26 |
+
})
|
| 27 |
+
|
| 28 |
+
action['delta_pos'] = move(o_d['hand_pos'], to_xyz=self._desired_pos(o_d), p=10.)
|
| 29 |
+
action['grab_effort'] = self._grab_effort(o_d)
|
| 30 |
+
|
| 31 |
+
return action.array
|
| 32 |
+
|
| 33 |
+
@staticmethod
|
| 34 |
+
def _desired_pos(o_d):
|
| 35 |
+
pos_curr = o_d['hand_pos']
|
| 36 |
+
pos_wrench = o_d['wrench_pos'] + np.array([-.02, .0, .01])
|
| 37 |
+
pos_peg = o_d['peg_pos'] + np.array([.12, .0, .14])
|
| 38 |
+
|
| 39 |
+
# If XY error is greater than 0.02, place end effector above the wrench
|
| 40 |
+
if np.linalg.norm(pos_curr[:2] - pos_wrench[:2]) > 0.02:
|
| 41 |
+
return pos_wrench + np.array([0., 0., 0.1])
|
| 42 |
+
# Once XY error is low enough, drop end effector down on top of wrench
|
| 43 |
+
elif abs(pos_curr[2] - pos_wrench[2]) > 0.03:
|
| 44 |
+
return pos_wrench
|
| 45 |
+
# Move upwards
|
| 46 |
+
else:
|
| 47 |
+
return pos_curr + np.array([.0, .0, .1])
|
| 48 |
+
|
| 49 |
+
@staticmethod
|
| 50 |
+
def _grab_effort(o_d):
|
| 51 |
+
pos_curr = o_d['hand_pos']
|
| 52 |
+
pos_wrench = o_d['wrench_pos'] + np.array([-.02, .0, .01])
|
| 53 |
+
|
| 54 |
+
if np.linalg.norm(pos_curr[:2] - pos_wrench[:2]) > 0.02 or abs(pos_curr[2] - pos_wrench[2]) > 0.07:
|
| 55 |
+
return 0.
|
| 56 |
+
else:
|
| 57 |
+
return 0.8
|
Metaworld/metaworld/policies/sawyer_door_close_v2_policy.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from metaworld.policies.action import Action
|
| 4 |
+
from metaworld.policies.policy import Policy, assert_fully_parsed, move
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class SawyerDoorCloseV2Policy(Policy):
|
| 8 |
+
|
| 9 |
+
@staticmethod
|
| 10 |
+
@assert_fully_parsed
|
| 11 |
+
def _parse_obs(obs):
|
| 12 |
+
return {
|
| 13 |
+
'hand_pos': obs[:3],
|
| 14 |
+
'unused_1': obs[3],
|
| 15 |
+
'door_pos': obs[4:7],
|
| 16 |
+
'unused_2': obs[7:-3],
|
| 17 |
+
'goal_pos': obs[-3:],
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
def get_action(self, obs):
|
| 21 |
+
o_d = self._parse_obs(obs)
|
| 22 |
+
|
| 23 |
+
action = Action({
|
| 24 |
+
'delta_pos': np.arange(3),
|
| 25 |
+
'grab_effort': 3
|
| 26 |
+
})
|
| 27 |
+
|
| 28 |
+
action['delta_pos'] = move(o_d['hand_pos'], to_xyz=self._desired_pos(o_d), p=25.)
|
| 29 |
+
action['grab_effort'] = 1.
|
| 30 |
+
|
| 31 |
+
return action.array
|
| 32 |
+
|
| 33 |
+
@staticmethod
|
| 34 |
+
def _desired_pos(o_d):
|
| 35 |
+
pos_curr = o_d['hand_pos']
|
| 36 |
+
pos_door = o_d['door_pos']
|
| 37 |
+
pos_door += np.array([0.05, 0.12, 0.1])
|
| 38 |
+
pos_goal = o_d['goal_pos']
|
| 39 |
+
|
| 40 |
+
# # if to the right of door handle///
|
| 41 |
+
# if pos_curr[0] > pos_door[0]:
|
| 42 |
+
# # if below door handle by more than 0.2
|
| 43 |
+
# if pos_curr[2] < pos_door[2] + 0.2:
|
| 44 |
+
# # rise above door handle by ~0.2
|
| 45 |
+
# return np.array([pos_curr[0], pos_curr[1], pos_door[2] + 0.25])
|
| 46 |
+
# else:
|
| 47 |
+
# # move toward door handle in XY plane
|
| 48 |
+
# return np.array([pos_door[0] - 0.02, pos_door[1], pos_curr[2]])
|
| 49 |
+
# # put end effector on the outer edge of door handle (still above it)
|
| 50 |
+
# elif abs(pos_curr[2] - pos_door[2]) > 0.04:
|
| 51 |
+
# return pos_door + np.array([-0.02, 0., 0.])
|
| 52 |
+
# # push from outer edge toward door handle's centroid
|
| 53 |
+
# else:
|
| 54 |
+
return pos_goal
|
Metaworld/metaworld/policies/sawyer_drawer_close_v1_policy.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from metaworld.policies.action import Action
|
| 4 |
+
from metaworld.policies.policy import Policy, assert_fully_parsed, move
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class SawyerDrawerCloseV1Policy(Policy):
|
| 8 |
+
|
| 9 |
+
@staticmethod
|
| 10 |
+
@assert_fully_parsed
|
| 11 |
+
def _parse_obs(obs):
|
| 12 |
+
return {
|
| 13 |
+
'hand_pos': obs[:3],
|
| 14 |
+
'drwr_pos': obs[3:6],
|
| 15 |
+
'unused_info': obs[6:],
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
def get_action(self, obs):
|
| 19 |
+
o_d = self._parse_obs(obs)
|
| 20 |
+
|
| 21 |
+
action = Action({
|
| 22 |
+
'delta_pos': np.arange(3),
|
| 23 |
+
'grab_effort': 3
|
| 24 |
+
})
|
| 25 |
+
|
| 26 |
+
action['delta_pos'] = move(o_d['hand_pos'], to_xyz=self._desired_pos(o_d), p=10.)
|
| 27 |
+
action['grab_effort'] = 1.
|
| 28 |
+
|
| 29 |
+
return action.array
|
| 30 |
+
|
| 31 |
+
@staticmethod
|
| 32 |
+
def _desired_pos(o_d):
|
| 33 |
+
pos_curr = o_d['hand_pos']
|
| 34 |
+
pos_drwr = o_d['drwr_pos']
|
| 35 |
+
|
| 36 |
+
# if further forward than the drawer...
|
| 37 |
+
if pos_curr[1] > pos_drwr[1]:
|
| 38 |
+
if pos_curr[2] < pos_drwr[2] + 0.4:
|
| 39 |
+
# rise up quickly (Z direction)
|
| 40 |
+
return np.array([pos_curr[0], pos_curr[1], pos_drwr[2] + 0.5])
|
| 41 |
+
else:
|
| 42 |
+
# move to front edge of drawer handle, but stay high in Z
|
| 43 |
+
return pos_drwr + np.array([0., -0.075, 0.4])
|
| 44 |
+
# drop down to touch drawer handle
|
| 45 |
+
elif abs(pos_curr[2] - pos_drwr[2]) > 0.04:
|
| 46 |
+
return pos_drwr + np.array([0., -0.075, 0.])
|
| 47 |
+
# push toward drawer handle's centroid
|
| 48 |
+
else:
|
| 49 |
+
return pos_drwr
|
Metaworld/metaworld/policies/sawyer_drawer_close_v2_policy.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from metaworld.policies.action import Action
|
| 4 |
+
from metaworld.policies.policy import Policy, assert_fully_parsed, move
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class SawyerDrawerCloseV2Policy(Policy):
|
| 8 |
+
|
| 9 |
+
@staticmethod
|
| 10 |
+
@assert_fully_parsed
|
| 11 |
+
def _parse_obs(obs):
|
| 12 |
+
return {
|
| 13 |
+
'hand_pos': obs[:3],
|
| 14 |
+
'unused_grasp_info': obs[3],
|
| 15 |
+
'drwr_pos': obs[4:7],
|
| 16 |
+
'unused_info': obs[7:],
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
def get_action(self, obs):
|
| 20 |
+
o_d = self._parse_obs(obs)
|
| 21 |
+
|
| 22 |
+
action = Action({
|
| 23 |
+
'delta_pos': np.arange(3),
|
| 24 |
+
'grab_effort': 3
|
| 25 |
+
})
|
| 26 |
+
|
| 27 |
+
action['delta_pos'] = move(o_d['hand_pos'], to_xyz=self._desired_pos(o_d), p=25.)
|
| 28 |
+
action['grab_effort'] = 1.
|
| 29 |
+
|
| 30 |
+
return action.array
|
| 31 |
+
|
| 32 |
+
@staticmethod
|
| 33 |
+
def _desired_pos(o_d):
|
| 34 |
+
pos_curr = o_d['hand_pos']
|
| 35 |
+
pos_drwr = o_d['drwr_pos'] + np.array([.0, .0, -.02])
|
| 36 |
+
|
| 37 |
+
# if further forward than the drawer...
|
| 38 |
+
if pos_curr[1] > pos_drwr[1]:
|
| 39 |
+
if pos_curr[2] < pos_drwr[2] + 0.23:
|
| 40 |
+
# rise up quickly (Z direction)
|
| 41 |
+
return np.array([pos_curr[0], pos_curr[1], pos_drwr[2] + 0.5])
|
| 42 |
+
else:
|
| 43 |
+
# move to front edge of drawer handle, but stay high in Z
|
| 44 |
+
return pos_drwr + np.array([0., -0.075, 0.23])
|
| 45 |
+
# drop down to touch drawer handle
|
| 46 |
+
elif abs(pos_curr[2] - pos_drwr[2]) > 0.04:
|
| 47 |
+
return pos_drwr + np.array([0., -0.075, 0.])
|
| 48 |
+
# push toward drawer handle's centroid
|
| 49 |
+
else:
|
| 50 |
+
return pos_drwr
|
Metaworld/metaworld/policies/sawyer_drawer_open_v1_policy.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from metaworld.policies.action import Action
|
| 4 |
+
from metaworld.policies.policy import Policy, assert_fully_parsed, move
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class SawyerDrawerOpenV1Policy(Policy):
|
| 8 |
+
|
| 9 |
+
@staticmethod
|
| 10 |
+
@assert_fully_parsed
|
| 11 |
+
def _parse_obs(obs):
|
| 12 |
+
return {
|
| 13 |
+
'hand_pos': obs[:3],
|
| 14 |
+
'drwr_pos': obs[3:6],
|
| 15 |
+
'unused_info': obs[6:],
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
def get_action(self, obs):
|
| 19 |
+
o_d = self._parse_obs(obs)
|
| 20 |
+
|
| 21 |
+
action = Action({
|
| 22 |
+
'delta_pos': np.arange(3),
|
| 23 |
+
'grab_effort': 3
|
| 24 |
+
})
|
| 25 |
+
|
| 26 |
+
# NOTE this policy looks different from the others because it must
|
| 27 |
+
# modify its p constant part-way through the task
|
| 28 |
+
pos_curr = o_d['hand_pos']
|
| 29 |
+
pos_drwr = o_d['drwr_pos']
|
| 30 |
+
|
| 31 |
+
# align end effector's Z axis with drawer handle's Z axis
|
| 32 |
+
if np.linalg.norm(pos_curr[:2] - pos_drwr[:2]) > 0.06:
|
| 33 |
+
to_pos = pos_drwr + np.array([0., 0., 0.3])
|
| 34 |
+
action['delta_pos'] = move(o_d['hand_pos'], to_pos, p=4.)
|
| 35 |
+
# drop down to touch drawer handle
|
| 36 |
+
elif abs(pos_curr[2] - pos_drwr[2]) > 0.04:
|
| 37 |
+
to_pos = pos_drwr
|
| 38 |
+
action['delta_pos'] = move(o_d['hand_pos'], to_pos, p=4.)
|
| 39 |
+
# push toward a point just behind the drawer handle
|
| 40 |
+
# also increase p value to apply more force
|
| 41 |
+
else:
|
| 42 |
+
to_pos = pos_drwr + np.array([0., -0.06, 0.])
|
| 43 |
+
action['delta_pos'] = move(o_d['hand_pos'], to_pos, p=50.)
|
| 44 |
+
|
| 45 |
+
# keep gripper open
|
| 46 |
+
action['grab_effort'] = -1.
|
| 47 |
+
|
| 48 |
+
return action.array
|
Metaworld/metaworld/policies/sawyer_faucet_close_v1_policy.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from metaworld.policies.action import Action
|
| 4 |
+
from metaworld.policies.policy import Policy, assert_fully_parsed, move
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class SawyerFaucetCloseV1Policy(Policy):
|
| 8 |
+
|
| 9 |
+
@staticmethod
|
| 10 |
+
@assert_fully_parsed
|
| 11 |
+
def _parse_obs(obs):
|
| 12 |
+
return {
|
| 13 |
+
'hand_pos': obs[:3],
|
| 14 |
+
'faucet_pos': obs[3:6],
|
| 15 |
+
'unused_info': obs[6:],
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
def get_action(self, obs):
|
| 19 |
+
o_d = self._parse_obs(obs)
|
| 20 |
+
|
| 21 |
+
action = Action({
|
| 22 |
+
'delta_pos': np.arange(3),
|
| 23 |
+
'grab_effort': 3
|
| 24 |
+
})
|
| 25 |
+
|
| 26 |
+
action['delta_pos'] = move(o_d['hand_pos'], to_xyz=self._desired_pos(o_d), p=25.)
|
| 27 |
+
action['grab_effort'] = 1.
|
| 28 |
+
|
| 29 |
+
return action.array
|
| 30 |
+
|
| 31 |
+
@staticmethod
|
| 32 |
+
def _desired_pos(o_d):
|
| 33 |
+
pos_curr = o_d['hand_pos']
|
| 34 |
+
pos_faucet = o_d['faucet_pos'] + np.array([.02, .0, .0])
|
| 35 |
+
|
| 36 |
+
if np.linalg.norm(pos_curr[:2] - pos_faucet[:2]) > 0.04:
|
| 37 |
+
return pos_faucet + np.array([.0, .0, .1])
|
| 38 |
+
elif abs(pos_curr[2] - pos_faucet[2]) > 0.04:
|
| 39 |
+
return pos_faucet
|
| 40 |
+
else:
|
| 41 |
+
return pos_faucet + np.array([-.1, .05, .0])
|
Metaworld/metaworld/policies/sawyer_faucet_open_v2_policy.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from metaworld.policies.action import Action
|
| 4 |
+
from metaworld.policies.policy import Policy, assert_fully_parsed, move
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class SawyerFaucetOpenV2Policy(Policy):
|
| 8 |
+
|
| 9 |
+
@staticmethod
|
| 10 |
+
@assert_fully_parsed
|
| 11 |
+
def _parse_obs(obs):
|
| 12 |
+
return {
|
| 13 |
+
'hand_pos': obs[:3],
|
| 14 |
+
'unused_gripper': obs[3],
|
| 15 |
+
'faucet_pos': obs[4:7],
|
| 16 |
+
'unused_info': obs[7:],
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
def get_action(self, obs):
|
| 20 |
+
o_d = self._parse_obs(obs)
|
| 21 |
+
|
| 22 |
+
action = Action({
|
| 23 |
+
'delta_pos': np.arange(3),
|
| 24 |
+
'grab_effort': 3
|
| 25 |
+
})
|
| 26 |
+
|
| 27 |
+
action['delta_pos'] = move(o_d['hand_pos'], to_xyz=self._desired_pos(o_d), p=25.)
|
| 28 |
+
action['grab_effort'] = 1.
|
| 29 |
+
|
| 30 |
+
return action.array
|
| 31 |
+
|
| 32 |
+
@staticmethod
|
| 33 |
+
def _desired_pos(o_d):
|
| 34 |
+
pos_curr = o_d['hand_pos']
|
| 35 |
+
pos_faucet = o_d['faucet_pos'] + np.array([-.04, .0, .03])
|
| 36 |
+
|
| 37 |
+
if np.linalg.norm(pos_curr[:2] - pos_faucet[:2]) > 0.04:
|
| 38 |
+
return pos_faucet + np.array([.0, .0, .1])
|
| 39 |
+
elif abs(pos_curr[2] - pos_faucet[2]) > 0.04:
|
| 40 |
+
return pos_faucet
|
| 41 |
+
else:
|
| 42 |
+
return pos_faucet + np.array([.1, .05, .0])
|
Metaworld/metaworld/policies/sawyer_hand_insert_v2_policy.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from metaworld.policies.action import Action
|
| 4 |
+
from metaworld.policies.policy import Policy, assert_fully_parsed, move
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class SawyerHandInsertV2Policy(Policy):
|
| 8 |
+
|
| 9 |
+
@staticmethod
|
| 10 |
+
@assert_fully_parsed
|
| 11 |
+
def _parse_obs(obs):
|
| 12 |
+
return {
|
| 13 |
+
'hand_pos': obs[:3],
|
| 14 |
+
'gripper': obs[3],
|
| 15 |
+
'obj_pos': obs[4:7],
|
| 16 |
+
'goal_pos': obs[-3:],
|
| 17 |
+
'unused_info': obs[7:-3],
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
def get_action(self, obs):
|
| 21 |
+
o_d = self._parse_obs(obs)
|
| 22 |
+
|
| 23 |
+
action = Action({
|
| 24 |
+
'delta_pos': np.arange(3),
|
| 25 |
+
'grab_effort': 3
|
| 26 |
+
})
|
| 27 |
+
|
| 28 |
+
action['delta_pos'] = move(o_d['hand_pos'], to_xyz=self._desired_pos(o_d), p=10.)
|
| 29 |
+
action['grab_effort'] = self._grab_effort(o_d)
|
| 30 |
+
|
| 31 |
+
return action.array
|
| 32 |
+
|
| 33 |
+
@staticmethod
|
| 34 |
+
def _desired_pos(o_d):
|
| 35 |
+
hand_pos = o_d['hand_pos']
|
| 36 |
+
obj_pos = o_d['obj_pos']
|
| 37 |
+
goal_pos = o_d['goal_pos']
|
| 38 |
+
|
| 39 |
+
# If error in the XY plane is greater than 0.02, place end effector above the puck
|
| 40 |
+
if np.linalg.norm(hand_pos[:2] - obj_pos[:2]) > 0.02:
|
| 41 |
+
return obj_pos + np.array([0., 0., 0.1])
|
| 42 |
+
# Once XY error is low enough, drop end effector down on top of puck
|
| 43 |
+
elif abs(hand_pos[2] - obj_pos[2]) > 0.05:
|
| 44 |
+
return obj_pos + np.array([0., 0., 0.03])
|
| 45 |
+
# If not above goal, move to be directly above goal
|
| 46 |
+
elif np.linalg.norm(hand_pos[:2] - goal_pos[:2]) > 0.04:
|
| 47 |
+
return np.array([goal_pos[0], goal_pos[1], hand_pos[2]])
|
| 48 |
+
else:
|
| 49 |
+
return goal_pos
|
| 50 |
+
|
| 51 |
+
@staticmethod
|
| 52 |
+
def _grab_effort(o_d):
|
| 53 |
+
hand_pos = o_d['hand_pos']
|
| 54 |
+
obj_pos = o_d['obj_pos']
|
| 55 |
+
|
| 56 |
+
if np.linalg.norm(hand_pos[:2] - obj_pos[:2]) > 0.02 or abs(hand_pos[2] - obj_pos[2]) > 0.1:
|
| 57 |
+
return 0.
|
| 58 |
+
else:
|
| 59 |
+
return 0.65
|
Metaworld/metaworld/policies/sawyer_handle_press_side_v2_policy.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from metaworld.policies.action import Action
|
| 4 |
+
from metaworld.policies.policy import Policy, assert_fully_parsed, move
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class SawyerHandlePressSideV2Policy(Policy):
|
| 8 |
+
|
| 9 |
+
@staticmethod
|
| 10 |
+
@assert_fully_parsed
|
| 11 |
+
def _parse_obs(obs):
|
| 12 |
+
return {
|
| 13 |
+
'hand_pos': obs[:3],
|
| 14 |
+
'gripper': obs[3],
|
| 15 |
+
'handle_pos': obs[4:7],
|
| 16 |
+
'unused_info': obs[7:],
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
def get_action(self, obs):
|
| 20 |
+
o_d = self._parse_obs(obs)
|
| 21 |
+
|
| 22 |
+
action = Action({
|
| 23 |
+
'delta_pos': np.arange(3),
|
| 24 |
+
'grab_effort': 3
|
| 25 |
+
})
|
| 26 |
+
|
| 27 |
+
action['delta_pos'] = move(o_d['hand_pos'], to_xyz=self._desired_pos(o_d), p=25.)
|
| 28 |
+
action['grab_effort'] = 1.
|
| 29 |
+
|
| 30 |
+
return action.array
|
| 31 |
+
|
| 32 |
+
@staticmethod
|
| 33 |
+
def _desired_pos(o_d):
|
| 34 |
+
pos_curr = o_d['hand_pos']
|
| 35 |
+
pos_button = o_d['handle_pos']
|
| 36 |
+
|
| 37 |
+
if np.linalg.norm(pos_curr[:2] - pos_button[:2]) > 0.02:
|
| 38 |
+
return pos_button + np.array([0., 0., 0.2])
|
| 39 |
+
else:
|
| 40 |
+
return pos_button + np.array([.0, .0, -.5])
|
Metaworld/metaworld/policies/sawyer_handle_pull_side_v1_policy.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from metaworld.policies.action import Action
|
| 4 |
+
from metaworld.policies.policy import Policy, assert_fully_parsed, move
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class SawyerHandlePullSideV1Policy(Policy):
|
| 8 |
+
|
| 9 |
+
@staticmethod
|
| 10 |
+
@assert_fully_parsed
|
| 11 |
+
def _parse_obs(obs):
|
| 12 |
+
return {
|
| 13 |
+
'hand_pos': obs[:3],
|
| 14 |
+
'handle_pos': obs[3:6],
|
| 15 |
+
'unused_info': obs[6:],
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
def get_action(self, obs):
|
| 19 |
+
o_d = self._parse_obs(obs)
|
| 20 |
+
|
| 21 |
+
action = Action({
|
| 22 |
+
'delta_pos': np.arange(3),
|
| 23 |
+
'grab_effort': 3
|
| 24 |
+
})
|
| 25 |
+
|
| 26 |
+
action['delta_pos'] = move(o_d['hand_pos'], to_xyz=self._desired_pos(o_d), p=25.)
|
| 27 |
+
action['grab_effort'] = 1.
|
| 28 |
+
|
| 29 |
+
return action.array
|
| 30 |
+
|
| 31 |
+
@staticmethod
|
| 32 |
+
def _desired_pos(o_d):
|
| 33 |
+
pos_curr = o_d['hand_pos']
|
| 34 |
+
pos_button = o_d['handle_pos'] + np.array([.02, .0, .0])
|
| 35 |
+
|
| 36 |
+
if abs(pos_curr[1] - pos_button[1]) > 0.04:
|
| 37 |
+
return pos_button + np.array([0., 0., 0.2])
|
| 38 |
+
elif abs(pos_curr[2] - pos_button[2]) > 0.03:
|
| 39 |
+
return pos_button + np.array([.1, .0, -.01])
|
| 40 |
+
elif abs(pos_curr[0] - pos_button[0]) > .01:
|
| 41 |
+
return np.array([pos_button[0] - .04, pos_button[1], pos_curr[2]])
|
| 42 |
+
else:
|
| 43 |
+
return pos_button + np.array([-.04, .0, .1])
|