Universal Robots Forum

Start a script via socket

Hello folks,
currently im working on the integration of an optoforce hex-e force-torque sensor.
I want to use optoforce functions brought with their URCap file.
For example of_move(…), of_search(…), etc…
I tried to call such functions via socket connection but as its not a native URscript command the interpreter can not handle the call. These functions are defined in the preamble of the local script.

One solution to get this working would be to start a program remotely. Is there a possibility to get this working? Any other/ better solution?

Thanks in advance!

Best,
Ralf

Calling a function like of_move() will only work, if the function is defined within the same context.
That means, that the function should be defined within the same program sequence sent.
This applies to all non-native script functions - i.e. any function not described in the URScript manual.

Hence, sending just one line over a client interface, will not be working, as the URControl process will have no memory of this function, if it is not sent in the same scope.

Hence, you can either start the program remotely using the Dashboard Server or send a complete script code with the function definition.
E.g.

def myRemoteProgram():
   def lightUp(n, t):
      set_digital_out(n, True)
      sleep(t)
      set_digital_out(n, False)
   end
   lightUp(0, 2)
end

Or simply use the functional code wo. a function definition:

def myRemoteProgram():
   set_digital_out(0, True)
   sleep(2)
   set_digital_out(0, False)
end

Hi @jbm,
we are trying to send a complete script code with function definition and control RG2 gripper. we tried it on 30002 and 30003 and couldn’t get it to work. How do we know that the sent script is received and running on the robot or robot failed to understand the sent script due to an error in the script.
Please find the code to control RG2 gripper below
def RG():
def bit(input):
msb=65536
local i=0
local output=0
while i<17:
set_digital_out(8,True)
if input>=msb:
input=input-msb
set_digital_out(9,False)
else:
set_digital_out(9,True)
end
if get_digital_in(8):
out=1
end
sync()
set_digital_out(8,False)
sync()
input=input2
output=output
2
i=i+1
end
return output
end
def RG2(target_width=110, target_force=40):
bit(0)
sleep(0.024)
rg_data=floor(target_width)*4
rg_data=rg_data+floor(target_force/2)4111
rg_data=rg_data+32768
bit(rg_data)
while get_digital_in(9) == True:
sync()
end
while get_digital_in(9) == False:
sync()
end
end
RG2(50, 40)
end

1 Like

Do you have indentations for every line in between the first “def RG():” and the last “end”?

Since it uses time. It should be send to the primary socket.

Hi @Ebbe,
I am very new to this function creation and sharing,but when opened with notepad++ it has indentation for every def() and end ,

Thank you @Ebbe,
I will try to send the code on 30001 port and check if it works.