|
|
|
|
|
"""Standalone MuJoCo simulator for Unitree G1""" |
|
|
import sys |
|
|
from pathlib import Path |
|
|
|
|
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent)) |
|
|
|
|
|
import yaml |
|
|
from sim.simulator_factory import SimulatorFactory, init_channel |
|
|
|
|
|
def main(n_envs=1, use_async_envs: bool = False, |
|
|
publish_images=True, camera_port=5554, cameras=None, **kwargs): |
|
|
|
|
|
publish_images = True |
|
|
camera_port = 5554 |
|
|
cameras = None |
|
|
|
|
|
|
|
|
config_path = Path(__file__).parent / "config.yaml" |
|
|
with open(config_path) as f: |
|
|
config = yaml.safe_load(f) |
|
|
|
|
|
|
|
|
enable_offscreen = publish_images or config.get("ENABLE_OFFSCREEN", False) |
|
|
|
|
|
print("="*60) |
|
|
print("π€ Starting Unitree G1 MuJoCo Simulator") |
|
|
print("="*60) |
|
|
print(f"π Scene: {config['ROBOT_SCENE']}") |
|
|
print(f"β±οΈ Timestep: {config['SIMULATE_DT']}s ({int(1/config['SIMULATE_DT'])} Hz)") |
|
|
print(f"ποΈ Visualization: {'ON' if config.get('ENABLE_ONSCREEN', True) else 'OFF'}") |
|
|
|
|
|
|
|
|
camera_configs = {} |
|
|
if enable_offscreen: |
|
|
camera_list = cameras or ["head_camera"] |
|
|
for cam_name in camera_list: |
|
|
camera_configs[cam_name] = {"height": 480, "width": 640} |
|
|
print(f"π· Cameras: {', '.join(camera_list)} β ZMQ port {camera_port}") |
|
|
|
|
|
print("="*60) |
|
|
|
|
|
|
|
|
init_channel(config=config) |
|
|
|
|
|
|
|
|
sim = SimulatorFactory.create_simulator( |
|
|
config=config, |
|
|
env_name="default", |
|
|
onscreen=config.get("ENABLE_ONSCREEN", True), |
|
|
offscreen=enable_offscreen, |
|
|
camera_configs=camera_configs, |
|
|
) |
|
|
|
|
|
|
|
|
print("\nSimulator running. Press Ctrl+C to exit.") |
|
|
if enable_offscreen and publish_images: |
|
|
print(f"Camera images publishing on tcp://localhost:{camera_port}") |
|
|
try: |
|
|
SimulatorFactory.start_simulator( |
|
|
sim, |
|
|
as_thread=False, |
|
|
enable_image_publish=publish_images, |
|
|
camera_port=camera_port, |
|
|
) |
|
|
except KeyboardInterrupt: |
|
|
print("\nShutting down simulator...") |
|
|
sim.close() |
|
|
|
|
|
if __name__ == "__main__": |
|
|
main() |
|
|
|
|
|
|