connect_ur
Connects to a Universal Robots cobot using its IP address for direct control and data exchange.
Instructions
根据用户提供的IP连接UR IP:机器人地址
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ip | Yes |
Implementation Reference
- src/nonead_universal_robots_mcp/server.py:187-188 (registration)Tool registration via @mcp.tool() decorator on connect_ur function
@mcp.tool() def connect_ur(ip: str): - Main handler for connect_ur tool - accepts an IP, creates a URBasic robot model and connection, stores it in robot_list global dict
def connect_ur(ip: str): """根据用户提供的IP连接UR IP:机器人地址""" try: host = ip global robot_list, robotModle_list if robot_list.get(ip, "unknown") != "unknown": robot_list[ip].robotConnector.close() return return_msg(f"优傲机器人连接失败: {ip}") robotModle = URBasic.robotModel.RobotModel() robot = URBasic.urScriptExt.UrScriptExt(host=host, robotModel=robotModle) robot_list[ip] = robot robotModle_list[ip] = robotModle if robot_list.get(ip, "unknown") == "unknown" or not robot_list[ ip].robotConnector.RTDE.isRunning(): return return_msg(f"优傲机器人连接失败: {ip}") logger.info(f"连接成功。IP:{host}") return return_msg(f"连接成功。IP:{host}") except Exception as e: logger.error(f"优傲机器人连接失败: {str(e)}") return return_msg(f"优傲机器人连接失败: {str(e)}") - Input schema: connect_ur(ip: str) - takes a single string parameter 'ip' for the robot address
def connect_ur(ip: str): - link_check helper calls connect_ur to re-establish connection if robot not connected
def link_check(ip): """检查连接状态,若连接断开或不存在,则建立连接""" if robot_list.get(ip, "unknown") == "unknown" or not robot_list[ ip].robotConnector.RTDE.isRunning(): return connect_ur(ip) return '连接成功' - return_msg helper used by connect_ur to format JSON responses
def return_msg(txt: str): return json.dumps(txt, indent=2, ensure_ascii=False)