Improve async example and remove Network demo code

- Move SimToView and ViewToSim dataclasses from async.py to viewer_protocol.py (adding a user_data field) to consolidate IPC protocol definitions.
  - Remove the simulated Network class and latency UI controls from async.py to simplify the example and focus on core multiprocessing communication.
  - Use parser.parse() in main() for cleaner and more direct MuJoCo model loading.
  - Add cancel_join_thread() to multiprocessing queues and a join timeout to prevent atexit handlers from blocking during process shutdown.

PiperOrigin-RevId: 932327625
Change-Id: If91777dba934814b3f9faa17f9055869920575d7
This commit is contained in:
Matija Kecman
2026-06-15 02:30:15 -07:00
committed by Copybara-Service
parent 2a210da0f7
commit 7c22920720
2 changed files with 69 additions and 73 deletions
@@ -16,10 +16,12 @@
StudioApp uses the protocol for convenience methods that accept any viewer.
"""
import dataclasses
from typing import Any
from typing import Protocol
import mujoco
from mujoco.experimental.studio import ux
import numpy as np
GFX_MODES = (
'classic',
@@ -33,6 +35,27 @@ GFX_MODES = (
)
@dataclasses.dataclass
class SimToView:
"""A message sent from the simulation to the viewer."""
model: mujoco.MjModel | None = None
state: np.ndarray | None = None
state_sig: int = 0
user_data: dict[str, Any] = dataclasses.field(default_factory=dict)
@dataclasses.dataclass
class ViewToSim:
"""A message sent from the viewer to the simulation."""
state: np.ndarray | None = None
state_sig: int = 0
reset: bool = False
send_rate: float = 60.0
user_data: dict[str, Any] = dataclasses.field(default_factory=dict)
class Viewer(Protocol):
"""Structural interface for any viewer."""