1. get_current_position - 获取机械臂当前坐标信息
方法: get_current_position(socketFd, coord, pos)
参数:
socket_fd:连接句柄
coord:坐标系类型
pos:输出参数,用于存储当前位置的向量
返回值:
使用示例:
Python
import nrc_interface as nrc
# 建立连接
socket_fd = nrc.connect_robot("192.168.1.13", "6001")
# 获取关节坐标系下的当前位置
current_pos = nrc.VectorDouble()
coord = 0 # 关节坐标系
ret = nrc.get_current_position(socket_fd, coord, current_pos)
if ret == 0:
pos_list = list(current_pos)
print(f"获取位置成功:{pos_list}")
else:
print(f"获取位置失败,错误码:{ret}")
2. get_robot_running_state - 获取作业文件运行状态
方法: get_robot_running_state(socket_fd, run_state)
参数:
socket_fd:连接句柄
run_state:输出参数,用于存储运行状态的向量
返回值:
使用示例:
Python
import nrc_interface as nrc
# 建立连接
socket_fd = nrc.connect_robot("192.168.1.13", "6001")
# 获取机器人运行状态
ret = nrc.get_robot_running_state(socket_fd, run_state)
print("当前运行状态:", ret) # 返回2位,第一位是执行结果,第二位状态
3. get_joint_position - 获取当前关节角度
方法: get_joint_position(socket_fd, dof, joint_pos)
参数:
socket_fd:连接句柄
dof:机械臂自由度,如6或7
joint_pos:输出参数,用于存储关节角度的向量
返回值:
使用示例:
Python
import nrc_interface as nrc
# 建立连接
socket_fd = nrc.connect_robot("192.168.1.13", "6001")
# 创建MoveCmd对象
moveCmd = nrc.MoveCmd()
# 获取7自由度关节角度
ret = nrc.get_joint_position(socket_fd, 7, moveCmd.targetPosValue)
if ret == 0:
joint_angles = list(moveCmd.targetPosValue)
print(f"返回值={ret}")
print(f"关节角度={joint_angles}")
else:
print(f"获取关节角度失败,错误码:{ret}")
4. get_robot_dh_param - 获取机械臂DH参数
方法: get_robot_dh_param(socketFd, param)
参数:
socketFd:连接句柄
param:输出参数,用于存储DH参数的结构体
返回值:
使用示例:
Python
import nrc_interface as nrc
import time
# 建立连接
socket_fd = nrc.connect_robot("192.168.1.13", "6001")
# 创建库自带的DH参数结构体
dh_param = nrc.RobotDHParam()
ret = nrc.get_robot_dh_param(socket_fd, dh_param)
# 读取获取到的数据
print("接口返回码:", ret)
print("=====获取机器人DH参数成功=====")
print("L1=", dh_param.L1)
print("L2=", dh_param.L2)
print("L3=", dh_param.L3)
print("L4=", dh_param.L4)
print("L5=", dh_param.L5)
print("L6=", dh_param.L6)
print("动态限制max=", dh_param.dynamicLimit_max)
print("3轴方向=", dh_param.threeAxisDirection)
print("正倒立模式=", dh_param.upsideDown)
5. get_library_version - 读取机械臂软件信息
方法: get_library_version()
参数:
返回值:
使用示例:
Python
import nrc_interface as nrc
# 获取库版本
version = nrc.get_library_version()
print(f"机器人库版本={version}")
6. get_robot_joint_param - 获取关节参数
方法: get_robot_joint_param(socketFd, id, param)
参数:
socketFd:连接句柄
id:关节轴号,1~7代表第1~7轴
param:输出参数,用于存储关节参数的结构体
返回值:
使用示例:
Python
import nrc_interface as nrc
# 建立连接
socket_fd = nrc.connect_robot("192.168.1.13", "6001")
# 创建关节参数对象
joint_param = nrc.RobotJointParam()
# 调用get_robot_joint_param获取第1轴参数
ret = nrc.get_robot_joint_param(socket_fd, 1, joint_param)
if ret == 0:
print(f"关节参数返回值(ret)={ret}")
print(f"减速比={joint_param.reducRatio}")
print(f"编码器分辨率={joint_param.encoderResolution}")
print(f"正软限位={joint_param.posSWLimit}")
print(f"负软限位={joint_param.negSWLimit}")
print(f"额定转速={joint_param.ratedRotSpeed}")
print(f"最大转速={joint_param.maxRotSpeed}")
print(f"运动方向={joint_param.direction}")
else:
print(f"获取关节参数失败,错误码:{ret}")
7. get_tool_hand_number - 获取当前使用的工具手编号
方法: get_tool_hand_number(socket_fd, tool_num)
参数:
socket_fd:连接句柄
tool_num:输出参数,用于存储工具号的整数变量
返回值:
使用示例:
Python
import nrc_interface as nrc
# 建立连接
socket_fd = nrc.connect_robot("192.168.1.13", "6001")
# 定义整数变量,用于接收结果
toolNum = 0
# 获取工具号
ret = nrc.get_tool_hand_number(socket_fd, toolNum)
print(f"获取工具号返回值(ret)={ret}")
print(f"当前工具号={toolNum}")
8. get_joint_temperature - 获取关节电机温度
方法: get_joint_temperature(socketFd, temperatures)
参数:
socketFd:连接句柄
temperatures:输出参数,用于存储输出的信息
返回值:
使用示例:
Python
import nrc_interface as nrc
# 建立连接
socket_fd = nrc.connect_robot("192.168.1.13", "6001")
joint_temperature = nrc.VectorDouble()
ret = nrc.get_joint_temperature(socket_fd, joint_temperature)
# 打印结果
print(f"返回值:{ret}")
print(f"关节温度:{list(joint_temperature)}")