How to send entire .script file to the robot?

Hi,
I have .urp file containing thousands of line of code which uses Robotiq Wrist Camera. I have checked the CPU usage of the robot while running the program via SSH with Top command. It is heavy.
What I want is: to run the program on the Raspberry Pi with Python as the goal is to outsource the CPU.
My question: How can I make the robot read the entire .script file? or Do i need to re-write the entire program in Python for what I want? @ajp

I know/read forum posts regarding how to send script commands via interpreter but still no luck!
Can you please share an example of code?
What I’ve tried so far:

  • Sending file on Interpreter mode. it accepts movej commands just fine but doesn’t IF or other commands.

  • Simple socket connection. (The robot is in Remote Control Mode)

#!/usr/bin/env python3
import socket

HOST = IP
PORT = 30002

def toBytes(str):
    return bytes(str.encode())

def main():
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((HOST, PORT))

    s.send(toBytes(
        "def Program():"+"\n"
        +"set_digital_out(1,True)" + "\n"
        +"aValue = 25"+ "\n"
        +"jSpeed = 3.0" + "\n"
        +"rValue = 0.000" + "\n"
        +"set_tcp(Tool_TCP)" + "\n"
        +"movej([0.00000, -1.57080, 1.57080, -1.57080, -1.57080, 0.00000], a=aValue, v=jSpeed, r=rValue)" + "\n"
        +"movej([-0.34835, -1.42418, 1.32454, -1.47116, -1.57085, -0.34836], a=aValue, v=jSpeed, r=rValue)" + "\n"
        +"set_digital_out(1, False)" + "\n"
        +"movej([0.31159, -1.18146, 1.00756, -1.39689, -1.57085, 0.31159], a=aValue, v=jSpeed, r=rValue)" + "\n"
        +"set_digital_out(1, True)" + "\n"
        +"end" +"\n")
        )

if __name__ == '__main__':
    main()

To which I will get no response from the robot. But I do if the code is:


    s.send(toBytes(
        "def Program():"+"\n"
        +"set_digital_out(1,True)" + "\n"
        +"end" +"\n")
        )

Assuming If I want to use XML-RPC protocol with RTDE library, how can I possibly run the below script on my pc/raspberry pi as a server?

 Waypoint_1_p=p[.228772518346, .455763095675, .347674799191, -1.690026577345, 2.648214023566, .000057993216]
 Waypoint_1_q=[1.3719388246536255, -1.5943252048888148, -1.3234245777130127, 4.487106009120605, 1.5801326036453247, 1.802979588508606]
 Waypoint_2_p=p[.228763356229, .455759116383, .347626423151, 3.130802393172, -.259629003696, .000019551922]
 Waypoint_2_q=[1.371955394744873, -1.5943714580931605, -1.3234750032424927, 4.487092657680176, 1.5801327228546143, -0.037084404622213185]
 Waypoint_3_p=p[.228775644377, .455772784559, .347641315071, 2.354154522787, 2.080235020725, .000059210401]
 Waypoint_3_q=[1.371955394744873, -1.5943719349303187, -1.323449730873108, 4.487122221583984, 1.5801042318344116, -1.6499698797809046]
 u12454u12455u12452u12509u12452u12531u12488_1_p=p[.226570636842, .451509332811, .246357970128, 2.337809621102, 2.088385848370, -.017441429083]
 u12454u12455u12452u12509u12452u12531u12488_1_q=[1.373509407043457, -1.5698608740679738, -1.605188012123108, 4.7313729403312585, 1.581647276878357, -1.6570900122271937]
   var_1=0
     movej(get_inverse_kin(Waypoint_1_p, qnear=Waypoint_1_q), a=1.3962634015954636, v=1.0471975511965976)
     sleep(3.0)
      rg_grip (100, 40, 0,   True  ,   False  )
     movej(get_inverse_kin(Waypoint_2_p, qnear=Waypoint_2_q), a=1.3962634015954636, v=1.0471975511965976)
     sleep(2.0)
 on_return = rg_grip(9.000000000000002, 40.0, tool_index = 0, blocking = True, depth_comp = False, popupmsg = True)
 rg_payload_set(mass = 0.0, tool_index = 0, use_guard = False)
     movej(get_inverse_kin(Waypoint_3_p, qnear=Waypoint_3_q), a=1.3962634015954636, v=1.0471975511965976)
      rg_grip (50, 40, 0,   True  ,   False  )
     var_1=var_1+1
     if (var_1 >= 3):
       movej(get_inverse_kin(u12454u12455u12452u12509u12452u12531u12488_1_p, qnear=u12454u12455u12452u12509u12452u12531u12488_1_q), a=1.3962634015954636, v=1.0471975511965976)

Thanks a lot!

Beck

Hi Beck,

Is the reason for wanting to free up CPU that you’re seeing slow down on the teach pendant, or you’re worried it’s going to exceed the limits and cause issues?

You could send the script file from a raspberry pi… but once you’ve sent it and it’s running, the controller CPU usage would be the same as if you ran the script from within Polyscope.

You need to actually call your Program() function at the end of the script you’re sending, or else it will never actually execute. I’m not sure why the digital out one would work without that.

There isn’t a way to do what you’re trying to do with UR standard XMLRPC and RTDE functionality, but you could look into this 3rd party library which externally controls the robot via RTDE:

https://sdurobotics.gitlab.io/ur_rtde/introduction/introduction.html

Hope this is of some use,

1 Like

Thanks for the suggestion.

Reason why I need to free up is the initial program start time is 15 (fifteen seconds) and I observe Teach Pendant freezing occasionally. Also, over-usage of CPU being the reason, it affects the Robotiq Wrist Camera object detection quality.

I will check the link you shared.
Thanks a lot!

Beck