Last updated
# Universal Robots script for controlling the robot with external python script
while True:
if socket_open("192.168.1.67", 8888):
while True:
values = socket_read_ascii_float(8)
joints = [values[1], values[2], values[3], values[4], values[5], values[6]]
if values[0] > 6:
textmsg("Moving to: ", joints)
movej(joints, v=values[7], a=values[8])
else:
socket_close()
break
end
socket_send_string("target_reached")
end
else:
textmsg("Connecting...")
sleep(1)
end
endimport socket
# connect to robot
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('0.0.0.0', 8888))
server.listen()
connection, address = server.accept()
# function to send move commands
def movej(pose, v=1, a=1):
print("Moving to: {}".format(pose))
connection.send("({}, {}, {}, {}, {}, {}, {}, {})\n".format(pose[0], pose[1], pose[2], pose[3], pose[4], pose[5], v, a).encode())
buf = connection.recv(128)
if len(buf) > 0:
print(buf.decode())
# movements
movej([0.00, -1.57, -1.57, 0.00, 1.57, 0.00])
movej([0.00, -1.57, 0, 0.00, 1.57, 0.00])
movej([0.00, -1.57, -1.57, 0.00, 1.57, 0.00])