Upload task files
Browse files- data/files/.DS_Store +0 -0
- data/files/put_block_back.py +130 -0
- data/files/put_block_back.ttm +0 -0
- data/files/rearrange_block.py +151 -0
- data/files/rearrange_block.ttm +0 -0
- data/files/reopen_drawer.py +110 -0
- data/files/reopen_drawer.ttm +0 -0
data/files/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
data/files/put_block_back.py
ADDED
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import itertools
|
2 |
+
import math
|
3 |
+
from typing import Dict, List
|
4 |
+
|
5 |
+
from pyrep.objects.dummy import Dummy
|
6 |
+
from pyrep.objects.joint import Joint
|
7 |
+
from pyrep.objects.object import Object
|
8 |
+
from pyrep.objects.shape import Shape
|
9 |
+
from pyrep.objects.proximity_sensor import ProximitySensor
|
10 |
+
from rlbench.backend.spawn_boundary import SpawnBoundary
|
11 |
+
from rlbench.backend.task import Task
|
12 |
+
from rlbench.backend.conditions import Condition, ConditionSet, DetectedCondition, NothingGrasped
|
13 |
+
|
14 |
+
NUM_TARGETS = 4
|
15 |
+
|
16 |
+
class JointTriggerCondition(Condition):
|
17 |
+
def __init__(self, joint: Joint, position: float):
|
18 |
+
"""in radians if revoloute, or meters if prismatic"""
|
19 |
+
self._joint = joint
|
20 |
+
self._original_pos = joint.get_joint_position()
|
21 |
+
self._pos = position
|
22 |
+
self._done = False
|
23 |
+
|
24 |
+
def condition_met(self):
|
25 |
+
met = math.fabs(
|
26 |
+
self._joint.get_joint_position() - self._original_pos) > self._pos
|
27 |
+
if met:
|
28 |
+
self._done = True
|
29 |
+
return self._done, False
|
30 |
+
|
31 |
+
class DetectedTriggerCondition(Condition):
|
32 |
+
def __init__(self, obj: Object, detector: ProximitySensor,
|
33 |
+
negated: bool = False):
|
34 |
+
self._obj = obj
|
35 |
+
self._detector = detector
|
36 |
+
self._negated = negated
|
37 |
+
self._done = False
|
38 |
+
|
39 |
+
def condition_met(self):
|
40 |
+
met = self._detector.is_detected(self._obj)
|
41 |
+
if self._negated:
|
42 |
+
met = not met
|
43 |
+
if met:
|
44 |
+
self._done = True
|
45 |
+
return self._done, False
|
46 |
+
|
47 |
+
|
48 |
+
|
49 |
+
class PutBlockBack(Task):
|
50 |
+
def init_task(self) -> None:
|
51 |
+
self._block = Shape("block")
|
52 |
+
self._detectors = [ProximitySensor(f"success{i+1}") for i in range(NUM_TARGETS)]
|
53 |
+
self._targets = [Shape(f"target{i+1}") for i in range(NUM_TARGETS)]
|
54 |
+
|
55 |
+
self._button = Shape("push_buttons_target1")
|
56 |
+
self._button_joint = Joint("target_button_joint1")
|
57 |
+
self._center_detector = ProximitySensor("success0")
|
58 |
+
|
59 |
+
self.spawn_boundary = SpawnBoundary([Shape("boundary")])
|
60 |
+
|
61 |
+
self.register_graspable_objects([self._block])
|
62 |
+
|
63 |
+
self.goal_conditions = []
|
64 |
+
|
65 |
+
def init_episode(self, index: int) -> List[str]:
|
66 |
+
target_patch = self._targets[index]
|
67 |
+
target_detector = self._detectors[index]
|
68 |
+
|
69 |
+
self.spawn_boundary.clear()
|
70 |
+
self.spawn_boundary.sample(self._button, min_distance=0.05)
|
71 |
+
|
72 |
+
# Set the position of the block to be the initial target XY ------------
|
73 |
+
x, y, _ = target_patch.get_position()
|
74 |
+
_, _, z = self._block.get_position()
|
75 |
+
self._block.set_position([x, y, z])
|
76 |
+
|
77 |
+
waypoint1 = Dummy("waypoint1")
|
78 |
+
_, _, z = waypoint1.get_position()
|
79 |
+
waypoint1.set_position([x, y, z])
|
80 |
+
|
81 |
+
waypoint10 = Dummy("waypoint10")
|
82 |
+
_, _, z = waypoint10.get_position()
|
83 |
+
waypoint10.set_position([x, y, z])
|
84 |
+
|
85 |
+
waypoint11 = Dummy("waypoint11")
|
86 |
+
_, _, z = waypoint11.get_position()
|
87 |
+
waypoint11.set_position([x, y, z])
|
88 |
+
# ----------------------------------------------------------------------
|
89 |
+
|
90 |
+
self.goal_conditions = [
|
91 |
+
# Checks that the block was lifted from the table
|
92 |
+
DetectedTriggerCondition(self._block, target_detector, negated=True),
|
93 |
+
# Checks that the cube was placed at the center of the table
|
94 |
+
DetectedTriggerCondition(self._block, self._center_detector),
|
95 |
+
# Checks that the button was pressed
|
96 |
+
JointTriggerCondition(self._button_joint, 0.003),
|
97 |
+
# Checks that the block was returned back to its original position
|
98 |
+
DetectedCondition(self._block, target_detector),
|
99 |
+
# Checks that nothing is still grasped
|
100 |
+
NothingGrasped(self.robot.gripper),
|
101 |
+
]
|
102 |
+
condition_set = ConditionSet(self.goal_conditions, False) # type: ignore
|
103 |
+
self.register_success_conditions([condition_set])
|
104 |
+
|
105 |
+
return ['move the block on the color patch to the center, then press the button, and finally move the block back to where it was placed']
|
106 |
+
|
107 |
+
def step(self) -> None:
|
108 |
+
if len(self.goal_conditions) < 1:
|
109 |
+
return
|
110 |
+
|
111 |
+
met1, _ = self.goal_conditions[0].condition_met()
|
112 |
+
#print(f"first condition met: {met1}")
|
113 |
+
|
114 |
+
met2, _ = self.goal_conditions[1].condition_met()
|
115 |
+
#print(f"second condition met: {met2}")
|
116 |
+
|
117 |
+
met3, _ = self.goal_conditions[2].condition_met()
|
118 |
+
#print(f"third condition met: {met3}")
|
119 |
+
|
120 |
+
met4, _ = self.goal_conditions[3].condition_met()
|
121 |
+
#print(f"fourth condition met: {met4}")
|
122 |
+
|
123 |
+
met5, _ = self.goal_conditions[4].condition_met()
|
124 |
+
#print(f"fifth condition met: {met5}")
|
125 |
+
|
126 |
+
def variation_count(self) -> int:
|
127 |
+
return 4
|
128 |
+
|
129 |
+
def is_static_workspace(self) -> bool:
|
130 |
+
return True
|
data/files/put_block_back.ttm
ADDED
Binary file (47.5 kB). View file
|
|
data/files/rearrange_block.py
ADDED
@@ -0,0 +1,151 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import itertools
|
2 |
+
import math
|
3 |
+
from typing import Dict, List
|
4 |
+
|
5 |
+
from pyrep.objects.dummy import Dummy
|
6 |
+
from pyrep.objects.joint import Joint
|
7 |
+
from pyrep.objects.object import Object
|
8 |
+
from pyrep.objects.shape import Shape
|
9 |
+
from pyrep.objects.proximity_sensor import ProximitySensor
|
10 |
+
from rlbench.backend.spawn_boundary import SpawnBoundary
|
11 |
+
from rlbench.backend.task import Task
|
12 |
+
from rlbench.backend.conditions import Condition, ConditionSet, DetectedCondition, NothingGrasped
|
13 |
+
|
14 |
+
NUM_TARGETS = 2
|
15 |
+
|
16 |
+
class JointTriggerCondition(Condition):
|
17 |
+
def __init__(self, joint: Joint, position: float):
|
18 |
+
"""in radians if revoloute, or meters if prismatic"""
|
19 |
+
self._joint = joint
|
20 |
+
self._original_pos = joint.get_joint_position()
|
21 |
+
self._pos = position
|
22 |
+
self._done = False
|
23 |
+
|
24 |
+
def condition_met(self):
|
25 |
+
met = math.fabs(
|
26 |
+
self._joint.get_joint_position() - self._original_pos) > self._pos
|
27 |
+
if met:
|
28 |
+
self._done = True
|
29 |
+
return self._done, False
|
30 |
+
|
31 |
+
class DetectedTriggerCondition(Condition):
|
32 |
+
def __init__(self, obj: Object, detector: ProximitySensor,
|
33 |
+
negated: bool = False):
|
34 |
+
self._obj = obj
|
35 |
+
self._detector = detector
|
36 |
+
self._negated = negated
|
37 |
+
self._done = False
|
38 |
+
|
39 |
+
def condition_met(self):
|
40 |
+
met = self._detector.is_detected(self._obj)
|
41 |
+
if self._negated:
|
42 |
+
met = not met
|
43 |
+
if met:
|
44 |
+
self._done = True
|
45 |
+
return self._done, False
|
46 |
+
|
47 |
+
|
48 |
+
|
49 |
+
class RearrangeBlock(Task):
|
50 |
+
def init_task(self) -> None:
|
51 |
+
self._detectors = [ProximitySensor(f"success{i+1}") for i in range(NUM_TARGETS)]
|
52 |
+
self._targets = [Shape(f"target{i+1}") for i in range(NUM_TARGETS)]
|
53 |
+
|
54 |
+
self._patch_block = Shape("block1")
|
55 |
+
self._center_block = Shape("block2")
|
56 |
+
self._center_detector = ProximitySensor("success0")
|
57 |
+
|
58 |
+
self._button = Shape("push_buttons_target1")
|
59 |
+
self._button_joint = Joint("target_button_joint1")
|
60 |
+
|
61 |
+
self.spawn_boundary = SpawnBoundary([Shape("boundary")])
|
62 |
+
|
63 |
+
self.register_graspable_objects([self._patch_block, self._center_block])
|
64 |
+
|
65 |
+
self.goal_conditions = []
|
66 |
+
|
67 |
+
def init_episode(self, index: int) -> List[str]:
|
68 |
+
target_patch = self._targets[index]
|
69 |
+
dual_index = NUM_TARGETS - index - 1
|
70 |
+
dual_patch = self._targets[dual_index]
|
71 |
+
|
72 |
+
self.spawn_boundary.clear()
|
73 |
+
self.spawn_boundary.sample(self._button, min_distance=0.05)
|
74 |
+
|
75 |
+
# Set the position of the patch block to be the initial target XY ------
|
76 |
+
x, y, _ = target_patch.get_position()
|
77 |
+
_, _, z = self._patch_block.get_position()
|
78 |
+
self._patch_block.set_position([x, y, z])
|
79 |
+
|
80 |
+
waypoint6 = Dummy("waypoint6")
|
81 |
+
_, _, z = waypoint6.get_position()
|
82 |
+
waypoint6.set_position([x, y, z])
|
83 |
+
|
84 |
+
waypoint7 = Dummy("waypoint7")
|
85 |
+
_, _, z = waypoint7.get_position()
|
86 |
+
waypoint7.set_position([x, y, z])
|
87 |
+
|
88 |
+
waypoint8 = Dummy("waypoint8")
|
89 |
+
_, _, z = waypoint8.get_position()
|
90 |
+
waypoint8.set_position([x, y, z])
|
91 |
+
|
92 |
+
# ----------------------------------------------------------------------
|
93 |
+
|
94 |
+
# Place the waypoints associated with the dual patch correctly ---------
|
95 |
+
waypoint2 = Dummy("waypoint2")
|
96 |
+
x, y, _ = dual_patch.get_position()
|
97 |
+
_, _, z = waypoint2.get_position()
|
98 |
+
waypoint2.set_position([x, y, z])
|
99 |
+
|
100 |
+
waypoint3 = Dummy("waypoint3")
|
101 |
+
_, _, z = waypoint3.get_position()
|
102 |
+
waypoint3.set_position([x, y, z])
|
103 |
+
|
104 |
+
# ----------------------------------------------------------------------
|
105 |
+
|
106 |
+
self.goal_conditions = [
|
107 |
+
# Checks that the center block was lifted up
|
108 |
+
DetectedTriggerCondition(self._center_block, self._center_detector, negated=True),
|
109 |
+
# Checks that the center block was placed in the empty patch
|
110 |
+
DetectedCondition(self._center_block, self._detectors[dual_index]),
|
111 |
+
# Checks that the button was pressed
|
112 |
+
JointTriggerCondition(self._button_joint, 0.003),
|
113 |
+
# Checks that the patch block was lifted up
|
114 |
+
DetectedTriggerCondition(self._patch_block, self._detectors[index], negated=True),
|
115 |
+
# Checks that the patch block was placed in the center
|
116 |
+
DetectedCondition(self._patch_block, self._center_detector),
|
117 |
+
# Checks that nothing is still grasped
|
118 |
+
NothingGrasped(self.robot.gripper),
|
119 |
+
]
|
120 |
+
condition_set = ConditionSet(self.goal_conditions, False) # type: ignore
|
121 |
+
self.register_success_conditions([condition_set])
|
122 |
+
|
123 |
+
return ['Move the block not on the patch to the empty patch, then press the button, then move the block that has not been moved off the patch']
|
124 |
+
|
125 |
+
def step(self) -> None:
|
126 |
+
if len(self.goal_conditions) < 1:
|
127 |
+
return
|
128 |
+
|
129 |
+
met1, _ = self.goal_conditions[0].condition_met()
|
130 |
+
#print(f"first condition met: {met1}")
|
131 |
+
|
132 |
+
met2, _ = self.goal_conditions[1].condition_met()
|
133 |
+
#print(f"second condition met: {met2}")
|
134 |
+
|
135 |
+
met3, _ = self.goal_conditions[2].condition_met()
|
136 |
+
#print(f"third condition met: {met3}")
|
137 |
+
|
138 |
+
met4, _ = self.goal_conditions[3].condition_met()
|
139 |
+
#print(f"fourth condition met: {met4}")
|
140 |
+
|
141 |
+
met5, _ = self.goal_conditions[4].condition_met()
|
142 |
+
#print(f"fifth condition met: {met5}")
|
143 |
+
|
144 |
+
met6, _ = self.goal_conditions[5].condition_met()
|
145 |
+
#print(f"sixth condition met: {met6}")
|
146 |
+
|
147 |
+
def variation_count(self) -> int:
|
148 |
+
return 2
|
149 |
+
|
150 |
+
def is_static_workspace(self) -> bool:
|
151 |
+
return True
|
data/files/rearrange_block.ttm
ADDED
Binary file (43.3 kB). View file
|
|
data/files/reopen_drawer.py
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import math
|
2 |
+
from typing import List, Tuple
|
3 |
+
import numpy as np
|
4 |
+
from pyrep.objects.proximity_sensor import ProximitySensor
|
5 |
+
from pyrep.objects.dummy import Dummy
|
6 |
+
from pyrep.objects.joint import Joint
|
7 |
+
from pyrep.objects.shape import Shape
|
8 |
+
from rlbench.backend.spawn_boundary import SpawnBoundary
|
9 |
+
from rlbench.backend.task import Task
|
10 |
+
from rlbench.backend.conditions import Condition, DetectedCondition, JointCondition, NothingGrasped, ConditionSet
|
11 |
+
|
12 |
+
DRAWER_NAMES = ['bottom', 'middle', 'top']
|
13 |
+
|
14 |
+
class JointConditionEx(Condition):
|
15 |
+
def __init__(self, joint: Joint, position: float):
|
16 |
+
"""in radians if revoloute, or meters if prismatic"""
|
17 |
+
self._joint = joint
|
18 |
+
self._original_pos = joint.get_joint_position()
|
19 |
+
self._pos = position
|
20 |
+
self._done = False
|
21 |
+
|
22 |
+
def condition_met(self):
|
23 |
+
met = math.fabs(
|
24 |
+
self._joint.get_joint_position() - self._original_pos) > self._pos
|
25 |
+
if met:
|
26 |
+
self._done = True
|
27 |
+
return self._done, False
|
28 |
+
|
29 |
+
|
30 |
+
class ReopenDrawer(Task):
|
31 |
+
|
32 |
+
def init_task(self):
|
33 |
+
self.button = Shape(f"push_buttons_target1")
|
34 |
+
self.drawer_parts = [Shape(f"drawer_{name}") for name in DRAWER_NAMES]
|
35 |
+
self.drawer_joints = [Joint(f"drawer_joint_{name}") for name in DRAWER_NAMES]
|
36 |
+
self.button_joint = Joint("target_button_joint1")
|
37 |
+
|
38 |
+
self.detector = ProximitySensor("success")
|
39 |
+
|
40 |
+
self.spawn_boundary = SpawnBoundary([Shape("boundary")])
|
41 |
+
self.target_drawer_joint = None
|
42 |
+
|
43 |
+
self.goal_conditions = []
|
44 |
+
|
45 |
+
def init_episode(self, index: int) -> List[str]:
|
46 |
+
for i in range(len(DRAWER_NAMES)):
|
47 |
+
if i == index:
|
48 |
+
self.drawer_joints[i].set_joint_position(0.21, disable_dynamics=True)
|
49 |
+
else:
|
50 |
+
self.drawer_joints[i].set_joint_position(0.0, disable_dynamics=True)
|
51 |
+
|
52 |
+
target_anchor = Dummy(f"waypoint_anchor_{DRAWER_NAMES[index]}")
|
53 |
+
waypoint0 = Dummy("waypoint0")
|
54 |
+
waypoint1 = Dummy("waypoint1")
|
55 |
+
waypoint6 = Dummy("waypoint6")
|
56 |
+
waypoint7 = Dummy("waypoint7")
|
57 |
+
waypoint8 = Dummy("waypoint8")
|
58 |
+
|
59 |
+
_, _, z = target_anchor.get_position()
|
60 |
+
x, y, _ = waypoint0.get_position()
|
61 |
+
waypoint0.set_position([x, y, z])
|
62 |
+
|
63 |
+
x, y, _ = waypoint1.get_position()
|
64 |
+
waypoint1.set_position([x, y, z])
|
65 |
+
|
66 |
+
x, y, _ = waypoint6.get_position()
|
67 |
+
waypoint6.set_position([x, y, z])
|
68 |
+
|
69 |
+
x, y, _ = waypoint7.get_position()
|
70 |
+
waypoint7.set_position([x, y, z])
|
71 |
+
|
72 |
+
x, y, _ = waypoint8.get_position()
|
73 |
+
waypoint8.set_position([x, y, z])
|
74 |
+
|
75 |
+
self.spawn_boundary.clear()
|
76 |
+
self.spawn_boundary.sample(self.button, min_distance=0.05)
|
77 |
+
|
78 |
+
self.goal_conditions = [
|
79 |
+
JointConditionEx(self.drawer_joints[index], 0.19),
|
80 |
+
JointConditionEx(self.button_joint, 0.003),
|
81 |
+
DetectedCondition(self.drawer_parts[index], self.detector),
|
82 |
+
]
|
83 |
+
condition_set = ConditionSet(self.goal_conditions, True) # type: ignore
|
84 |
+
self.register_success_conditions([condition_set])
|
85 |
+
|
86 |
+
self.target_drawer_joint = self.drawer_joints[index]
|
87 |
+
|
88 |
+
return ['Close the opened drawer, push the button, and then open the previous drawer again']
|
89 |
+
|
90 |
+
# def step(self) -> None:
|
91 |
+
# #if self.target_drawer_joint:
|
92 |
+
# # print(f"drawer_joint: {self.target_drawer_joint.get_joint_position()}")
|
93 |
+
#
|
94 |
+
# if len(self.goal_conditions) < 1:
|
95 |
+
# return
|
96 |
+
#
|
97 |
+
# met1, _ = self.goal_conditions[0].condition_met()
|
98 |
+
# print(f"first condition met: {met1}")
|
99 |
+
#
|
100 |
+
# met2, _ = self.goal_conditions[1].condition_met()
|
101 |
+
# print(f"second condition met: {met2}")
|
102 |
+
#
|
103 |
+
# met3, _ = self.goal_conditions[2].condition_met()
|
104 |
+
# print(f"second condition met: {met3}")
|
105 |
+
|
106 |
+
def variation_count(self) -> int:
|
107 |
+
return len(DRAWER_NAMES)
|
108 |
+
|
109 |
+
def is_static_workspace(self) -> bool:
|
110 |
+
return True
|
data/files/reopen_drawer.ttm
ADDED
Binary file (70.6 kB). View file
|
|