RTDE Client example

This example shows how to use the RTDEClient class for the robot’s Real-Time Data Exchange (RTDE) interface.

The RTDE client has to be initialized with a list of keys that should be streamed from the robot and a list of keys that should be sent to the robot. The client will then start a background thread establishing communication.

In this example, those keys are stored in two text files relative to this repository’s root: rtde_input_keys.txt and rtde_output_keys.txt. The example will read those files and use them to initialize the RTDE client.

Internally, the RTDE client uses the same producer / consumer architecture as show in the Primary Pipeline example example. However, it doesn’t have a consumer thread, so data has to be read by the user to avoid the pipeline’s queue from overflowing.

Creating an RTDE Client

An RTDE client can be directly created passing the robot’s IP address, a INotifier object, an output and an input recipe. Optionally, a communication frequency can be passed as well. If that is omitted, RTDE communication will be established at the robot’s control frequency.

An RTDE data package containing every key-value pair from the output recipe can be fetched using the getDataPackage() method. This method will block until a new package is available.

Reading data from the RTDE client

Once the RTDE client is initialized, we’ll have to start communication separately. As mentioned above, we’ll have to read data from the client once communication is started, hence we start communication right before a loop reading data.

Writing Data to the RTDE client

In this example, we use the RTDE client to oscillate the speed slider on the teach pendant between 0 and 1. While this doesn’t bear any practical use it shows how sending data to the RTDE interface works.

To send data to the RTDE client, we can use RTDEWriter object stored in the RTDE client. This has methods implemented for each data type that can be sent to the robot. The input recipe used to initialize the RTDE client has to contain the keys necessary to send that specific data.

Note

Many RTDE inputs require setting up the data key and a mask key. See the RTDE guide for more information.