File Exchange

image thumbnail

UR5 Control Using Matlab

version (64.8 KB) by Fereshteh Aalamifar
Read current robot tooltip, move to desired pose and orientation


Updated 26 May 2015

View License

Read current robot tooltip position and orientation, move to desired position and orientation.
You can also activate or deactivate cooperative control mode in CB2 controller; or read robot pose while you are moving it in cooperative or automatic mode.
You can also control UR5 using 3d mouse.
Requires running a program on Polyscope software (in the package). Tested on several UR5 (CB2) and Polyscope versions.

Comments and Ratings (20)

Hi Perig and Ole, sorry I don't have any experience with UR10.

Heng Gu

Hey Fereshteh,could you please tell me where the Polyscope folder you mentioned in the note of 'robotcontrol_demo.m' is? Thamks in anvance!

Hi Perig. Did you figure it out? I'm having the same problem.

Hi, I am tying to adapt this to control a UR10 robot with Matlab 2018b. Software version 3.7.

I did not change the IP address in Matlab code, kept it '' to accept all IP addresses. I changed the port to 30004 which is the port for RTDE on this version of the software. I changed the IP address on the socket_open to match my PC IP address and changed the port to be 30004.

When I run with matlab as the server, it just hangs and nothing happens even after I run the program on the robot. The socket_open on the robot seems to time out and move on to the socket_read_ascii() function and wait there.

If I run matlab as the client by changing the IP address to the robot address, I can open the socket but when i send the data (2) to read, I am not seeing any response on the robot and i don't see the variable 'task' being assigned anything. It shows [0.00000, NaN].

Any idea?

Hi Feder. By 'press play on robot...' I meant run the polyscope program.

feder Lu

feder Lu

Hey Fereshteh, can you tell me what mean 'press play on robot . . .' in the matlab code.thank you very much! and i don‘t know is it connect ?

DB Cooper

Hi Fereshteh,

I got the 3D mouse control up and running. However, when I compare translation and orientation on the UR robots touchpad, they are not in alignment with the translation and orientation as retrieved by the provided MATLAB scripts. Did you experience this as well, and how can I resolve this issue?

DB Cooper


I am trying to establish a connection through Matlab / Ethernet and I cannot get the socket connection to work. I connected the UR5 by ethernet to my macbook which is running Windows 10 as well. Changing the IP address to the Ethernet address for both my original macbook address, as well as the virtual machine's address doesn't work. I followed aforementioned instructions but can't get it to work. Hope somebody can provide me with the proper IP addresses in Matlab, the Polyscope program and set-up. Im going crazy...
Thanks in advance.
Chiron Morsink

Andrej Dik

Hi Ben and Luis,
I got it running with the following changes:
In the VMs network settings I chose "Bridged Mode".
In PolyScope I have loaded the program "matlabcontrol3dmouse.urp" and changed the IP address in the command "socket_open("192....)" to my PCs IP address. Furthermore, in the command "speedl(Move_to_Pos..." I changed "t_min" to "t", because I get an error for "t_min".
In Matlab I opened the function "main_3dMouse.m" and changed the IP address in the command "Robot_IP = '';" to the VMs IP address.
Hope that helps.

I am trying to use the 3D Mouse controling code however the socket connection is not established. I connected the UR5 by ethernet to the PC and the 3D mouse thought USB to the PC. I did not changed the Matlab code and when I hit run the socket connection fails. What do I need to do ?

Thanks in advance
Luis Castro

Ben Gross

Hi Fereshteh, I have been attemtping to set up your UR5 controller program, and in your demo code you mention in the notes to "set the PC ip in the polyscope" I was wondering how to do that

thanks Ben Gross

Hi Daniel, yes; you should use a different socket port to send commands directly. I think this article is what you are looking for:

Daniel Honc

Fereshteh, many thanks. It works perfectly. Did you try to control robot directly with URScript commands without Polyscope? Daniel

Daniel, just insert your USB drive into the USB port of the UR5 control panel (teach pendant or UR5 controller or Polyscope). Then, you can load the program from USB drive and "save as" on control panel's local drive.

Daniel Honc

Hello Fereshteh, I am sorry. I do not know how to "Copy the Polyscope folder to UR5 Controller using a USB drive". What else should I do in Polyscope? I suppose at least add script to a robot program. Many thanks. Daniel

Fereshteh, I found what was the problem with my setup. The NAT8 network adapter was not the one I should have used. As soon as I used the bridged network mode (independent ip from the computer) it worked flawlessly!

Philippe, there already is a txt file in the package that gives you instructions on how to set this up on URsim: Polyscope Simulation Guide.txt

I know it's been a while since you released this program, but could there be a way to publish a little tutorial on how to set this up on URsim?

It would be GREATLY appreciated. Thanks!

feng fcc

thanks!that is my requirement


Cooperative control in all directions

Added cooperative mode activation and real time robot pose reading

Added 3d mouse control

Decreased the delay in moverobot.

Fixed a bug in the example.

Added comments.

MATLAB Release Compatibility
Created with R2013b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: 3D mouse support

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.

Learn About Live Editor