File size: 7,354 Bytes
d18db74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import numpy as np

from enum import Enum
from pathlib import Path

import mimicgen_envs

class EnvType(Enum):
    FRANKA = 'franka'
    POINT_MAZE = 'point_maze'
    ROBOMIMIC = 'robomimic'

class RLAlgorithm(Enum):
    PPO = "PPO"
    SAC = "SAC"

    def get_algo(self):
        from stable_baselines3 import PPO, SAC

        if self == RLAlgorithm.PPO:
            return PPO
        elif self == RLAlgorithm.SAC:
            return SAC
        else:
            raise ValueError(f"Unknown algorithm {self}")
        
class ImitationAlgorithm(Enum):
    BC_RNN = 'bc_rnn'
    BC = 'bc'
    CQL = 'cql'
    IQL = 'iql'
    IDQL = 'idql'
    IDQL_QSM = 'idql_qsm'
    IQL_DIFFUSION = 'iql_diffusion'
    DISCRIMINATOR = 'discriminator'
    
    def is_offline_rl(self):
        return self in [ImitationAlgorithm.IQL, ImitationAlgorithm.CQL, ImitationAlgorithm.IQL_DIFFUSION, ImitationAlgorithm.IDQL_QSM, ImitationAlgorithm.IDQL]
    
    def is_diffusion(self):
        return self in [ImitationAlgorithm.IQL_DIFFUSION, ImitationAlgorithm.IDQL, ImitationAlgorithm.IDQL_QSM]
    
class PolicyType(Enum):
    ROBOMIMIC = 'robomimic'
    STABLE_BASELINES = 'sb3'
    DIFFUSION = 'diffusion'
    OGBENCH = 'ogbench'
    COMPOSITE = 'composite'
    PD = 'pd'
    DISCRIMINATOR = 'discriminator'
    QTRANSFORMER = 'qtransformer'
    
class OGBenchAlgo(Enum):
    GCBC = 'gcbc'
    GCIQL = 'gciql'
    HIQL = 'hiql'
    CRL = 'crl'
    
    def get_agent(self):
        from impls.agents import agents
        
        return agents[self.value]
        
class CombinedPolicyType(Enum):
    HEURISTIC_RESET = 'heuristic_reset'
    HEURISTIC_RESET_SPLIT = 'heuristic_reset_split'
class RobomimicEnvType(Enum):
    LIFT = 'Lift'
    STACK = 'Stack'
    NUT_ASSEMBLY = 'NutAssembly'
    NUT_ASSEMBLY_SQUARE = 'NutAssemblySquare'
    NUT_ASSEMBLY_ROUND = 'NutAssemblyRound'
    NUT_ASSEMBLY_HANG_INSERT = 'NutAssemblyHangInsert'
    PICK_PLACE = 'PickPlace'
    DOOR = 'Door'
    THREE_PIECE_ASSEMBLY = 'ThreePieceAssembly'
    THREADING = 'Threading'
    MUG_CLEANUP = 'MugCleanup'
    COFFEE = 'Coffee'
    TOOL_HANG = 'ToolHang'
    
    def get_object_names(self):
        # see object names in robosuite environments, i.e. robosuite/environments/manipulation/nut_assembly.py:403
        if self in [RobomimicEnvType.NUT_ASSEMBLY, RobomimicEnvType.NUT_ASSEMBLY_SQUARE, RobomimicEnvType.NUT_ASSEMBLY_ROUND]:
            return ['SquareNut', 'RoundNut']
        elif self == RobomimicEnvType.THREE_PIECE_ASSEMBLY:
            return ['Base', 'Piece1']
        elif self == RobomimicEnvType.THREADING:
            return ['Needle', 'Tripod']
        elif self == RobomimicEnvType.TOOL_HANG:
            return ['standObject','frameObject','toolObject']
        else:
            return []
        
    def get_default_obj_init_ranges(self):
        if self in [RobomimicEnvType.NUT_ASSEMBLY, RobomimicEnvType.NUT_ASSEMBLY_SQUARE, RobomimicEnvType.NUT_ASSEMBLY_ROUND]:
            return {
                'SquareNut':
                [
                    [-0.115, -0.11], 
                    [0.11, 0.225],
                ],
                'RoundNut':
                [
                    [-1.0, -0.9],
                    # [-0.115, -0.11], 
                    [-0.225, -0.11],
                ]    
            }
        elif self in [RobomimicEnvType.THREE_PIECE_ASSEMBLY]:
            return {
                'Base':
                [
                    [0.0, 0.0], 
                    [0.0, 0.0],
                    [0.0, 0.0],
                ],
                'Piece1':
                [
                    [-0.22, 0.22], 
                    [-0.22, 0.22],
                    [1.5708, 1.5708],
                ],
                # 'Piece2':
                # [
                #     [-0.22, 0.22], 
                #     [-0.22, 0.22],
                #     [1.5708, 1.5708],
                # ]
            }
        elif self == RobomimicEnvType.THREADING:
            return {
                'Needle':
                [
                    [-0.2, -0.05], 
                    [0.15, 0.25],
                    [-2. * np.pi / 3., -np.pi / 3.],
                ],
                'Tripod':
                [
                    [0.0, 0.0], 
                    [-0.15, -0.15],
                    [np.pi / 2., np.pi / 2.],
                ]
            }
        elif self == RobomimicEnvType.TOOL_HANG:
            return {
                'standObject':
                [
                    [-0.08, -0.08], 
                    [0.0, 0.0],
                    [0.0, 0.0],
                ],
                'frameObject':
                [
                    [-0.02, -0.06], 
                    [-0.26, -0.22],
                    [(-np.pi / 2) + (np.pi / 6) - np.pi / 18, (-np.pi / 2) + (np.pi / 6) + np.pi / 18],
                ],
                'toolObject':
                [
                    [-0.02, -0.06], 
                    [-0.22, -0.18],
                    [(-np.pi / 2) - (np.pi / 9.0) - np.pi / 18, (-np.pi / 2) - (np.pi / 9.0) + np.pi / 18],
                ],
            }
        else:
            return {}
        
    def get_simple_name(self):
        if self == RobomimicEnvType.NUT_ASSEMBLY_SQUARE:
            return 'square'
        else:
            return self.value.lower()
        
    def get_surface_ref_pos(self):
        # reference pos to pass into Placement Sampler
        if self in [RobomimicEnvType.NUT_ASSEMBLY, RobomimicEnvType.NUT_ASSEMBLY_SQUARE, RobomimicEnvType.NUT_ASSEMBLY_ROUND]:
            return np.array([0.0, 0.0, 0.82])
        elif self in [RobomimicEnvType.THREE_PIECE_ASSEMBLY, RobomimicEnvType.THREADING]:
            return np.array([0.0, 0.0, 0.8])
        elif self == RobomimicEnvType.TOOL_HANG:
            return np.array([0.0, 0.0, 0.8])
        else:
            return []

class IO_Devices(Enum):
    KEYBOARD = 'keyboard'
    SPACEMOUSE = 'spacemouse'
    SPAECMOUSE_ORIGINAL = 'spacemouse_original'

    def get_device(self, pos_sensitivity=1.0, rot_sensitivity=1.0):
        if self == IO_Devices.KEYBOARD:
            from sim_pipeline.data_collection.keyboard import Keyboard

            device = Keyboard(pos_sensitivity=pos_sensitivity, rot_sensitivity=rot_sensitivity)
        elif self == IO_Devices.SPACEMOUSE:
            from sim_pipeline.data_collection.spacemouse_hybrid import SpaceMouse as SpaceMouseHybrid

            device = SpaceMouseHybrid(pos_sensitivity=pos_sensitivity, rot_sensitivity=rot_sensitivity)
        elif self == IO_Devices.SPAECMOUSE_ORIGINAL:
            from robosuite.devices import SpaceMouse

            device = SpaceMouse(pos_sensitivity=pos_sensitivity, rot_sensitivity=rot_sensitivity)
        else:
            raise ValueError(f"Unknown device {self}")
        
        return device

import sim_pipeline
ROOT_DIR = Path(sim_pipeline.__file__).parent
CONFIG_DIR = ROOT_DIR / 'configs'
LOG_DIR = ROOT_DIR / 'logs'
DATA_DIR = ROOT_DIR / 'data'
ROLLOUT_DATA_DIR = DATA_DIR / 'rollout_generated_data'
COMBINED_DATA_DIR = DATA_DIR / 'combined'
DATASET_DB_PATH = ROOT_DIR / 'datasets.db'
MODEL_DB_PATH = ROOT_DIR / 'models.db'

CALIBRATION_PATH = (Path(__file__).parent.parent.parent.parent / 'weird_franka' / 'weird_franka' / 'perception' / 'cameras' / 'calibration' /
                    'logs' / 'default.json')