forked from stepjam/RLBench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
open_window.py
76 lines (62 loc) · 2.89 KB
/
open_window.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from typing import List, Tuple
import numpy as np
from pyrep.objects.object import Object
from pyrep.objects.joint import Joint
from pyrep.objects.shape import Shape
from pyrep.objects.dummy import Dummy
from rlbench.backend.task import Task
from rlbench.backend.conditions import JointCondition
OPTIONS = ['left', 'right']
class OpenWindow(Task):
def init_task(self):
self.waypoint0 = Dummy('waypoint0')
self.waypoint1 = Dummy('waypoint1')
self.waypoint2 = Dummy('waypoint2')
self.waypoint3 = Dummy('waypoint3')
self.waypoint0_ = Dummy('waypoint0_')
self.waypoint1_ = Dummy('waypoint1_')
self.waypoint2_ = Dummy('waypoint2_')
self.waypoint3_ = Dummy('waypoint3_')
self.right_unlocked_cond = JointCondition(
Joint('right_handle_joint'), np.deg2rad(60))
self.left_unlocked_cond = JointCondition(
Joint('left_handle_joint'), np.deg2rad(60))
self.right_frame = Shape('right_frame')
self.left_frame = Shape('left_frame')
def init_episode(self, index: int) -> List[str]:
self.right_frame.set_dynamic(False)
self.left_frame.set_dynamic(False)
self.left_unlocked = False
self.right_unlocked = False
option = OPTIONS[index]
if option == 'right':
self.waypoint0.set_position(self.waypoint0_.get_position())
self.waypoint1.set_position(self.waypoint1_.get_position())
self.waypoint2.set_position(self.waypoint2_.get_position())
self.waypoint2.set_orientation(self.waypoint2_.get_orientation())
self.waypoint3.set_position(self.waypoint3_.get_position())
self.waypoint3.set_orientation(self.waypoint3_.get_orientation())
self.register_success_conditions([JointCondition(
Joint('right_window_joint'), np.deg2rad(50))])
else:
self.register_success_conditions([JointCondition(
Joint('left_window_joint'), np.deg2rad(50))])
return ['open %s window' % option,
'rotate the handle to unlock the %s window, then open it' % option,
'push the %s window open' % option,
'use the handle to open the %s window' % option]
def variation_count(self) -> int:
return 2
def step(self) -> None:
if not self.left_unlocked:
self.left_unlocked = self.left_unlocked_cond.condition_met()[0]
if self.left_unlocked:
self.left_frame.set_dynamic(True)
if not self.right_unlocked:
self.right_unlocked = self.right_unlocked_cond.condition_met()[0]
if self.right_unlocked:
self.right_frame.set_dynamic(True)
def base_rotation_bounds(self) -> Tuple[List[float], List[float]]:
return [0, 0, -3.14 / 4.], [0, 0, 3.14 / 4.]
def boundary_root(self) -> Object:
return Shape('boundary_root')