1 set_current_mode - 设置机器人模式(切换示教模式和运动模式)
方法: set_current_mode(socket_fd:int, mode:int)
参数:
返回值:
使用示例:
Python 复制
import nrc_interface as nrc
import time
#建立连接
socket_fd = nrc.connect_robot ("192.168.1.13" , "6001" )
#设置机器人当前模式
#mode参数说明:
#模式0:示教 1:远程 2:运行
mode = 2 #运行模式
ret = nrc.set_current_mode (socket_fd, mode)
print (f"设置模式返回值(ret)={ret}" )
2 set_digital_output - 设置数字IO输出
方法: set_digital_output(socket_fd:int, port:int, value:int)
参数:
socket_fd:连接句柄
port:输出端口号
value:输出值
返回值:
使用示例:
Python 复制
import nrc_interface as nrc
import time
#建立连接
socket_fd = nrc.connect_robot ("192.168.1.13" , "6001" )
#设置数字输出量
port = 1 #输出端口号
value = 1 #输出值:1=ON/0=OFF
ret = nrc.set_digital_output (socket_fd, port, value)
print (f"设置DO端口{port}输出{value}返回值={ret}" )
time.sleep (0.2 )
3 get_digital_output - 获取所有数字IO
方法: get_digital_output(socket_fd:int, output_values:VectorInt)
参数:
socket_fd:连接句柄
output_values:输出参数,用于存储所有数字输出状态的向量
返回值:
使用示例:
Python 复制
import nrc_interface as nrc
#建立连接
socket_fd = nrc.connect_robot ("192.168.1.13" , "6001" )
#一次获取全部64路数字输出
#_out = nrc.VectorInt()
#for i in range(64):
# _out.push_back(0)
#ret = nrc.get_digital_output(socket_fd, _out)
#print(f"全部DO状态返回值(ret)={ret}")
#print(f"64路DO={list(_out)}")
print ("获取所有数字IO接口使用示例" )
4 get_digital_input - 获取所有IO输入状态
方法: get_digital_input(socket_fd:int, input_values:VectorInt)
参数:
socket_fd:连接句柄
input_values:输出参数,用于存储所有数字输入状态的向量
返回值:
使用示例:
Python 复制
import nrc_interface as nrc
#建立连接
socket_fd = nrc.connect_robot ("192.168.1.13" , "6001" )
#一次获取全部64路数字输入
_in = nrc.VectorInt ()
for i in range (64 ):
_in.push_back (0 )
ret = nrc.get_digital_input (socket_fd, _in)
print (f"全部DI状态返回值(ret)={ret}" )
print (f"64路DI={list(_in)}" )