Receiving data from URScript via Python

Hi, I’m using TCP/IP primary client interface to control the robot through Python. I am able to send URScript commands through Python to move the robot, but am not able to receive data. For example, I cannot seem to properly execute the get_actual_tcp_pose command. This is my code for receiving data:

s.send(command.encode('utf-8'))
received_data = s.recv(1024)
print(received_data)

When I print received_data, I get a long binary list (like: which does not seemingly change between commands. What am I doing wrong?

The binary dump looks like: b’\x00\x00\x007\x14\xff\xff\xff\xff\xff\xff\xff\xff\xfe\x03\tURControl\x05\x04\x00\x00\x00\x00\x00\x00\x00\x0021-06-2019, 10:03:02\x00\x00\x00\x18\x14\xff\xff\xff\xff\xff\xff\xff\xff\xfe\x0c\x00\x00\x00\x00\x00\x00…

Try to .decode(“utf-8”) the return message.

I tried that, now I’m getting an error saying “UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xff in position 5: invalid start byte”. Do you know what might be causing this?

Is there some way to enable receiving messages? Because no matter what I send, I always receive the same binary dump with recv. The received data never changes

Hi @ak6,

The data you are receiving is not directly related to the data you are sending, it contains all relevant data from the controller sent out at regular intervals, the script code you send to this port will execute but you will not be able to receive return values in this way.

Recommend you check out the below third party library for an easy way to get started talking to the robot with python:

https://sdurobotics.gitlab.io/ur_rtde/introduction/introduction.html

1 Like

So with primary interface, there is no way to receive data from the robot? I can only use RTDE to receive data?

Look at the documents at the end of this site: Remote Control Via TCP/IP - 16496
In the excel document for exmaple point 5.9 there are listed all data, which the primary and secondary clients send. Maybe the list contain the data which you are looking for? But note: New data are available only every 100 ms. If you need other data or higher refresh rate, you can look at the end of the excel document “RealTime” or to this site Real-Time Data Exchange (RTDE) Guide - 22229. But before you use the RealTime client you should use the recommended RTDE.

1 Like

Thanks! Besides the faster refresh rate, what are the other advantages of the RTDE? I am able to now receive data via the primary interface and am wondering if RTDE offers more useful advantages.

I don’t know more advantages. I have never used RTDE in my applications. The primary and secondary client were always enough.

So RTDE is a more robust protocol, that is better at ensuring your data is exchanged at the required frequency, and you can specify in a recipe file which specific data fields you would like to receive. Primary and secondary just throw everything out at you and the burden is on you to unpack it and sift through for that you want, the controller doesn’t care whether you received it or not.

Also the format of the datastreams is likely to change between software releases, which can be troublesome, this won’t be an issue with RTDE.

2 Likes