Git Product home page Git Product logo

rtde_python_client_library's Introduction

RTDE client library - Python

Library implements API for Universal Robots RTDE realtime interface.

Full RTDE description is available on Universal Robots support site

Project structure

rtde

RTDE core library

  • rtde.py: RTDE connection management object

  • rtde_config.py: XML configuration files parser

  • csv_writer.py, csv_reader.py: read and write rtde data objects to text csv files

examples

  • record.py - example of recording realtime data from selected channels.
  • example_control_loop.py - example for controlling robot motion. Program moves robot between 2 setpoints. Copy rtde_control_loop.urp to the robot. Start python script before starting program.
  • example_plotting.py - example for using csv_reader, and plotting selected data.

Running examples

It's recommended to run examples in virtual environment. Some require additional libraries.

python record.py -h
python record.py --host 192.168.0.1 --frequency 10

Using robot simulator in Docker

RTDE can connect from host system to controller running in Docker when RTDE port 30004 is forwarded.

  1. Get latest ursim docker image: docker pull universalrobots/ursim_e-series
  2. Run docker container: docker run --rm -dit -p 30004:30004 -p 5900:5900 -p 6080:6080 universalrobots/ursim_e-series
  3. open vnc client in browser, and confirm safet: http://localhost:6080/vnc.html?host=docker_ip&port=6080

More information about ursim docker image is available on Dockerhub

Using robot simulator in VirtualBox

RTDE can connect from host system to controller running in VirtualBox when RTDE port 30004 is forwarded.

  1. Download simulator from Universal Robots support site
  2. Run simulator in VirtualBox
  3. Open menu Devices->Network Settings
  4. Open Advanced settings for NAT
  5. Open Port Forwarding
  6. Add new rule, setting host, and guest ports to 30004. Leave host, and guest IP fields blank.

Using rtde library

Copy rtde folder python project Library is compatible with Python 2.7+, and Python 3.6+

Build release package

mvn package

Using with virtual environment

Create virtual environment, and install wheel package

Linux & MacOS

python -m venv venv
source venv/bin/activate
pip install wheel

Install rtde package

pip install target/rtde-<version>-release.zip

Windows PowerShell

If Python3 is not installed, then just run python3 from powershell. Microsoft store will launch the installation.

Permission to run scripts in console is needed to activate virtual envrionment.

set-executionpolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
python -m venv venv
venv/Scripts/Activate.ps1
pip install wheel

Install rtde package

pip install target/rtde-<version>-release.zip

Contributor guidelines

Code is formatted with black. Run code formatter before submitting pull request.

rtde_python_client_library's People

Contributors

hashb avatar michal-milkowski avatar myinternetofthings avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rtde_python_client_library's Issues

record.py --binary error

Hello,

When I run the record.py example with the --binary argument there is an error.

  • run code :
    python .\record.py --binary

  • error :
    Traceback (most recent call last): File "...\rtde\examples\record.py", line 78, in <module> writer.writeheader() File "...\.venv\lib\site-packages\rtde\csv_binary_writer.py", line 75, in writeheader self.__file.write(struct.pack(str(len(headerStr)) + 's', headerStr)) struct.error: argument for 's' must be a bytes object

Infinite "Unknown package command: x" error

Hi team,

I am using latest RTDE version and running a program which moves the robot head to 165 different positions in a cylindrical pattern with a time delay of 10 seconds after moving to each position. I am using a thread that sends the watchdog for every second to make the connection active. The program is randomly going to infinite loop with the below error.

What could be the possible cause for the infinite loop ?Are we loosing the connection to the controller ? In that case can it be restored automatically ?

“Unknown package command: 0”

File "C:path\RTDE_Python_Client_Library-main\examples\interopTest_CircleTest.py", line 251, in
move_to_exHandle(con, setp, topCenter)
File "C:path\RTDE_Python_Client_Library-main\examples\interopTest_CircleTest.py", line 72, in move_to_exHandle
move_to(con, setp, new_setp)
File "C:path\RTDE_Python_Client_Library-main\examples\interopTest_CircleTest.py", line 85, in move_to
Cur_state = con.receive()
File "C:path\RTDE_Python_Client_Library-main\rtde\rtde.py", line 218, in receive
return self.__recv(Command.RTDE_DATA_PACKAGE, binary)
File "C:path\RTDE_Python_Client_Library-main\rtde\rtde.py", line 320, in __recv
data = self._on_packet(packet_header.command, packet)
File "C:path\RTDE_Python_Client_Library-main\rtde\rtde.py", line 273, in on_packet
log.error("Unknown package command: " + str(cmd))
File "C:\userPath\AppData\Local\Programs\Python\Python310\lib\logging_init
.py", line 1506, in error
self.log(ERROR, msg, args, **kwargs)
File "C:\userPath\AppData\Local\Programs\Python\Python310\lib\logging_init
.py", line 1624, in log
self.handle(record)
File "C:\userPath\AppData\Local\Programs\Python\Python310\lib\logging_init
.py", line 1634, in handle
self.callHandlers(record)
File "C:\userPath\AppData\Local\Programs\Python\Python310\lib\logging_init
.py", line 1704, in callHandlers
lastResort.handle(record)
File "C:\userPath\AppData\Local\Programs\Python\Python310\lib\logging_init
.py", line 966, in handle
self.acquire()
File "C:\userPath\AppData\Local\Programs\Python\Python310\lib\logging_init
.py", line 917, in acquire
self.lock.acquire()

Times out after 10s

Seems like RTDE expects you to poll it continuously after you connect if you want fresh data. It'd be good if that was clearly called out in the docs.

If I do this:

rtde.connect()
time.sleep(11)
rtde.receive()

I get errors like received 0 bytes from Controller, probable cause: Controller has stopped or received 0 bytes from Controller. Also, I'll often get two stale messages before it notices the disconnect.

is_connected method is not working

Hi

is_connected() returns a wrong state if no other methods are called on the rtde connection.
In below example, it is retuning true. but it is actually disconnected. It is not cross checking with the controller and returning the object state.

I would like to handle issue 6 with a getConnection method which returns existing connection and if it is not available, it will create a new connection.

rtde.connect()
time.sleep(11)
Print(str(rtde.is_connected()))

When I finish executing sendCustomScriptFile, my subsequent programs cannot proceed.

Hi team,
The following is my python code:
import rtde_control
import rtde_receive
import time
rtde_c = rtde_control.RTDEControlInterface("number")
rtde_r = rtde_receive.RTDEReceiveInterface("number")
print("a")
result = rtde_c.sendCustomScriptFile("my.script")
'''
The code for my.script is
movej(get_inverse_kin(Waypoint_1_p, qnear=Waypoint_1_q), a=1.3962634015954636, v=1.0471975511965976)
movej(get_inverse_kin(Waypoint_2_p, qnear=Waypoint_2_q), a=1.3962634015954636, v=1.0471975511965976)
'''
print("b")
if result:
print("true")
print("c")

My arms do move to where I want, but the output only print "a"(it stuck at result = rtde_c.sendCustomScriptFile("my.script") this line).

I use another function which is sendCustomScript as follows:
import rtde_control
import rtde_receive
import time
rtde_c = rtde_control.RTDEControlInterface("number")
rtde_r = rtde_receive.RTDEReceiveInterface("number")
print("a")
inline_script ="""
def script_test():\n
global Waypoint_1_p=p[.563680615211, -.477776281521, .931261513423, -.216869564618, .618509619849, -2.027430390457]\n
global Waypoint_1_q=[-0.420081917439596, -1.3105357152274628, -1.815070629119873, -0.5506666463664551, 1.5176153182983398, 0.14520569145679474]\n
global Waypoint_2_p=p[.709160793559, -.224598873441, .900052191176, -.342416429180, .556536765580, -1.643688525955]\n
global Waypoint_2_q=[-0.02563649812807256, -1.3105324667743226, -1.8508906364440918, -0.55081661165271, 1.5176604986190796, 0.14514535665512085]\n
movej(get_inverse_kin(Waypoint_1_p, qnear=Waypoint_1_q), a=1.3962634015954636, v=1.0471975511965976)\n
movej(get_inverse_kin(Waypoint_2_p, qnear=Waypoint_2_q), a=1.3962634015954636, v=1.0471975511965976)\n
end\n
run program\n"""
result = rtde_c.sendCustomScript(inline_script)
print("b")
if result:
print("true")
print("c")

And I get the same as above.
My arms do move to where I want, but the output only print "a"(it stuck at result = rtde_c.sendCustomScriptFile("my.script") this line).

ValueError: An input parameter is already in use.

Hello,
I try to run the example_control_loop.py, but it always says the variables are in use. (IN_USE).
Have not been able to run it ever. Are there some undocumented requirements?

The record.py example works ! But that does not use any input_variables (input to the UR) so that not failing on 'in use'.

I run it on Windows, with the URSIM UR5 in a Virtual Box.
Clean install, reboot virtual machine, does not seem to help.

netstat shows this: so there are connections to port 30004 but that's directly after restarting so that's normal, i guess.
image

error:
image

Any help would be greatly appreciated.
Best Regards,

Problem running example_control_loop.py

I've attached a photo of the error. It occurs from the rtde_config.ConfigFile(config_filename) on line 43 of the program.

image

Any suggestions of points in the right direction are appreciated

Apple Silicon support?

Hi, maybe this already works if building it using maven, but I was hoping to use the PyPi package but it seems it does not support Apple Silicon?

Do you have any plans to support this? And/Or do you have a suggested workaround?

socket.timeout: timed out

What could cause a socket timeout and how to prevent it?
I am also not sure what information could be useful to debug it, if necessary ask for more details.
It happened after about 10-12 hours of execution.
I already tried to change the default timeout but to no avail.

Traceback (most recent call last):
  File "controller.py", line 288, in <module>
    main()
  File "controller.py", line 263, in main
    state = con.receive()  # <- 100 Hz requests
  File "rtde/rtde.py", line 218, in receive
    return self.__recv(Command.RTDE_DATA_PACKAGE, binary)
  File "rtde/rtde.py", line 306, in __recv
    self.__recv_to_buffer(DEFAULT_TIMEOUT)
  File "rtde/rtde.py", line 341, in __recv_to_buffer
    more = self.__sock.recv(4096)
socket.timeout: timed out

Control Robotiq Gripper

Hi, thanks for your great job.

My gripper is linked to the UR arm via a short line, so how can I control the gripper at the same time by using this tool?

Thanks for your attention and keep waiting for your kind response!

When I use the ur_rtde Python package, it prompts “RuntimeError: One of the RTDE input registers are already in use!”

When I use the “ur_rtde” Python package, it prompts “RuntimeError: One of the RTDE input registers are already in use! Currently you must disable the EtherNet/IP adapter, PROFINET, or any MODBUS unit configured on the robot. This might change in the future.”
The error occurs when executing:

import rtde_control
rtde_c = rtde_control.RTDEControlInterface(“192.168.1.8”)

I have already disabled the EtherNet/IP, PROFINET, and MODBUS services in the UR controller, but the issue still persists.
Could you please advise on how to resolve this? This problem needs to be addressed urgently due to project requirements. Thank you!

.urp program couldn´t be loaded

Hi there,

for some reason I cannot load example urp file on the teach pendant. Could you please share screenshots how does it look like?

Thanks a lot!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.