movel_z
Move the robot's TCP along the Y axis by a specified distance. Provide the robot's IP address and distance in meters.
Instructions
命令指定IP机器人的TCP沿Y轴方向移动 IP:机器人地址 distance:移动距离(米)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ip | Yes | ||
| distance | Yes |
Implementation Reference
- The movel_z tool handler: takes an IP address and a distance (in meters), gets the current TCP pose, adds the distance to the Z-axis component (pose[2]), sends a movel command to the robot, waits for confirmation, and returns the result.
@mcp.tool() def movel_z(ip: str, distance: float): """命令指定IP机器人的TCP沿Y轴方向移动 IP:机器人地址 distance:移动距离(米)""" try: if '连接失败' in link_check(ip): return return_msg(f"与机器人的连接已断开。") pose = robot_list[ip].get_actual_tcp_pose() pose[2] = pose[2] + distance robot_list[ip].movel(pose) time.sleep(1) result = movelConfirm(ip, pose) cmd = (f"def my_program():\n" f" movel(p[{'{:.4f}'.format(pose[0])},{'{:.4f}'.format(pose[1])},{'{:.4f}'.format(pose[2])},{'{:.4f}'.format(pose[3])},{'{:.4f}'.format(pose[4])},{'{:.4f}'.format(pose[5])},],0.5,0.25,0,0)\n" f"end\nmy_program()") logger.info(f"发送脚本:{cmd}") if result == 1: return return_msg(f"命令 {cmd} 已发送,移动完成。") else: return return_msg(f"命令 {cmd} 已发送,移动失败。") except Exception as e: logger.error(f"移动失败: {str(e)}") return return_msg(f"移动失败: {str(e)}") - src/nonead_universal_robots_mcp/server.py:659-659 (registration)Registration of movel_z as an MCP tool via the @mcp.tool() decorator on the FastMCP instance 'mcp'.
@mcp.tool() - Helper function movelConfirm used by movel_z to verify that the movel movement completed successfully.
def movelConfirm(ip, pose): """ movel移动的结果确认 1:移动到位 2:移动结束,但是位置不准确 """ loop_flg = True count = 0 while loop_flg: time.sleep(1) current_pose = round_pose(robot_list[ip].get_actual_tcp_pose()) if right_pose_tcp(current_pose, pose): robot_list[ip].robotConnector.DashboardClient.ur_running() running = robot_list[ip].robotConnector.DashboardClient.last_respond if running == 'Program running: false': return 1 else: robot_list[ip].robotConnector.DashboardClient.ur_running() running = robot_list[ip].robotConnector.DashboardClient.last_respond if running == 'Program running: true': '''尚未移动完成''' continue else: '''移动完成''' count = count + 1 if count > 5: return 2