File size: 1,337 Bytes
ef118cf | 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 | """Base controller interface for G1 robot."""
import numpy as np
from abc import ABC, abstractmethod
class BaseController(ABC):
"""Abstract base class for G1 robot controllers."""
def __init__(self, num_joints: int = 29):
self.num_joints = num_joints
self.time = 0.0
self.dt = 0.01 # 100 Hz default
@abstractmethod
def compute_action(self, obs: np.ndarray, data) -> np.ndarray:
"""
Compute control action given observation and MuJoCo data.
Args:
obs: Observation vector from environment
data: MuJoCo data object for direct joint access
Returns:
Action array of shape (num_joints,) with torques
"""
pass
def reset(self):
"""Reset controller state."""
self.time = 0.0
def step(self, dt: float = 0.01):
"""Advance controller time."""
self.time += dt
self.dt = dt
@property
def name(self) -> str:
"""Controller name for UI display."""
return self.__class__.__name__
class NoController(BaseController):
"""No control - robot falls naturally."""
def compute_action(self, obs: np.ndarray, data) -> np.ndarray:
return np.zeros(self.num_joints)
@property
def name(self) -> str:
return "None (Free Fall)"
|