发布时间: 2026-01-30

二次开发启动流程


1. 简介

客户应用场景中可能会要求使用 SDK 来开发,下面介绍 SDK 启动机器人方法,过程中请保持机器人为远程模式(REMOTE),与示教器操作大体一致只是以代码的形式分步执行,清除报错,上使能,同步,编码器校准等功能,至机器人处于可运行状态。

 

以下各指令代码可参考SDK手册

2. 操作流程

2.1 初始化状态

机器人开机处于初始化状态(通过虚拟输出 m473 判断,1 表示未完成初始化状态,0 表示完成初始化状态),指令函数可使用getVirtualOutput。

获取初始化状态代码示例():

# 获取虚拟输出 IO 状态(初始化状态)
def getVirtualOutput():
    # 获取虚拟输出 IO 状态(初始化状态)参数: addr:虚拟 IO 地址,范围:int[400,1535]
    # m473:1 表示未完成初始化状态,0 表示完成初始化状态
    ret, result, id = sendCMD(sock, "getVirtualOutput", {"addr": 473})
    print("获取初始化状态")
    if (ret == True):
        print("result = ", result)
        time.sleep(0.1)
    else:
        print("err_msg = ", result["message"])
    return (result)

2.2 清除报错并释放抱闸

如上序初始化判断为未初始化状态则需要使用 clearAlarm 指令对机器人清错和打开抱闸。机器人抱闸打开情况可以通过 get_servo_brake_off_status 函数判断。

清除报错并等待抱闸释放代码示例():

# 清 除 警 报 并 等 待 抱 闸 释 放
def clearAlarm():
    ret, result, id = sendCMD(sock,"clearAlarm")
    print("清 除 报 警 等 待 抱 闸 释 放")
    # print("ret = ", ret, " ", "id = ", id)
    if (ret == True):
        brakeopen = [0, 0, 0, 0, 0, 0]
        # 获取伺服抱闸打开情况
        suc, brakeopen, id = sendCMD(sock, "get_servo_brake_off_status")
        b_sum = 0
        # brakeopen 为6个轴抱闸打开情况,打开为 1,不然为 0,全部打开为[1,1,1,1,1,1]
        for d in brakeopen:
            b_sum = b_sum + d
        while b_sum != 6:
            # 获取伺服抱闸打开情况
            suc, brakeopen, id = sendCMD(sock, "get_servo_brake_off_status")
            b_sum = 0
            for d in brakeopen:
                b_sum = b_sum + d
            time.sleep(0.1)
            # 等待 6 个轴抱闸全部打开
        print("已释放:result = ", result)
        time.sleep(0.1)
    else:
        print("err_msg = ", result["message"])

2.3 获取同步状态并同步

获取机器人同步状态 getMotorStatus,若未同步执行同步指令 syncMotorStatus。

获取同步状态代码示例():

# 获 取 同 步 状 态 并 同 步
def getMotorStatus():
    ret, result, id = sendCMD(sock,"getMotorStatus")
    print("获 取 同 步 状 态")
    if (result == False):
        # 同 步
        ret1, result1, id = sendCMD(sock,"syncMotorStatus")
        # print("ret = ", ret1, " ", "id = ", id)
        if (ret1 == True):
            print("已同步:result = ", result1)
        else:
            print("err_msg = ", result1["message"])

 

2.4 打开伺服使能

机器人使用运动功能或运动指令时需打开伺服使能,上使能后才能执行。

# 打 开 伺 服
def status():
    ret, result, id = sendCMD(sock, "getServoStatus")
    if (result == False):
        ret, result, id = sendCMD(sock,"set_servo_status",{"status":1})
        print("打 开 伺 服")
        # print("ret = ", ret, " ", "id = ", id)
        if (result == True):
            print("伺服已打开:result = ", result)
            time.sleep(0.1)
        else:
            print("err_msg = ", result["message"])

2.5 获取机器人是否处于精确模式

判断机器人是否处于精确模式(通过虚拟输出 m472 判断,0 表示未校准模式,1 表示精确模式),若未校准,执行校准操作 calibrate_encoder_zero_position,并等待机器人达到m472=1 的精确模式。

获取机器人是否处于精确模式并执行精确模式指令示例():

# 编码器零位校准
def calibrate_encoder_zero_position():
    suc, rb_calib, id = sendCMD(sock, "getVirtualOutput", {"addr": 472})
    # print("编码器零位状态")
    if rb_calib == 0:
        ret, result, id = sendCMD(sock, "calibrate_encoder_zero_position")
        if (ret == True):
            suc, rb_calib, id = sendCMD(sock, "getVirtualOutput", {"addr": 472})
            while rb_calib == 0:
                suc, rb_calib, id = sendCMD(sock, "getVirtualOutput", {"addr": 472})
            time.sleep(0.1)
        else:
            print("err_msg = ", result["message"])          

3. 汇总

操作流程的2.1-2.5汇总在一起就可以实现SDK一键启动至可运行状态(见下图)。

# 机器人IP地址
robot_ip = "192.168.1.200"
#建立连接
conSuc, sock = connectETController(robot_ip)
print(conSuc)
#获取初始化状态
# ret: 1 表示未完成初始化状态,0 表示完成初始化状态
ret = getVirtualOutput()
if ret == 1:
    # 清除警报完成初始化状态
    clearAlarm()
# 获取同步状态并同步
getMotorStatus()
#打开伺服
status()
# 编码器零位校准
calibrate_encoder_zero_position()

注:所有SDK指令代码运行时,需要机器人处于远程模式(REMOTE)

 

提交反馈