How do I use the RTDE with Python?

I have been trying to understand the RTDE, following the guides and example code but I do not understand how to implement the RTDE in such a way that I can read a signal from the UR cobot. I am completely lost.

Hello everyone,

I face a similar situation, but probably we should ask a specific question so that others can help more easily. I’ll give it a shot, maybe it describes your problem as well @ncoope13.

So, with all the example files and a nice youtube playlist explaining their meaning, I still wonder…

  1. which parts of the code I actually need to modify. In my case, I don’t care yet about the exact moves of the robot. My point is just to have SOME data to be read out into a csv file (or anything else), as a proof of concept that I can make RTDE work. All else will follow.
    I know that the IP of the robot must be set in the parameter robot_host in, but I’m not sure what else I need to change. Any idea?

  2. Which of the files will I have to execute to initiate RTDE once all parameters are set, and how? Just run files within the IDE while being connected to the UR?

Sorry for my beginner’s knowledge only (quite new with Python programming, and totally new to UR), and sorry for intervening in your thread @ncoope13, but I guess we are looking for the same kind of answers.

1 Like

I am happy to see that videos I made were useful for some :slight_smile:
After 2 years of working with the UR5e I can tell you the following:

  • if you really need to work in 500HZ then go with RTDE
  • else I recommend to use this code (Bitbucket) I have been using it for a while now, and was able to implement quite sophisticated control methods with success but in slower rate (125HZ)

Try using this script:

All you need to do is to connect your Pc with your cobot via ethernet, change the IP-address in line 38 from the file, it should be the same as the one you gave ur cobot and you need to change the ipv4-address from your ethernet port into an ip-address with the same sub network.


First thing, ping the robot in the command window to see if you got a connection.

Second modify the script. Any time I modify a script I rename to something like

Put your robot IP address in the code below:

parser = argparse.ArgumentParser()
“–host”, default=“your robot IP address”, help=“name of host to connect to (localhost)”

Change the following code

“–samples”, type=int, default=0, help=“number of samples to record”


“–samples”, type=int, default=10, help=“number of samples to record”

When you do this only ten lines of data will be recorded…

Open the record_data.csv file and see if data was retrieved.

Let me know if this helps.

If it does I can assist you some more.

RTDE (Real-Time Data Exchange) is a protocol for real-time communication between a robot controller and an external device, such as a PC running Python. Here are the general steps to use RTDE with Python:

Install the RTDE library: You can install the RTDE library using pip by running the following command in the terminal: pip install rtde.

Connect to the robot controller: Establish a connection between your PC and the robot controller using Ethernet. Make sure that the robot controller has RTDE enabled and that the IP address of the PC is in the same subnet as the robot.

Initialize the RTDE interface: Create an RTDE interface object in Python using the IP address of the robot controller and the desired RTDE protocol version, like this:

Copy code
from rtde import RTDE
rtde = RTDE(“”, 30004)
Start the RTDE communication: Start the RTDE communication using the rtde.connect() method.

Configure the RTDE inputs and outputs: Use the rtde.setSpeedSliderFraction() method to set the speed slider fraction, and use the rtde.setInputBooleanRegisters() method to configure the RTDE inputs.

Read and write RTDE data: Use the rtde.getInputBooleanRegisters() method to read RTDE input data, and use the rtde.setControllerCommand() method to write RTDE output data.

Close the RTDE connection: Use the rtde.disconnect() method to close the RTDE connection when you are done.

It is important to note that the specific usage and configuration of RTDE with Python may vary depending on the specific robot controller and RTDE application. You may need to consult the documentation of your robot controller and the RTDE library for more detailed instructions and examples.

Rachel Gomez

This article has some great resources and examples.