forked from stepjam/RLBench
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathslide_block_to_color_target.py
61 lines (46 loc) · 2.05 KB
/
slide_block_to_color_target.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from typing import List
from pyrep.objects.shape import Shape
from pyrep.objects.dummy import Dummy
from pyrep.objects.proximity_sensor import ProximitySensor
from rlbench.backend.task import Task
from rlbench.backend.conditions import DetectedCondition
import numpy as np
class SlideBlockToColorTarget(Task):
def init_task(self) -> None:
self.block = Shape('block')
self.target_colors = ['green', 'blue', 'pink', 'yellow']
self._waypoint_paths = {
0: [Dummy('point1a'),
Dummy('point1b')],
1: [Dummy('point2a'),
Dummy('point2b'),
Dummy('point2c'),
Dummy('point2d'),
Dummy('point2e')],
2: [Dummy('point3a'),
Dummy('point3b')],
3: [Dummy('point4a'),
Dummy('point4b'),
Dummy('point4c'),
Dummy('point4d'),
Dummy('point4e')]
}
def init_episode(self, index: int) -> List[str]:
self._variation_index = index
self.register_success_conditions([
DetectedCondition(Shape('block'),
ProximitySensor(f'success{self._variation_index+1}'))])
target_color = self.target_colors[self._variation_index]
target_waypoints = self._waypoint_paths[self._variation_index]
self._waypoints = [Dummy('waypoint%d'%(i))
for i in range(5)]
for i in range(len(target_waypoints)):
self._waypoints[i].set_pose(target_waypoints[i].get_pose())
self.register_stop_at_waypoint(i+1)
return ['slide the block to %s target' % (target_color),
'slide the block onto the %s square' % (target_color),
'push the block until it is sitting on top of the %s target' % (target_color),
'slide the block towards the %s plane' % (target_color),
'cover the %s target with the block by pushing the block in its direction' % (target_color)]
def variation_count(self) -> int:
return 4