Hi,
I am doing a university project on a UR10 robot and I want to collect different data during a screwing process. I am interested in how to gather task data of the robot in real time by using python. I have achieved socket connection, but I have problems with collecting the data. RTDE is a bit complicated for me since im new, but I also do not know if it would even work with the CB2. Is there a more straight forward way to collect data over TCP connection and will I have any limitations?
Thanks for any input 
RTDE really is the more superior and robust client interface. While the Python client library’s codebase can be somewhat complex the examples are fairly straightforward and easy to adapt to your needs.
All you really need to do is…
- Ensure your cobot is on and connected to a network.
- Identify the cobot’s IPv4
- Clone the RTDE repository
- Using a console within the examples directory run
python record.py --host=YOUR_COBOT_IPv4
After that, all the variables declared in file ..examples\record_configuration.xml
will be written to file ..examples\robot_data.csv
.
Alternatively, the primary client interface is a little less intimidating to digest but not as robust or flexible. I’m writing an experimental primary client library that could help you get your feet wet. It was only tested with e-series models but I think it should work with cb series if your PolyScope version is recent.
1 Like
Just to give an update if anyone will be looking. My UR10 is connected to a PLC trough which I have connected my laptop. I have an older version of the Polyscope, 1.8 I think, so the only protocol that is working for me is to use TCP connection over modbus. I can get values as a 16-bit integers which is not great, but best that I figured out currently.
This is the python code for reading the registries that can be found here:
https://www.universal-robots.com/articles/ur/interface-communication/modbus-server/
This is the python code for getting the registry for TCP_position in X:
from pyModbusTCP.client import ModbusClient
from pyModbusTCP import utils
TCP_x = 400
function for unsigned integers
def unsigned(a):
if a > 32767:
a = a - 65535
else:
a = a
return a
connecting to Modbus
try:
c = ModbusClient(host=‘172.20.1.50’, port=502, auto_open=True, debug=False)
print(“connected”,c.open())
except ValueError:
print(“Error with host or port params”)
reading the register
while True:
# Read the value of the specified register from the UR10
register_value = c.read_holding_registers(TCP_x)
reg_var = unsigned(register_value[0])
print(reg_var)
Also a thing worth noting, modbus I guess can not show negative values, so when the register is negative it turns in to a unsigned integer. Thats why this function unsigned() is for.
2 Likes
Thank you @ovuiev21 for sharing the example code.
I am also using a CB2 Robot and your code was super helpful to get Modbus running via Python.
I have also added a function to write to the register.
Here is my minimal code if anyone is interested:
from pyModbusTCP.client import ModbusClient
import time
TCP_x = 400
TCP_y = 401
TCP_z = 402
def unsigned(a):
if a > 32767:
a = a - 65535
else:
a = a
return a
try:
#connect via modbus
robot = ModbusClient(host="192.168.178.45", port=502, auto_open=True, debug=False)
print("connected",c.open())
except:
print("Error with host or port params")
i = 0
while True:
# Read the value of the specified register from the UR10
register_value = robot.read_holding_registers(TCP_x)
reg_var = unsigned(register_value[0])
print("TCP-X:",reg_var)
register_value = robot.read_holding_registers(TCP_y)
reg_var = unsigned(register_value[0])
print("TCP-Y:",reg_var)
register_value = robot.read_holding_registers(TCP_z)
reg_var = unsigned(register_value[0])
print("TCP-Z:",reg_var)
if robot.write_single_register(128, i):
print("write ok", i)
else:
print("write error")
time.sleep(1)
i+=1
print("--------"*2)
1 Like