nepyope commited on
Commit
a291cc7
·
verified ·
1 Parent(s): afeca72

Update env.py

Browse files
Files changed (1) hide show
  1. env.py +57 -1
env.py CHANGED
@@ -1,3 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # Use default values
2
  publish_images = True
3
  camera_port = 5555
@@ -53,4 +90,23 @@
53
  )
54
  except KeyboardInterrupt:
55
  print("\nShutting down simulator...")
56
- sim.close()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # env.py
2
+
3
+
4
+ from pathlib import Path
5
+ import yaml
6
+ from huggingface_hub import snapshot_download
7
+ import os
8
+ import gymnasium as gym
9
+ from gymnasium import spaces
10
+ import numpy as np
11
+ snapshot_download(repo_id='lerobot/unitree-g1-mujoco', revision=None, cache_dir=None)
12
+
13
+ from sim.simulator_factory import SimulatorFactory, init_channel
14
+
15
+
16
+ class UnitreeG1SimulationEnvironment:
17
+ """
18
+ Unitree G1 Simulation Environment for EnvHub.
19
+ """
20
+ def __init__(self, config_path=None):
21
+ # Load config
22
+ config_path = Path(__file__).parent / "config.yaml"
23
+ with open(config_path) as f:
24
+ self.config = yaml.safe_load(f)
25
+
26
+
27
+
28
+ # optional cleanup
29
+ def close(self):
30
+ self.sim.close()
31
+
32
+ def make_env(n_envs=1, use_async_envs: bool = False,
33
+ publish_images=True, camera_port=5555, cameras=None, **kwargs):
34
+ """
35
+ Required entrypoint for EnvHub.
36
+ Returns an environment instance with running simulator.
37
+ """
38
  # Use default values
39
  publish_images = True
40
  camera_port = 5555
 
90
  )
91
  except KeyboardInterrupt:
92
  print("\nShutting down simulator...")
93
+ sim.close()
94
+ import time
95
+ time.sleep(1000000)
96
+ class DummyEnv(gym.Env):
97
+ def __init__(self):
98
+ super().__init__()
99
+ self.action_space = spaces.Box(-1, 1, shape=(1,), dtype=np.float32)
100
+ self.observation_space = spaces.Box(-1, 1, shape=(1,), dtype=np.float32)
101
+
102
+ def reset(self, seed=None, options=None):
103
+ super().reset(seed=seed)
104
+ return np.zeros(1, dtype=np.float32), {}
105
+
106
+ def step(self, action):
107
+ return np.zeros(1, dtype=np.float32), 0.0, False, False, {}
108
+
109
+ def run(self):
110
+ pass
111
+
112
+ return DummyEnv()