Home› Programming
Discussion
Back to discussions page
RobTop
Posts: 7 Apprentice
Python GetCurrentTcpPosition UR5E |
793 views
|
Answered | |
/ Most recent by matthewd92
in Programming
|
11 comments |

in Programming
Hi,
I am working with the ur5e and want to control
Script:
I open the socket connection with python.
I receive the 1108 Bytes and I parse the actual position. I do this in a loop, 1000 times.
But the received position is every time the same.
But the robot is moving.
Now I close the socket
Question:
Why is the sent actual TCP position everytime the same?
Do I have to sent an URScript to the UR5e which is calling the get_actual_tcp_position() and is sending it to a digital out?
I am working with the ur5e and want to control
Script:
I open the socket connection with python.
I receive the 1108 Bytes and I parse the actual position. I do this in a loop, 1000 times.
But the received position is every time the same.
But the robot is moving.
Now I close the socket
Question:
Why is the sent actual TCP position everytime the same?
Do I have to sent an URScript to the UR5e which is calling the get_actual_tcp_position() and is sending it to a digital out?
But why do I need to reconnect to the UR5E to get the current position?
Why doesnt the UR5E send the actual tcp position without reconnecting to him?
I am confused
I am not a python programmer but if you wanted to post the code I would be happy to look at it best I can, maybe others on here could help as well.
I know with nodejs once we establish the socket connection we have to add a listener to the socket that actually listens for the incoming data stream and then passes off each new packet to the code that breaks it down and stores it into the state tree.
my python code:
# Echo client program
import socket
import time
import struct
PORT_30003 = 30003
home_status = 0
program_run = 0
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(10)
s.connect((HOST, PORT_30003))
s.setblocking(0)
while (True):
if program_run == 0:
try:
get_active_tcp(s)
get_active_tcp(s)
get_active_tcp(s)
get_active_tcp(s)
get_active_tcp(s)
get_active_tcp(s)
except socket.error as socketerror:
print("Error: ", socketerror)
home_status = 1
program_run = 0
s.close()
print "Program finish"
//And the get_active_tcp:
def get_active_tcp(s):
time.sleep(1.00)
print ""
packet_1 = s.recv(4)
packet_2 = s.recv(8)
packet_3 = s.recv(48)
packet_4 = s.recv(48)
packet_5 = s.recv(48)
packet_6 = s.recv(48)
packet_7 = s.recv(48)
packet_8 = s.recv(48)
packet_9 = s.recv(48)
packet_10 = s.recv(48)
packet_11 = s.recv(48)
packet_12 = packet_12.encode("hex") #convert the data from \x hex notation to plain hex
x = str(packet_12)
x = struct.unpack('!d', packet_12.decode('hex'))[0]
print "X = ", x * 1000
packet_13 = packet_13.encode("hex") #convert the data from \x hex notation to plain hex
y = str(packet_13)
y = struct.unpack('!d', packet_13.decode('hex'))[0]
print "Y = ", y * 1000
packet_14 = packet_14.encode("hex") #convert the data from \x hex notation to plain hex
z = str(packet_14)
z = struct.unpack('!d', packet_14.decode('hex'))[0]
print "Z = ", z * 1000
packet_15 = packet_15.encode("hex") #convert the data from \x hex notation to plain hex
Rx = str(packet_15)
Rx = struct.unpack('!d', packet_15.decode('hex'))[0]
print "Rx = ", Rx
packet_16 = packet_16.encode("hex") #convert the data from \x hex notation to plain hex
Ry = str(packet_16)
Ry = struct.unpack('!d', packet_16.decode('hex'))[0]
print "Ry = ", Ry
packet_17 = packet_17.encode("hex") #convert the data from \x hex notation to plain hex
Rz = str(packet_17)
Rz = struct.unpack('!d', packet_17.decode('hex'))[0]
print "Rz = ", Rz
packet_18 = s.recv(624)
// UR5-Simulator is running in the VMWare and is in the remote running.
// If I move the Roboter with another script, the Roboter is moving, but no change in the received message.
// But it is a different message because the timestamp in the received message is changing!
// So what is my mistake? Do I have to execute a URScript in the Roboter to get the current tcp?
Like I said, I am not a python programmer so I will have to dig a little deeper. I will try to do a simple nodejs program as well to see if I am seeing similar issues. We do not decode RTE for position data, we use RTDE for all of that now as RTE was deprecated a while ago and they are pushing everyone to RTDE which is a more robust data tool. I would recommend if you are building something new that you take a look at the RTDE documentation. I know there are some sample Python programs on the UR website as well as its a little more complex to set-up and get running.
I need an example with showing the current Position :-)
Hints: starting the record.py with --samples 2500 works
starting without --samples 2500 leads to a corrupt csv file.
For plotting I started example_plot.py
Is RTDE the future?
Is there a sample code for parsing the RTDE Protocol in MATLAB?