[Solved] Calling "add-on" functions on UR-10 using Python

Hi! We’re currently using Python over ethernet to send commands to the UR-10. We’re also using a hex torque sensor and it’s add-on commands to provide extra functionality to the UR-10. Specifically we’re trying to use the “pin_insertion” command to guide a pin into a very tight hole. Now we can perform the pin insertion just fine if we create and perform the commands using UrScript on the UR-10 itself. But since our entire logic is in Python we want to perform the commands from there.

The commands we want to perform are as follows:

//Zero the sensor
of_tcp_offset_send_actual()
of_ft_bias()
//Perform the insertion
global of_return = of_pin_insertion( minDistZ = 0.03 , forceZ = 5.0 , compliance = [True, True, True, True, True, True] , maxDistZ = 0.05 , expSpeed = 0.0 , deltaForce = 0.0 , timeOut = 0.0 , FTLimits = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0] , PGainF = 1.0 , PGainT = 0.2 , silent = False )

We tried to excecute the commands as follows using Python but this doesnt work…:

send_command("of_tcp_offset_send_actual()")
send_command("of_ft_bias()")
send_command("global of_return = of_pin_insertion( minDistZ = 0.03 , forceZ = 5.0 , compliance = [True, True, True, True, True, True] , maxDistZ = 0.05 , expSpeed = 0.0 , deltaForce = 0.0 , timeOut = 0.0 , FTLimits = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0] , PGainF = 1.0 , PGainT = 0.2 , silent = False )")

The send command function is as follows:

def send_command(string):
global s
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(10)
s.connect((HOST, PORT_30003))
s.send(string + "\n")
time.sleep(0.01)
s.close

Any help would be nice!

We fixed it by sending each line individually from a script file which we pulled from the UR.

SOLUTION

If you want to send multiple lines of URscript code to the universal robot over Socket, you can open a .script file downloaded from the UR and send it over Socket. The UR will then execute the program.

In this case we use python and a UR10.

How to get the script

  1. Write the code on the UR in function blocks found under structure
  2. Save the program on the UR
  3. Make connection from your computer to the robot using FTP
  4. Download your <program>.script from the UR
  5. Save the script file in your project folder (i.e. a resource folder called “res”)

How to use it

f = open("../res/insertion.script") # open the script downloaded from the UR

# The variable 's' is the socket connection with the UR.
# If you don't know how the use sockets click on the link at the bottom of the post.
# Next step is reading the data and sending it as shown below.

s.send(f.read()) 

You only need these two lines of code to make it happen.

If you want to know when the code is finished you could always put a digital_output to 1 and read it out from the default packets the UR returns. More info about return values can also be found in the link below.

http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/script-from-host-to-robot-via-socket-connection/