get_robot_mode
Retrieve the current operating mode of a Universal Robot by IP address. Enables real-time status monitoring for robot control.
Instructions
获取指定IP机器人的运行状态 IP:机器人地址
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ip | Yes |
Implementation Reference
- The main tool handler for 'get_robot_mode'. It checks connection via link_check, calls DashboardClient.ur_robotmode(), and returns the robot's running status as a JSON string.
@mcp.tool() def get_robot_mode(ip: str): """获取指定IP机器人的运行状态 IP:机器人地址""" try: if '连接失败' in link_check(ip): return return_msg(f"与机器人的连接已断开。") robot_list[ip].robotConnector.DashboardClient.ur_robotmode() logger.info(f"IP为{ip}的优傲机器人的运行状态为: {robot_list[ip].robotConnector.DashboardClient.last_respond}") return return_msg( f"IP为{ip}的优傲机器人的运行状态为: {robot_list[ip].robotConnector.DashboardClient.last_respond}") except Exception as e: logger.error(f"运行状态获取失败: {str(e)}") return return_msg(f"运行状态获取失败: {str(e)}") - src/nonead_universal_robots_mcp/server.py:310-310 (registration)The tool is registered via the @mcp.tool() decorator on the get_robot_mode function. MCP is a FastMCP instance created on line 31.
@mcp.tool() - Helper function return_msg formats the output as JSON string for the tool response.
def return_msg(txt: str): return json.dumps(txt, indent=2, ensure_ascii=False) - Helper function link_check verifies the robot connection before executing the tool logic.
def link_check(ip): """检查连接状态,若连接断开或不存在,则建立连接""" if robot_list.get(ip, "unknown") == "unknown" or not robot_list[ ip].robotConnector.RTDE.isRunning(): return connect_ur(ip) return '连接成功' - URBasic/dashboard.py:121-137 (schema)Underlying DashboardClient method ur_robotmode() that sends the 'robotmode' command to the UR robot and reads back the mode response.
def ur_robotmode(self): ''' Robot mode enquiry Return value to Log file: "Robotmode: <mode>", where <mode> is: NO_CONTROLLER DISCONNECTED CONFIRM_SAFETY BOOTING POWER_OFF POWER_ON IDLE BACKDRIVE RUNNING ''' self.__send('robotmode\n')