Skip to content

快速开始

最小可运行示例:连接控制器、获取版本、读取位置。

python
import nrc_interface as nrc

# 1. 连接
fd = nrc.connect_robot("192.168.1.15", "6001")
if fd <= 0:
    print("连接失败")
    exit(1)

print("连接成功!fd =", fd)
print("SDK 版本:", nrc.get_library_version())

# 2. 获取当前位置
pos = nrc.VectorDouble(7)
nrc.get_current_position(fd, 0, pos)
print("关节位置:", [pos[i] for i in range(7)])

# 3. 断开
nrc.disconnect_robot(fd)

安全运动示例

安全警告: 以下代码会导致机器人运动!确保工作空间内没有人员或障碍物,急停按钮在可触及范围内,首次运行时用低速。

python
import nrc_interface as nrc
import sys

CONTROLLER_IP = "192.168.1.16"
CONTROLLER_PORT = "6001"

def move_joint(fd, target_pos):
    cmd = nrc.MoveCmd()
    cmd.coord = 0
    cmd.targetPosType = nrc.PosType_data
    cmd.targetPosValue = target_pos
    cmd.velocity = 20
    cmd.acc = 20
    cmd.dec = 20
    cmd.pl = 5
    nrc.queue_motion_push_back_moveJ(fd, cmd)
    nrc.queue_motion_send_to_controller(fd, 1)

fd = nrc.connect_robot(CONTROLLER_IP, CONTROLLER_PORT)
if fd <= 0:
    sys.exit(1)

pos = nrc.VectorDouble(7)
nrc.get_current_position(fd, 0, pos)
current = [pos[i] for i in range(7)]
print("当前位置:", current)

# 在当前位置基础上微调
nrc.queue_motion_set_status(fd, True)
current[0] -= 1
move_joint(fd, nrc.VectorDouble(current))

下一步