服务器的固定IP地址:127.0.0.1
机器臂的IP地址:192.168.0.156
端口:10003
采用TCP/IP通信,机器臂当服务端,自己电脑当客户机,故修改自己电脑IP地址为192.168.0.157,使其在同一个域即可通信。
用cmd调出控制界面 然后 ping 192.168.0.156
ping成功之后就可以用串口助手调试发送指令
尝试发送PCS2ACS,0,-400,200,200,-90,0,90,; 这个是一求各轴角度的一条指令,就是把当前姿态,转化为6个轴的角度
然后返回PCS2ACS,OK,-42.93,18.0313,-137.192,134.305,-72.1305,-72.5478,;
发送MoveJ,0,-42.93,18.0313,-137.192,134.305,-72.1305,-72.5478,; 机械臂开始移动
实现一个扫描正方形动作
import random
import re
import time
import socket
print("start test")
# 1. 创建tcp的套接字
tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# 2. 链接服务器
server_ip = "192.168.0.10"#156
server_port = 10003
server_addr = (server_ip, server_port)
tcp_socket.connect(server_addr)
time.sleep(5)
#3.开始运动
x=-400
for z in range (200,601,100):
for y in range (-200,201,100):
d="PCS2ACS"+","+"0,"+str(x)+","+str(y)+","+str(z)+","+"-90,0,90,;"
send_data = d
print(d)
tcp_socket.send(send_data.encode("utf-8"))
receive=tcp_socket.recv(1024)
receive=receive.decode()
print(receive)
m=re.split(",",receive)
d="MoveJ"+","+"0,"+m[2]+","+m[3]+","+m[4]+","+m[5]+","+m[6]+","+m[7]+",;"
print(d)
send_data = d
tcp_socket.send(send_data.encode("utf-8"))
receive=tcp_socket.recv(1024)
receive=receive.decode()
while(1):
d="ReadRobotState,0,;"
send_data = d
tcp_socket.send(send_data.encode("utf-8"))
receive=tcp_socket.recv(1024)
receive=receive.decode()
m=re.split(",",receive)
if m[2]=='0':
break
time.sleep(0.5)
m=[]