This section contains guides for how to use the ur_rtde interface.

Realtime Setup Guide

Not done yet.

Use with MATLAB

MATLAB supports calling python library functions, please see this site for more information.

Here is an example of receiving the actual joint and tcp pose from the robot, and moving the robot to some pre-defined cartesian position in MATLAB:

import py.rtde_receive.RTDEReceiveInterface
import py.rtde_control.RTDEControlInterface

rtde_r = RTDEReceiveInterface("localhost");
rtde_c = RTDEControlInterface("localhost");

actual_q = rtde_r.getActualQ();
actual_tcp_pose = rtde_r.getActualTCPPose();

% Convert to MATLAB array of double
actual_q_array = cellfun(@double, cell(actual_q));
actual_tcp_pose_array = cellfun(@double, cell(actual_tcp_pose));


position1 = [-0.343, -0.435, 0.50, -0.001, 3.12, 0.04];
position2 = [-0.243, -0.335, 0.20, -0.001, 3.12, 0.04];



Please notice, it is very important to include the ‘clear’ command and the end of execution, otherwise the ur_rtde threads will continue run in the background and you would not be able to execute the code again until the environment has been cleared.


Currently using the ur_rtde interface has only been tested with MATLAB R2019b using Python 2.7, since this seems to be the default interpreter of MATLAB R2019b. However, it should also work with Python 3.x

Use with Robotiq Gripper

There are currently 3 ways of using a Robotiq gripper with ur_rtde:

  • Option 1: (Sending the robotiq preamble + function to be executed)

You can send the robotiq preamble script together with the function you want to run, using the sendCustomScriptFunction() of the rtde_control interface. Unfortunately you have to send the preamble with the gripper api functions everytime, which does give a bit of delay. You can download the preamble for use with Python here:, and a python interface for using the robotiq gripper this way here:

Example of this method:

from robotiq_gripper_control import RobotiqGripper
from rtde_control import RTDEControlInterface
import time

rtde_c = RTDEControlInterface("<ROBOT_IP>")
gripper = RobotiqGripper(rtde_c)

# Activate the gripper and initialize force and speed
gripper.activate()  # returns to previous position after activation
gripper.set_force(50)  # from 0 to 100 %
gripper.set_speed(100)  # from 0 to 100 %

# Perform some gripper actions
gripper.move(10)  # mm

# Stop the rtde control script


  • Does not require any UR Cap to be installed.


  • Slow execution, since the preamble is transmitted each time.

  • Simultaneous robot movements is not possible (since the rtde_control script is interrupted)

  • Option 2: (Using the RS485 UR Cap)

Download the RS485 UR cap from here rs485-1.0.urcap, install it on the robot and remember to remove the Robotiq_Grippers UR Cap as these two cannot function together. It does not work with the Robotiq_Grippers UR Cap since this cap occupies the RS485 port all the time.

You can then use the tool_communication script for making the robotiq serial port available on your desktop. (eg. /tmp/ttyUR). Finally use a modbus RTU based driver to communicate through the serial port. Alternatively you can avoid running the tool_communication script and just communicate directly to the socket at the port specified in the RS485 cap (default is 54321).


  • Allows you to communicate to the RS485 port on the robot.

  • This approach can be used with different grippers, that uses the UR RS485 connection.

  • Fast communication.


  • Does not work together with the official Robotiq_Grippers UR Cap.

  • Requires you to install a UR Cap.

  • Option 3: (Communicating directly with Robotiq_grippers UR Cap port)

A robotiq gripper can be controlled through a port (63352) that is opened by the Robotiq_grippers UR Cap. This port provides direct communication to the gripper. So you simply connect to the robot IP at this port and you can command it using the Robotiq string commands, see the ‘Control’ section of this manual.


ur_rtde includes a C++ interface for robotiq grippers implemented by (Uwe Kindler). See the API here: Robotiq Gripper API, and the example here: Robotiq Gripper Example


You can download an example Python class for controlling the gripper using this method here: This class was implemented by Sam (Rasp) thanks! The class can be used like this:

import robotiq_gripper
import time

ip = ""

def log_info(gripper):
    print(f"Pos: {str(gripper.get_current_position()): >3}  "
          f"Open: {gripper.is_open(): <2}  "
          f"Closed: {gripper.is_closed(): <2}  ")

print("Creating gripper...")
gripper = robotiq_gripper.RobotiqGripper()
print("Connecting to gripper...")
gripper.connect(ip, 63352)
print("Activating gripper...")

print("Testing gripper...")
gripper.move_and_wait_for_pos(255, 255, 255)
gripper.move_and_wait_for_pos(0, 255, 255)


  • Works with Robotiq_grippers UR Cap.

  • Fast communication.


  • You might not be able to leverage existing robotiq drivers, depending on implementation.

My current recommendation is to use Option 3 for controlling a Robotiq gripper, and if that does not suit your needs go with Option 2. Option 1 should only be used as a last resort.