5.4 零位校准

示例限制: 下方脚本保留英文原示例中的六关节校准循环及六个角度的输出示例。运行前必须核实 ultraArm P1 当前固件和库支持的关节编号及接口行为。本示例尚未经过实机验证。

使用前准备

使用示例前,请确认以下硬件及环境已准备就绪:

  • 硬件
    • ultraArm P1 机械臂
    • 网线(连接机械臂与电脑)
    • 电源适配器
    • 急停开关(用于安全操作)
  • 软件与环境
    • 已安装 Python 3.6 或更高版本,参阅 Python 环境搭建。
    • 已通过终端命令 pip install ultraArm_P1_lib 安装 ultraArm_P1_lib 库。
    • 确保机械臂已正常通电并处于待机状态。
    • 注意: P1 服务端在开机后自动启动,无需手动操作。
  • 网络配置
    • 机械臂默认 IP 地址:192.168.0.232
    • 默认端口:4500
    • 电脑网卡 IP 地址必须与机械臂处于同一网段,例如 192.168.0.xxx,其中 xxx 为 2~254 且不能与机械臂冲突。
    • 具体操作参阅静态 IP 配置。
    • 配置示例:机械臂 IP 为 192.168.0.232,电脑 IP 为 192.168.0.100,子网掩码为 255.255.255.0,DNS 为 114.114.114.114。
    • 配置完成后,在电脑终端执行以下命令。能够收到返回的数据包,说明网络连通。
ping 192.168.0.232

关节零位校准

功能说明

本示例用于对 ultraArm P1 机械臂进行关节零位校准。零位校准会影响后续所有运动的准确性,请严格按照步骤操作。

操作前安全须知

  • 校准过程中,所有关节将会放松。
  • 机械臂可能因重力而突然下落。
  • 请务必用双手稳稳托住机械臂。
  • 确保周围没有其他人员或障碍物。

第一步:创建零位校准脚本

新建 set_joint_zero.py 文件,写入以下代码。为保证中英文示例一致,代码中的提示信息保留英文。

import time
from ultraArm_P1_lib import P1Client

def safe_input(prompt):
    """Safe yes/no input"""
    while True:
        ans = input(prompt + " (yes/no): ").strip().lower()
        if ans in ('y', 'yes'):
            return True
        elif ans in ('n', 'no'):
            return False
        else:
            print("Please enter y/yes or n/no")

def read_angles(p1_arm, retry=3, delay=0.2):
    """Safely read joint angles"""
    for _ in range(retry):
        angles = p1_arm.get_angles()
        if isinstance(angles, list):
            return angles
        time.sleep(delay)
    return None

def check_zero_position(angles, tolerance=0.5):
    """Check if the angle is close to zero."""
    if angles is None:
        return False, None
    ok = all(abs(a) <= tolerance for a in angles)
    off_joints = [f"J{i+1}:{round(a,2)}°" for i,a in enumerate(angles) if abs(a) > tolerance]
    return ok, off_joints

def main():
    p1_arm = P1Client('192.168.0.232', 4500)

    # Power-on check
    if p1_arm.is_power_on() != 1:
        print("The robot is not powered on, it is being powered on....")
        p1_arm.power_on()
        time.sleep(0.02)

    if safe_input('The robotic arm is about to relax all joints. Please hold on tight! Type "yes" and press Enter to select "Relax All Joints Now".'):
        p1_arm.set_motor_enabled(254, 0)
        time.sleep(0.02)
    else:
        print("Zero-point calibration has been cancelled.")
        return

    if safe_input('Please manually drag each joint to the zero mark, type "yes" and press Enter to "Lock the joints and perform zero-point calibration".'):
        p1_arm.set_motor_enabled(254, 1)
        time.sleep(0.02)
        # Perform joint zero-position calibration
        for i in range(1, 7):
            p1_arm.set_servo_calibration(i)
            time.sleep(0.05)

        # Calibration complete, reading angle
        angles = read_angles(p1_arm)
        ok, off_joints = check_zero_position(angles)

        if ok:
            print("✅ Zero-position calibration successful. Current angle:{}".format([round(a, 2) for a in angles]))
        else:
            print(f"⚠️ Zero-position calibration failed; the following joints deviated from zero:{off_joints}")
    else:
        print("The joint has been locked, but zero-position calibration has not been performed.")
        p1_arm.set_motor_enabled(254, 1)
        time.sleep(0.02)

if __name__ == "__main__":
    try:
        main()
    except Exception as e:
        print(f"❌ Script execution exception: {e}")

第二步:运行脚本

在终端执行:

python3 set_joint_zero.py

第三步:放松关节

程序会提示即将放松全部关节,要求先托住机械臂,并输入 yes 确认。

The robotic arm is about to relax all joints. Please hold on tight! Type "yes" and press Enter to select "Relax All Joints Now". (yes/no):

确认机械臂已被稳妥支撑后,输入 yes 并按回车。

第四步:校准零位

手动移动各关节,使其对准机械臂上的物理零位刻度线,并保持机械臂稳定。程序会提示锁紧关节并执行零位校准:

Please manually drag each joint to the zero mark, type "yes" and press Enter to "Lock the joints and perform zero-point calibration". (yes/no):

输入 yes 后,程序将锁紧关节并执行校准。

第五步:校准验证

原示例的成功输出如下(实际角度数量应以设备返回值为准):

✅ Zero-position calibration successful. Current angle:[0.0, 0.0, 0.0, 0.0, 0.0, 0.0]

出现成功信息表示脚本的角度检查通过。如果输出警告,请检查关节对齐情况及接口配置后重新校准。


← 上一章 | 下一章 →

results matching ""

    No results matching ""