forked from AlmondGod/aloha-bigym
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cupboards.py
79 lines (48 loc) · 2.19 KB
/
cupboards.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
77
78
79
"""Cupboard interaction tasks."""
from abc import ABC
import numpy as np
from bigym.bigym_env import BiGymEnv
from bigym.const import PRESETS_PATH
from bigym.envs.props.cabintets import BaseCabinet, WallCabinet
TOLERANCE = 0.1
class _CupboardsInteractionEnv(BiGymEnv, ABC):
"""Base cupboards environment."""
RESET_ROBOT_POS = np.array([-0.2, 0, 0])
_PRESET_PATH = PRESETS_PATH / "counter_base_wall_3x1.yaml"
def _initialize_env(self):
self.cabinet_drawers = self._preset.get_props(BaseCabinet)[0]
self.cabinet_wall = self._preset.get_props(WallCabinet)[0]
self.all_cabinets = [
self.cabinet_drawers,
self.cabinet_wall,
]
class DrawerTopOpen(_CupboardsInteractionEnv):
"""Open top drawer of the cupboard task."""
def _success(self) -> bool:
return np.allclose(self.cabinet_drawers.get_state()[-1], 1, atol=TOLERANCE)
class DrawerTopClose(_CupboardsInteractionEnv):
"""Close top drawer of the cupboard task."""
def _success(self) -> bool:
return np.allclose(self.cabinet_drawers.get_state()[-1], 0, atol=TOLERANCE)
def _on_reset(self):
self.cabinet_drawers.set_state(np.array([0, 0, 1]))
class DrawersAllOpen(_CupboardsInteractionEnv):
"""Open all drawers of the cupboard task."""
def _success(self) -> bool:
return np.allclose(self.cabinet_drawers.get_state(), 1, atol=TOLERANCE)
class DrawersAllClose(_CupboardsInteractionEnv):
"""Close all drawers of the cupboard task."""
def _success(self) -> bool:
return np.allclose(self.cabinet_drawers.get_state(), 0, atol=TOLERANCE)
def _on_reset(self):
self.cabinet_drawers.set_state(np.array([1, 1, 1]))
class WallCupboardOpen(_CupboardsInteractionEnv):
"""Open doors of the wall cupboard task."""
def _success(self) -> bool:
return np.allclose(self.cabinet_wall.get_state(), 1, atol=TOLERANCE)
class WallCupboardClose(_CupboardsInteractionEnv):
"""Close doors of the wall cupboard task."""
def _success(self) -> bool:
return np.allclose(self.cabinet_wall.get_state(), 0, atol=TOLERANCE)
def _on_reset(self):
self.cabinet_wall.set_state(np.array([1, 1]))