forked from stepjam/RLBench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreach_target.py
48 lines (40 loc) · 1.89 KB
/
reach_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
from typing import List, Tuple
import numpy as np
from pyrep.objects.shape import Shape
from pyrep.objects.proximity_sensor import ProximitySensor
from rlbench.const import colors
from rlbench.backend.task import Task
from rlbench.backend.spawn_boundary import SpawnBoundary
from rlbench.backend.conditions import DetectedCondition
class ReachTarget(Task):
def init_task(self) -> None:
self.target = Shape('target')
self.distractor0 = Shape('distractor0')
self.distractor1 = Shape('distractor1')
self.boundaries = Shape('boundary')
success_sensor = ProximitySensor('success')
self.register_success_conditions(
[DetectedCondition(self.robot.arm.get_tip(), success_sensor)])
def init_episode(self, index: int) -> List[str]:
color_name, color_rgb = colors[index]
self.target.set_color(color_rgb)
color_choices = np.random.choice(
list(range(index)) + list(range(index + 1, len(colors))),
size=2, replace=False)
for ob, i in zip([self.distractor0, self.distractor1], color_choices):
name, rgb = colors[i]
ob.set_color(rgb)
b = SpawnBoundary([self.boundaries])
for ob in [self.target, self.distractor0, self.distractor1]:
b.sample(ob, min_distance=0.2,
min_rotation=(0, 0, 0), max_rotation=(0, 0, 0))
return ['reach the %s target' % color_name,
'touch the %s ball with the panda gripper' % color_name,
'reach the %s sphere' %color_name]
def variation_count(self) -> int:
return len(colors)
def base_rotation_bounds(self) -> Tuple[List[float], List[float]]:
return [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]
def get_low_dim_state(self) -> np.ndarray:
# One of the few tasks that have a custom low_dim_state function.
return np.array(self.target.get_position())