“”"
This script just represent the functions of the Remote tool for UR Robots E-Series
“”"
import time
Importing the robot_control.py (need to be in same folder as the main script)
import robot_control as rc
import rtde as rt
Robot IP must be String to parse it to the Socket connections
robot_ip = ‘192.168.1.128’
There about 3 connection ways to the UR.
You can use the RTDE to request data from Robot. So you will be able to get feedback from robot with 125hz
Refresh rates up to 500Hz are also possible, but require Gigabit network and Unix Based Computer like Linux or MacOS
info = rc.RTDE(robot_ip) # init Info Level connection to Robot
This represend the instant control level. The commands send to the robot will be executed directly.
It is ignoring if robot is still working on something.
control = rc.URControl(robot_ip, True) # init instand Control level
This part can be used if you want to have a full script that does not require live control.
Scripts must be finished and send to the robot. The robot can handle up to 500 lines.
After 500 Lines reached, you need to clear the intrpreter buffer and start counting from 1.
#icontrol = rc.URControl(robot_ip, False) # init intepreter Control level
#Definerar koordinater i systemet, där x och y beskrivs i meter. Maxlängd på 0.8 m
move_s = 0.1
def start_pos():
control.send_home() # this will tell the robot to move to his home position in joints not as target.
while not info.target_reached(rc.home_joints, level=5, joints=True):
pass
def digital_out_test():
“”"
This Scrip should show how to control Digital Outs.
Important note!
To interact with Tool Output just use digital out 8 for tool out 0 and digital out 9 for tool out 1
But to ask the state of the Tool output you will have different id's (TDO0=16, TDO1=17).
This is commented in Robot control
"""
while 1: # Infinite Loop
# Check if the tool digital output 0 is on
if info.get_digital_output_on(16):
control.set_digital_out(8, False) # Turn the TDO0 off
else:
control.set_digital_out(8, True) # Turn the TDO0 on
# sleep is not needed but it is better to visualize
def move_robot(c):
pose = info.get_TCP_pose()
rs.reconnect_robot()
if name == ‘main’:
control.send_home() #sätter robot i start position
while not info.target_reached(rc.home_joints, level=5, joints=True):
pass
while True:
print("start of loop")
actual_pose = info.get_TCP_pose()
print("define X in dm")
x = int(input())
print("define y in dm")
y = int(input())
actual_pose[0] += (move_s * x)
actual_pose[1] += (move_s * y)
control.send_movel(actual_pose)
while not info.target_reached(rc.home_joints, level=3, joints=True):
pass
digital_out_test()
print("done with function")
I have used this script for a while and have noticed that after one mainloop the robot no longer gains any bytes and gets an exception error that stops the full program. Has anybody had the same problem, I have tried putting in refresh commands but it is not working. The robot is fully connected so it’s not a connection error.
This is the log output
INFO:rtde:RTDE synchronization started
Connecting instand_mode
start of loop
define X in dm
2
define y in dm
2
ERROR:rtde:received 0 bytes from Controller, probable cause: Controller has stopped
INFO:rtde:RTDE disconnected
Traceback (most recent call last):
File “C:\URsim\Python\UR_Robot_Control-1.0.0\UR_Robot_Control-1.0.0\sample.py”, line 80, in
while not info.target_reached(rc.home_joints, level=3, joints=True):
File “C:\URsim\Python\UR_Robot_Control-1.0.0\UR_Robot_Control-1.0.0\robot_control.py”, line 414, in target_reached
actual_pose = self.get_joints()
File “C:\URsim\Python\UR_Robot_Control-1.0.0\UR_Robot_Control-1.0.0\robot_control.py”, line 342, in get_joints
state = self.rob.receive()
File “C:\URsim\Python\UR_Robot_Control-1.0.0\UR_Robot_Control-1.0.0\rtde\rtde.py”, line 184, in receive
return self.__recv(Command.RTDE_DATA_PACKAGE, binary)
File “C:\URsim\Python\UR_Robot_Control-1.0.0\UR_Robot_Control-1.0.0\rtde\rtde.py”, line 269, in __recv
self.__recv_to_buffer(DEFAULT_TIMEOUT)
File “C:\URsim\Python\UR_Robot_Control-1.0.0\UR_Robot_Control-1.0.0\rtde\rtde.py”, line 309, in __recv_to_buffer
raise RTDEException(‘received 0 bytes from Controller’)
rtde.rtde.RTDEException: ‘received 0 bytes from Controller’