draw_rectangle
Create rectangles or squares in horizontal or vertical planes by specifying origin, width, height, and coordinate settings. Use this tool to define precise geometric shapes for Universal Robots via nUR MCP Server.
Instructions
给定起点位置和边长,在水平或竖直方向画一个正方形 origin:画长方形时TCP的起点位置 width:长(米) height:宽(米) coordinate:圆所在的平面。z:圆形所在的平面与基座所在平面垂直,其它:圆形所在的平面与基座所在平面平行。默认值:z。
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| coordinate | No | z | |
| height | Yes | ||
| ip | Yes | ||
| origin | Yes | ||
| width | Yes |
Implementation Reference
- The handler function for the draw_rectangle MCP tool. Decorated with @mcp.tool(), it takes IP, origin, width, height, and coordinate parameters to generate robot movement commands that draw a rectangle in 3D space.def draw_rectangle(ip: str, origin: dict, width: float, height: float, coordinate="z"): """给定起点位置和边长,在水平或竖直方向画一个正方形 origin:画长方形时TCP的起点位置 width:长(米) height:宽(米) coordinate:圆所在的平面。z:圆形所在的平面与基座所在平面垂直,其它:圆形所在的平面与基座所在平面平行。默认值:z。""" try: if '连接失败' in link_check(ip): return return_msg(f"与机器人的连接已断开。") wp_1 = [origin[0], origin[1], origin[2], origin[3], origin[4], origin[5]] wp_2 = [origin[0], origin[1], origin[2], origin[3], origin[4], origin[5]] wp_3 = [origin[0], origin[1], origin[2], origin[3], origin[4], origin[5]] if coordinate.lower() == "z": wp_1[1] = wp_1[1] + width wp_2[1] = wp_2[1] + width wp_2[3] = wp_2[3] - height wp_3[3] = wp_3[3] - height else: wp_1[1] = wp_1[1] + width wp_2[1] = wp_2[1] + width wp_2[0] = wp_2[0] + height wp_3[0] = wp_3[0] + height cmd = (f"movel(p{str(origin)}, a=1, v=0.25)\nmovel(p{str(wp_1)}, a=1, v=0.25)\n" f"movel(p{str(wp_2)}, a=1, v=0.25)\nmovel(p{str(wp_3)}, a=1, v=0.25)\n" f"movel(p{str(origin)}, a=1, v=0.25)") robot_list[ip].robotConnector.RealTimeClient.SendProgram(cmd) return return_msg(f"命令已发送:{cmd}") except Exception as e: logger.error(f"命令发送失败: {str(e)}") return return_msg(f"命令发送失败: {str(e)}")