ur-rtde

1.6.3 · active · verified Thu Apr 16

ur-rtde is a Python interface for controlling and receiving data from Universal Robots (UR) manipulators using the Real-Time Data Exchange (RTDE) interface of the robot. It is a C++ library with Python bindings, providing fast and lightweight communication. The current version is 1.6.3, released on March 13, 2026. The library is actively maintained with a somewhat regular, though not strictly fixed, release cadence.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to connect to a Universal Robot using the RTDE Receive and Control interfaces, retrieve current joint positions, and prepare for sending commands. Ensure your robot's IP address is correct and the 'External Control' URCap is running on the robot controller for control commands. The commented-out sections show examples of moving the robot and controlling I/O. **Always ensure robot movements are safe before execution.**

import rtde_control
import rtde_receive
import rtde_io
import time

# Replace with your robot's IP address
ROBOT_IP = os.environ.get('UR_ROBOT_IP', '192.168.1.10')

try:
    # Initialize RTDE interfaces
    rtde_r = rtde_receive.RTDEReceiveInterface(ROBOT_IP)
    rtde_c = rtde_control.RTDEControlInterface(ROBOT_IP)
    rtde_io_ = rtde_io.RTDEIOInterface(ROBOT_IP)

    if not rtde_r.isConnected():
        print(f"Could not connect to RTDE Receive interface at {ROBOT_IP}")
        exit()
    if not rtde_c.isConnected():
        print(f"Could not connect to RTDE Control interface at {ROBOT_IP}")
        exit()

    print("Successfully connected to the robot.")

    # Start synchronization
    rtde_r.startFileSynchronization("") # No recipe file for quickstart, use default
    rtde_c.sendStart()

    # Example: Read a robot state (joint positions)
    print(f"Current Joint Positions: {rtde_r.getActualQ()}")

    # Example: Send a simple move command (blocking)
    # NOTE: Ensure the robot is in 'Remote Control' mode and 'External Control' URCap is running on the robot.
    # This example assumes the robot is ready to receive commands.
    # Make sure this move is safe for your robot setup.
    # target_q = [-1.5, -1.8, 1.8, -1.8, -1.5, 0.0] # Example joint configuration in radians
    # if rtde_c.moveJ(target_q, 0.5, 0.3): # speed, acceleration
    #     print("Robot moved to target joint configuration.")
    # else:
    #     print("Failed to move robot.")

    # Example: Set a digital output
    # rtde_io_.setStandardDigitalOut(0, True)
    # print("Set digital output 0 to True")
    # time.sleep(1)
    # rtde_io_.setStandardDigitalOut(0, False)
    # print("Set digital output 0 to False")

finally:
    # Stop RTDE communication and disconnect
    if 'rtde_c' in locals() and rtde_c.isConnected():
        rtde_c.sendPause()
        rtde_c.disconnect()
        print("Disconnected RTDE Control Interface.")
    if 'rtde_r' in locals() and rtde_r.isConnected():
        rtde_r.disconnect()
        print("Disconnected RTDE Receive Interface.")

view raw JSON →