File size: 1,883 Bytes
05b8dea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
if os.environ.get("ISR_MEMDECODE") == "1":
    try: import memdecode  # noqa
    except Exception as e: print("memdecode patch failed:", e)
if os.environ.get("ISR_GYM_ALOHA") == "1":
    try:
        import gym_aloha  # noqa  (registers gym_aloha/* envs in every process incl. forkserver children)
        from gym_aloha.env import AlohaEnv
        if not hasattr(AlohaEnv, "task_description"): AlohaEnv.task_description = property(lambda self: f"aloha {getattr(self, 'task', '')}")  # lerobot_eval requires it
    except Exception as e: print("gym_aloha import failed:", e)
if os.environ.get("ISR_ALOHA_DEG") == "1":   # policy trained in degrees; env speaks radians
    try:
        import numpy as np
        from gym_aloha.env import AlohaEnv
        _step, _reset = AlohaEnv.step, AlohaEnv.reset
        def _o(o):
            if isinstance(o, dict) and "agent_pos" in o: o["agent_pos"] = np.rad2deg(o["agent_pos"]).astype(np.float32)
            return o
        def step(self, action): o, r, te, tr, i = _step(self, np.deg2rad(np.asarray(action, dtype=np.float64))); return _o(o), r, te, tr, i
        def reset(self, *a, **k): o, i = _reset(self, *a, **k); return _o(o), i
        AlohaEnv.step, AlohaEnv.reset = step, reset
    except Exception as e: print("aloha deg shim failed:", e)
if os.environ.get("ISR_ACTION_REPEAT", "1") != "1":   # rate-matched deployment: hold each policy action N sim steps
    try:
        from gym_aloha.env import AlohaEnv
        _N = int(os.environ["ISR_ACTION_REPEAT"]); _step_r = AlohaEnv.step
        def step_rep(self, action):
            tot = 0.0
            for _ in range(_N):
                o, r, te, tr, i = _step_r(self, action); tot += float(r)
                if te or tr: break
            return o, tot, te, tr, i
        AlohaEnv.step = step_rep
    except Exception as e: print("action repeat shim failed:", e)