movej
Control robot joint movement by sending precise angular positions to a Universal Robot via its IP address. Specify joint angles, acceleration, speed, duration, and blending radius for accurate motion.
Instructions
发送新的关节姿态到指定IP的机器人,使每个关节都旋转至指定弧度。 IP:机器人地址 q:各关节角度 a:加速度(米每平方秒) v:速度(米每秒) t:移动时长(秒) r:交融半径(米)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| a | No | ||
| ip | Yes | ||
| q | Yes | ||
| r | No | ||
| t | No | ||
| v | No |
Implementation Reference
- The primary handler for the 'movej' MCP tool. It registers the tool via @mcp.tool() decorator, checks connection, sends the movej command to the UR robot via URBasic, and confirms success using movejConfirm.@mcp.tool() def movej(ip: str, q: dict, a=1, v=1, t=0, r=0): """发送新的关节姿态到指定IP的机器人,使每个关节都旋转至指定弧度。 IP:机器人地址 q:各关节角度 a:加速度(米每平方秒) v:速度(米每秒) t:移动时长(秒) r:交融半径(米)""" try: if '连接失败' in link_check(ip): return return_msg(f"与机器人的连接已断开。") cmd = f"movej({q},{a},{v},{t},{r})" robot_list[ip].movej(q, a, v, t, r) result = movejConfirm(ip, q) if result == 1: return return_msg(f"命令 {cmd} 已发送,移动完成。") else: return return_msg(f"命令 {cmd} 已发送,移动失败。") except Exception as e: logger.error(f"发送新的关节姿态到UR机器人失败: {str(e)}") return return_msg(f"发送新的关节姿态到UR机器人: {str(e)}")
- Helper function used by movej to confirm if the robot has reached the target joint positions accurately after the move.def movejConfirm(ip, q): """ movej移动的结果确认 1:移动到位 2:移动结束,但是位置不准确 """ loop_flg = True count = 0 while loop_flg: time.sleep(1) current_pose = round_pose(robot_list[ip].get_actual_joint_positions()) if right_pose_joint(current_pose, q): 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
- Helper to round pose values to 3 decimal places, used in movejConfirm.def round_pose(pose): """给坐标取近似值,精确到三位小数""" pose[0] = round(pose[0], 3) pose[1] = round(pose[1], 3) pose[2] = round(pose[2], 3) pose[3] = round(pose[3], 3) pose[4] = round(pose[4], 3) pose[5] = round(pose[5], 3) return pose
- Helper to check if current joint pose is within 0.1 radian tolerance of target, used in movejConfirm.def right_pose_joint(current_pose, q): """关节的弧度验证,允许0.1的误差,按角度计算大约5度""" if q[0] + 0.1 >= current_pose[0] >= q[0] - 0.1: if q[1] + 0.1 >= current_pose[1] >= q[1] - 0.1: if q[2] + 0.1 >= current_pose[2] >= q[2] - 0.1: if q[3] + 0.1 >= current_pose[3] >= q[3] - 0.1: if q[4] + 0.1 >= current_pose[4] >= q[4] - 0.1: if q[5] + 0.1 >= current_pose[5] >= q[5] - 0.1: return True return False