Skip to content

Introduction to RTDE Protocol

Introduction

The RTDE (Real-Time Data Exchange) protocol allows for real-time data exchange between the robot controller and external devices. Through the RTDE protocol, external devices can obtain the robot's status information, such as joint angle, end-of-arm tooling's position and attitude, movement speed, and acceleration. In addition, external devices can send control commands to the robot via the RTDE protocol, for example, moving the robot to a specified position by writing codes to the register.

The RTDE protocol has the following characteristics:

  • Real-time: When the robot controller and external devices exchange data through the RTDE protocol, the data transmission is fast and does not compromise the real-time performance of the robot controller.
  • Bi-directional communication: The RTDE protocol supports bi-directional data exchange between the robot controller and external devices, that is, external devices can not only receive robot data, but also send commands.
  • Cross-language and cross-platform: The RTDE protocol supports communication between multiple programming languages (such as C++ and Python) and different platforms.
  • Multiple transport protocols supported: The RTDE protocol can use various transport protocols for data transmission, such as TCP Socket and WebSocket, making it suitable for various network environments.

Supported Transport Protocols and Port Numbers

The RTDE function module in the AUBO SDK supports TCP Socket and WebSocket transport protocols, with the corresponding port numbers as follows:

ProtocolPort number
TCP Socket30010
WebSocket9013

RTDE Protocol Specifications

RTDE Menu

RTDE Menu is a menu that defines the content and format of the RTDE data synchronization packet; it is a specification. It describes the input and output fields that can be synchronized and their data types. The RTDE Menu includes the input menu and output menu. The input menu is for the client to push data to the server, while the output menu is for the server to push data to the client. To know the list of topics and data types in the RTDE Menu, please refer to RTDE Menu.

Request-Response

The client can subscribe to topics, publish topics, and unsubscribe from topics to the server.

Subscribe to Topics

When the client subscribes to a topic, it sends a data packet to the server. The first element of the data packet is the index value, fixed at 100, and the second element is an object that contains the following members: channel, frequency, segments, to_server, and trigger. Among them, the value of to_server is fixed as false, and segments are the members of the output menu in the RTDE Menu. For the definitions of these members, refer to the following RtdeRecipe structure:

c++
struct RtdeRecipe
{
    bool to_server;                    ///<  Input/Output, to_server=false means subscribing to data from the server, while to_server=true means pushing data to the server.
    int chanel;                        ///< Channel  The channel number only supports 0-99.
    double frequency;                  ///<  Update frequency
    int trigger;                       ///< Trigger method (this feature is not yet implemented): 0 - Periodic; 1 - Variable
    std::vector<std::string> segments; ///< Field list, indicating the topics that are in subscription/published.
};

After that, the client will receive the data packet in response from the server. The first element of the data packet is the channel, which is the same value as the channel in subscription. The second and subsequent elements are the data of the topic in subscription.

For example, if you want to subscribe to the topic "R1_actual_q" on channel 0, the data packet sent by the client to the server is as follows:

bash
[100,{"chanel":0,"frequency":50.0,"segments":["R1_actual_q"],"to_server":false,"trigger":0}]

The response of the server received by the client is as follows:

bash
[0,[-0.027531569059195515,-0.28143723119618147,1.6961810563264004,0.4177235477634482,1.5627876064666573,-0.03521353669519756]]

In the above example, the first element in the data packet means channel 0, and the second element is the value of the topic "R1_actual_q" in subscription, which represents the actual values of the six joint angles.

Unsubscribe from Topics

After subscribing to a topic, the client will continuously receive data sent from the server. To cancel the push, the client can unsubscribe from the topic. The data packet format for unsubscribing from a topic is the same as that for subscribing to a topic, but frequency shall be set to 0, channel shall be set to the channel of the topic to be canceled, and segments shall be empty.

For example, to unsubscribe from the topic on channel 0,

bash
[100,{"chanel":0,"frequency":0.0,"segments":[],"to_server":false,"trigger":0}]

Publish Topics

When the client publishes a topic, it sends a data packet to the server. The first element of the data packet is the index value, fixed at 100, and the second element is an object that contains the following members: channel, frequency, segments, to_server, and trigger. Among them, the value of to_server is fixed as true, and segments are the members of the input menu in the RTDE Menu. For the definitions of these members, refer to the following RtdeRecipe structure:

C++
struct RtdeRecipe
{
    bool to_server;                    ///<  Input/Output, to_server=false means subscribing to data from the server, while to_server=true means pushing data to the server.
    int chanel;                        ///<  Channel  The channel number only supports 0-99.
    double frequency;                  ///< Update frequency
    int trigger;                       ///< Trigger method (this feature is not yet implemented): 0 - Periodic; 1 - Variable
    std::vector<std::string> segments; ///< Field list, indicating the topics that are in subscription/published.
};

Then, the client pushes data to the server. The first element of the data packet is the channel, the same value as the channel for publishing the topic. The second and subsequent elements are the data of the published topic.

For example, to publish the topic "input_float_registers_0" and "input_double_registers_1" on channel 1, the data packet sent from the client to the server would be:

bash
[100,{"chanel":1,"frequency":1.0,"segments":["input_float_registers_0","input_double_registers_1"],"to_server":true,"trigger":0}]

Then, the client pushes data to the server:

bash
[1,3.1,4.1]

In the above example, the first element in the data packet represents channel 1, and the second and third elements represent the values of "input_float_registers_0" and "input_double_registers_1", respectively.

To check if the data is successfully pushed, you can subscribe to the topics "input_float_registers_r0" and "input_double_registers_r1":

bash
[100,{"chanel":1,"frequency":1.0,"segments":["input_float_registers_r0","input_double_registers_r1"],"to_server":false,"trigger":0}]

If the data is successfully pushed, the response received by the client from the server will be:

bash
[1,3.0999999046325684,4.1]

Example

An example of websocket protocol transmission written in Python is as follows:

localhost is the IP address of the robot

python
import asyncio
import websockets


async def rtde_communication():
    uri = "ws://localhost:9013"
    async with websockets.connect(uri) as websocket:
        # Publish Topics
        publish_topic = '[100,{"chanel":1,"frequency":1.0,"segments":["input_float_registers_0",' \
                        '"input_double_registers_1"],"to_server":true,"trigger":0}] '
        await websocket.send(publish_topic)

        # Push Data to Server
        publish_data = '[1,3.3,4.4]'
        await websocket.send(publish_data)

        # Subscribe to Topics
        subscribe_topic = '[100,{"chanel":1,"frequency":50.0,"segments":["input_float_registers_r0",' \
                          '"input_double_registers_r1"],"to_server":false,"trigger":0}] '
        await websocket.send(subscribe_topic)

        # Receive the RTDE Data Packet
        while True:
            data_packet = await websocket.recv()
            print("Received data packet:", data_packet)


asyncio.get_event_loop().run_until_complete(rtde_communication())

Program running result:

Received data packet: [1,3.299999952316284,4.4]
Received data packet: [1,3.299999952316284,4.4]
Received data packet: [1,3.299999952316284,4.4]
Received data packet: [1,3.299999952316284,4.4]
Received data packet: [1,3.299999952316284,4.4]
Received data packet: [1,3.299999952316284,4.4]
Received data packet: [1,3.299999952316284,4.4]