import logging

logger = logging.getLogger(__name__)

class UnitreeRobotAdapter:
    """宇树机器人适配器（模拟模式）"""
    
    def __init__(self):
        self.is_connected = False
        self.mock_mode = True  # 模拟模式，不需要真实硬件

    def connect(self):
        """连接机器人"""
        try:
            self.is_connected = True
            logger.info("成功连接宇树机器人（模拟模式）")
        except Exception as e:
            logger.error(f"连接失败: {str(e)}")
            raise

    def move(self, velocity: float, duration: float = 1.0):
        """
        控制机器人运动
        :param velocity: 运动速度 (0-3 m/s)
        :param duration: 运动持续时间(秒)
        """
        if not 0 <= velocity <= 3:
            raise ValueError("速度超出有效范围 (0-3 m/s)")
        
        if self.mock_mode:
            logger.info(f"模拟移动: 速度={velocity}m/s, 持续={duration}秒")
            return

    def get_status(self):
        """获取当前状态"""
        if self.mock_mode:
            return {"status": "connected", "mode": "mock"}
        return None

    def emergency_stop(self):
        """紧急停止"""
        if self.mock_mode:
            logger.warning("已触发紧急停止（模拟模式）")

    def disconnect(self):
        """断开连接"""
        self.is_connected = False
        logger.info("已断开机器人连接")