UR Script:

Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.

Also check out the CB3 forum

UR Script Programming.

So far we have used the touch screen teaching pendant on the Universal-Robot to make our robot programs which is very convenient and easy to build up programs.

But sometimes it can be desirable to be able to make the robot program on a host computer and just communicating and sending commands from the host computer or PC via an Ethernet socket connection directly to the robot motion and action control without using the teaching pendant. For example if the robot is part of a big complex installation where all equipment are controlled from the host computer or PC.

Another advantage by doing this is that the program can be further developed, edited and tidy up while the robot is running production. Then when there is a break in the production the new modified program can be activated and control the robot right away (provided the programmer did not make any programming errors in the new version).

The differences in using the teaching pendant and the remote scripting method is that when editing with the teaching pendant the program execution has to be stopped while editing and thereby interrupt the actual production whereas editing in the host application can be done aside from the running version and thereby not disturb the production.

Another advantage is that the host application programmer can make new functions and features by himself and basically create a complete new user interface and functionalities to the robot and handling of his data and interfacing with even other computer systems to his creativity abilities.

The Universal-Robot offers such possibilities to make remote script programming with its build in script interpreter. The choice of programming environment on the host computer is up to the programmer and typically programming languages such as C++, Java, Visual Basic, and Python or similar is the choice, but even Notepads can be used as an editor.

But before jumping into the remote script programming there is also an alternative script programming method provide by the teaching pendant as well which is also very useful. With this method it is possible to Import Script statements or whole Script files into the robot program created by the teaching pendant – so this method is something in between using only the teaching pendants program objects and the fully remote Script programming. This method will be explained first.

It is also important to mention the separate document and manual for Universal-Robot script programming called scriptmanual_enx.x where the commands with their parameters are explained.

Disclaimer: While the Zacobria Pte. Ltd. believes that information and guidance provided is correct, parties must rely upon their skill and judgement when making use of them. Zacobria Pte. Ltd. assumes no liability for loss or damage caused by error or omission, whether such an error or omission is the result of negligence or any other cause. Where reference is made to legislation it is not to be considered as legal advice. Any and all such liability is disclaimed.

If you need specific advice (for example, medical, legal, financial or risk management), please seek a professional who is licensed or knowledgeable in that area.

Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.

Also check out the CB3 forum



159 thoughts on “UR Script:

  1. Manuchehr

    Hello again!
    First of all, thanks for the material.

    Could you, please, help me with my problem?

    I’m using vision system PIM60 with my UR5. As a tool I use pneumatic gripper. My object to pick up is a chip. So, PIM60 detects an object and places to the given location.

    But the problem is that UR5 keeps going to the same place where object has already been found. Once the chip is relocated, I want the manipulator to wait until another chip’s placed to detect by PIM60. I’ve tried using “SICKobjLocated”(which is equals 1 if the object’s been located), but it doesn’t work.

    Thanks in advance.

    Reply
    1. zacopressadmin Post author

      Hi Manuchehr

      Thanks for the question.

      It might be the logic or timing in your program that needs to be worked on.

      Author:
      By Zacobria Lars Skovsgaard
      Accredited Universal Robots support Centre and Forum.

      Also check out the CB3 forum



      Reply
  2. Da Ho

    Hello,
    i think that does’t fit in this topic, but i didn’t find another one.
    I want to install the Guest Additions in VirtualBox in the URSim(1.8) Simulation of the UR10.
    When i try to install it, i allways have the Problem that i need the super user password.
    Is there a password that everyone can use?
    Hope you guys can help me, because the screen resolution(800×600) is to small and so the window of the UniversalRobot is like “jumping” up and down in the bottom part of the window and so i can’t use the controlelements.

    Reply
    1. zacopressadmin Post author

      Hello Da Ho

      Thanks for the question.

      Has the “Seamless mode” been tried ?

      Author:
      By Zacobria Lars Skovsgaard
      Accredited Universal Robots support Centre and Forum.

      Also check out the CB3 forum



      Reply
  3. Luis

    Hello!
    I am trying to control my UR10 using a 3D mouse. The scrip I am using is on https://www.mathworks.com/matlabcentral/fileexchange/50655-ur5-control-using-matlab, I connected the PC thought ethernet to the UR10 and the 3D mouse by USB to the PC, I also changed the robot IP in the Matlab code. When I run the program it doesn’t make the socket connection.
    Do you happen to know the error. Or do you know a easier solution for the problem ?

    Thanks in advance

    Reply
    1. zacopressadmin Post author

      Hello Luis

      Thanks for the question.

      I am not ware of the function for this script from mathworks – have you asked on their forum who created it ?

      Author:
      By Zacobria Lars Skovsgaard
      Accredited Universal Robots support Centre and Forum.

      Also check out the CB3 forum



      Reply
  4. Collin Roy

    I am using a thread in my program to verify if my vacuum is okay when I’m taking a plank of wood. I would like to know if I can pause my program from my thread using a popup message. I know that I can use the function pause() but I want to use a popup at the same time.

    Thanks a lot in advance, Collin

    Reply
    1. zacopressadmin Post author

      Hi Collin

      Thanks for the question.

      A Popup in a Thread does not stop the program.

      Maybe it can be considered to set a flag in the Thread when the event happen – and then use this flag in the main program to produce a Popup.

      Author:
      By Zacobria Lars Skovsgaard
      Accredited Universal Robots support Centre and Forum.

      Also check out the CB3 forum



      Reply
  5. Tobias

    I externally generated a list of movel() commands (about 60000 targets) as UR-scripts file for a raster-scan of a free-form surface.

    Is there a way to handle the coresponding script-file of about 7MB?
    The PolyScope interface was not able to load it within 3 hours.
    (Loading a 2MB file did last several minutes)

    Is there a genral limitation ragarding the script file size?

    As an alternative: would it be possible to achive an almost continious movement of the robot using the Ethernet socket and URscript commands?

    Best regards,
    Tobias

    Reply
    1. zacopressadmin Post author

      Hi Tobias

      How are you sending these commands ?

      To which port are you sending these commands ?

      Author:
      By Zacobria Lars Skovsgaard
      Accredited Universal Robots support Centre and Forum.

      Also check out the CB3 forum



      Reply
      1. Tobias

        Hi!

        It is an UR-script file (externally created, uploaded to the robot) which is loaded into a Polyscope program as “Script Code”.
        (“Small” files are working as expected. In particular the robot movement seems to be continuous)

        As an alternative:
        If I would use socket commands, I would only be able to move the robot like in start/stop regime? or additional effort regarding the timing of the commands would be required?

        Reply
        1. zacopressadmin Post author

          Hi Tobias

          I am not aware of the limit size for such script file.

          It is also possible to use the “speedl” command to make continius moves by changing direction by sending a new “speedl” command after a previous one.

          Author:
          By Zacobria Lars Skovsgaard
          Accredited Universal Robots support Centre and Forum.

          Also check out the CB3 forum



          Reply
  6. Paul

    Hi,

    I’m programming a UR5 in URScript. Is it possible to create a list of poses or inverse kinematic solutions and manipulate that list in a while loop? For example, I’m trying to run code similar to below

    #pose_10_w_inv et al are all inverse kinematic solutions for the poses I want the robot to move through
    pose_x0_w_inv_list = [pose_10_w_inv,pose_20_w_inv,pose_30_w_inv,pose_40_w_inv,pose_50_w_inv,pose_60_w_inv]
    pose_x1_w_inv_list = [pose_11_w_inv,pose_21_w_inv,pose_31_w_inv,pose_41_w_inv,pose_51_w_inv,pose_61_w_inv]

    MoveLinear(pose_x0_w_inv_list,pose_x1_w_inv_list)

    Then I try to call these lists in the following function

    def MoveLinear(pose_list_1, pose_list_2):
    i = 0
    while i < 6
    movel(pose_list_1[i],accel_mss,speed_ms,0,blend_radius_m)
    sleep(1)
    movel(pose_list_2[i],accel_mss,speed_ms,0,blend_radius_m)
    i = i + 1
    end
    end

    Is it possible to manipulate poses or inverse kinematic solutions like this?

    Reply
    1. zacopressadmin Post author

      Hi Paul

      Thanks for the question.

      Yes it is possible. Now an example has been created at this link below – scroll down to “Example 7″

      http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/functions-1/

      Author:
      By Zacobria Lars Skovsgaard
      Accredited Universal Robots support Centre and Forum.

      Also check out the CB3 forum



      Reply
  7. Sanketh Ramachandra

    Hello Lars,

    Had a question on error catching on the PolyscopeUI. I am writing a module wherein the Robot programmer passes the commands by hand, Example:
    DoSomeLogicAndMove(var1,MoveType,Position):
    … Performs internal logic
    … movej(Position,a=1.0,v=0.4)
    end
    s there anyway I could check if the user entered value for a pose is valid. If not, I could perform error handling.

    Reply
    1. zacopressadmin Post author

      Hello Sanketh

      Thanks for your question.

      It depends a little on how you program is made.

      Maybe not exactly catch all scenarios because there are many and there could be singularities that is difficult to predict and also a customized end effectors could be in the way for something the robot do not know about.

      But maybe in order to catch some situations it can be considered to check on the current position – and then look at the entered values – e.g. if the robot is at a certain X position – then make sure the entered data does not cause the robot to end up in a X position that is out of reach.

      Maybe also consider to only allow small changes so the robot cannot make to far moves for the current position because there could be a risk for singularity.

      Author:
      By Zacobria Lars Skovsgaard
      Accredited Universal Robots support Centre and Forum.

      Also check out the CB3 forum


      Reply
  8. Jan

    Hello,

    I’m a student and I’m trying to mill something with my UR3. I generated G-Code with “HSMXpress” for SolidWorks. I use “RoboDK” to handle the G-Code. The program which is generated by RoboDK causes an error on my teach pendant: “CIRCULAR_ARC_WITH_ZERO_RADIUS” and the robot stops.
    This error only appears at “moveC” commands, but I can’t find the mistake.
    This is an extract from my program:

    global speed_ms = 0.3
    global speed_rads = 0.75
    global accel_mss = 3
    global accel_radss = 1.2
    global blend_radius_m = 0.001

    movel([0.028830, -1.118635, 1.885941, -2.338102, 4.712389, 4.741219],accel_mss,speed_ms,0,blend_radius_m)
    speed_ms = 0.006
    movec([0.028774, -1.118438, 1.886086, -2.338444, 4.712389, 4.741163],[0.028719, -1.118249, 1.886246, -2.338793, 4.712389, 4.741108],accel_mss,speed_ms,blend_radius_m)
    movec([0.028566, -1.118156, 1.886443, -2.339084, 4.712389, 4.740955],[0.028413, -1.118064, 1.886645, -2.339377, 4.712389, 4.740802],accel_mss,speed_ms,blend_radius_m)

    The second moveC command causes the error and I don’t know why.

    Can anybody help me or has an idea who can help me?

    Thank you,

    Jan

    Reply
    1. zacopressadmin Post author

      Hi Jan

      Thanks for the question.

      I am not familiar with RoboDK and maybe you can also ask them the question.

      But I did try and type the data from your program into a program on my robot.

      First I wish to see where the actual position for each of the 4 waypoints in the circle really are.

      movec([0.028774, -1.118438, 1.886086, -2.338444, 4.712389, 4.741163],[0.028719, -1.118249, 1.886246, -2.338793, 4.712389, 4.741108],accel_mss,speed_ms,blend_radius_m)
      movec([0.028566, -1.118156, 1.886443, -2.339084, 4.712389, 4.740955],[0.028413, -1.118064, 1.886645, -2.339377, 4.712389, 4.740802],accel_mss,speed_ms,blend_radius_m)

      The two line “movec” is actually 4 waypoints which are – “First half Circle start” – “First half Circle Via point” – “Second half Circle start” – “Second half Circle Via point”.

      So I make that 4 waypoints to see where they are.

      movel([0.028774, -1.118438, 1.886086, -2.338444, 4.712389, 4.741163],accel_mss,speed_ms,blend_radius_m)
      movel([0.028719, -1.118249, 1.886246, -2.338793, 4.712389, 4.741108],accel_mss,speed_ms,blend_radius_m)
      movel([0.028566, -1.118156, 1.886443, -2.339084, 4.712389, 4.740955],accel_mss,speed_ms,blend_radius_m)
      movel([0.028413, -1.118064, 1.886645, -2.339377, 4.712389, 4.740802],accel_mss,speed_ms,blend_radius_m)

      And then I run the program – and then I can see that these 4 waypoints are almost the same position – then robot hardly move at all – which indicate that this is a too small circle that has virtual no radius – which is also what the error messages indicate – “CIRCULAR_ARC_WITH_ZERO_RADIUS”.

      Although there is a tiny small difference in the joint angle data in the 4 waypoints – it is too small difference for the robot and it is virtual the same position and therefore seems to be no real circle.

      Author:
      By Zacobria Lars Skovsgaard
      Accredited Universal Robots support Centre and Forum.

      Also check out the CB3 forum

      Reply
      1. Jan

        Hi,

        thank you very much!
        So the circle is too small for the robot. Is there any information what the minimum circle radius has to be? Then I can configure HSMXpress to avoid small circular movements.

        Best regards,

        Jan

        Reply
  9. Ruben Ufkes

    Hello,

    First of all, I am a mechanical engineering student and only have two months of experience with programming and controlling stuff like the UR5-robot so excuse me for my ignorance and lack of info I’m telling you.

    I managed to write a programm in C# that can read and write to multiple registers. I can read of the (current) x,y,z coordinates at starting address 400 which is great, but is it also possible to write x,y,z coordinates to registers?

    Thanks!

    Reply
    1. zacopressadmin Post author

      Hi Ruben

      Thanks for the question.

      I assume the registers you read for X, Y and Z is part of the MODBUS registers 400-405 at TCP port 502. These registers are for read only which can be seen on the register list at this link

      https://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/modbus-server-16377/

      To write values for X, Y, Z (and maybe a complet set then also Rx, Ry and Rz) this can be done in a move command – either locally in a Polyscope program or from a remote host by sending a move command as a script command. Some more example at these links.

      http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/position-variables-1/

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

      Author:
      By Zacobria Lars Skovsgaard
      Accredited Universal Robots support Centre and Forum.

      Also check out the CB3 forum

      Reply
  10. Anita Macher

    Hi Lars,

    I am programming a UR10 via scripting. The robot is a part in a bigger program. I want to set the safeguard of the robot, if something happens in the bigger program.
    How can I do this?

    Thanks for your help,
    Anita

    Reply
  11. Adam

    HI Lars,
    In my application we would like an operator to have some sort of way to “call” for help. We would like to avoid using a push button if possible so we can keep the amount of wires down. We were hoping for there to be a way for us to have a popup or something that is on the GUI run screen at all times and then if the operator needs help they can push the button and that will turn on an output to the PLC and the PLC will turn on a indicator light. We have other popups that we want to appear if certain things happen in the program as well, and we would like for those popups to come up in place of the help button popup. Any ideas on how we could do this or if this is even possible?

    Thanks.

    Reply
  12. Michael

    Good day I have a question about UR, but don’t know where to ask. We have UR5 and Keyence vision system camera and I want to write simple program, where Keyence detects an object and robot picks it. The problem is how to communicate and how to make that program on UR? I have set IP on robot and keyence and it seems that they communicate but i can’t send anything to UR.

    Reply
    1. zacopressadmin Post author

      Hi Michael

      Thanks for your question.

      Often a vision camera with ethernet communication and using a TCP socket works in a way where it can be polled for data i.e. triggered for data by sending a trigger command from the robot – that will cause the camera to snap an image and then send the coordinate data of the location for the part to be detected back to the robot over the TCP socket connection.

      Different camera brands and models have different protocol – so it is necessary to know this protocol (data format) so he robot and camera can communicate. You can properly get the protocol and data format from the camera vendor.

      It also requires that the camera has been setup to detect and recognize the shape and location of the parts to detect.

      At this link is an example for how a camera is triggered by sending a string from the robot “asking for data” – and the the camera returns the coordinate for the object location. Of cause the string “asking for data” show in this example – is just an example and this trigger is different from camera to camera – and there can also be more data send out from the camera.

      http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/script-client-server/

      Author:
      By Zacobria Lars Skovsgaard
      Accredited Universal Robots support Centre and Forum.

      Also check out the CB3 forum

      Reply
  13. Tjipke van der Heide

    Hey folks at zacobria,

    i have been using an ur5 for quite some time, but i ran into a problem with running through a trajectory.
    Right now the ur_driver i use is not used with ros, so it directly communicates with the ur5 robot. using “addCommandToQueue()”, i can send cartesian coordinates to the robot, and everything works fine.

    The problem is getting data back from the ur5. at http://www.sysaxes.com/manuels/scriptmanual_en_3.1.pdf i found the ur5 script manual, and one of the functions that i can give is called get_inverse_kin. if i have a c++ program running on an external pc, and i send this command to the ur5, how can my pc get back the data that this function returns? for example, http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/script-from-host-to-robot-via-socket-connection/ explains how to get back a result from executing a ” set_digital_out” command. here the return value is a series of bytes. Can the same be accomplished with get_inverse_kin?

    I hope someone will be able to help,

    Tjipke van der Heide

    Reply
    1. zacopressadmin Post author

      Hi Tjipke van der Heide

      Thanks for your question.

      1.
      The feedback from the robot you see on the link you refer to with the example that send the command “set_digital_out” to port 30002 – is actually not related to the command send over. The robot do set the digital output with the “set_digital_out” command which is the purpose in the example – however the return data that the robot send back is a default continuously stream of data for the status of the robot – actually it is not necessary to send any command to receive these data – the robot will still send this stream of status data out on port 30002 – which can be seen if you connect to port 30002 with the test program “sockettest” – then there is a flow of data. These data is called Matlab data and some more information can be found at this link below which has an excell sheet with the information that can be downloaded – maybe these data contains what you need.

      http://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/remote-control-via-tcpip-16496/

      2.
      To send raw script commands to port 30002 is a sort of “one way” commands which the article also mention – which means it is possible to “set” things like setting outputs – or “set” a position with a “move” command and the robot will move as described in the example. So the “one way” commands send to port 30002 cannot read something back (other than the Matlab data as describe above) – so reading of inputs or getting the result of a “get_inverse_kin” command will not return the result on port 30002 with this method.

      3.
      Instead the example in the link below shows how to get data back to the host (PC) by using a “Client-Server” situation.

      http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-client-server-example/

      In the example another command is used called “get_forward_kin” and a similar approach can be used for other data that needs to be send from the robot to the external host.
      The key is that in a Client-Server situation there is a Client program running on the robot made in Polyscope that prepare the data that needs to be send over – and then open a port to the host (PC) and transmit the data over the TCP socket to the host Server program.

      4.
      Depending on the data needed on the host – for example if it is the position data or data for the I/O state then another method can also be used by accessing the MODBUS server on port 502 on the robot.

      For example register 400-405 holds the data for the current position – and register 0 holds the data for the current state of the inputs and register 1 holds the data for the current state of the outputs – and since register 1 is outputs they can also be set via the MODBUS server.

      An example of using the MODBUS register is at this link.

      http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/modbus-registers-input-and-output-handling-via-port-502/

      A list of the contents of all the MODBUS registers on the UR is at this link

      http://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/modbus-server-16377/

      Author:
      By Zacobria Lars Skovsgaard
      Accredited Universal Robots support Centre and Forum.

      Also check out the CB3 forum

      Reply
      1. Tjipke van der Heide

        Thank you for the reply, what i was trying to do was trying to use the robot’s built in inverse kinematics solver to give back a series of joint positions, to then feed back to the robot. It seems that another way has to be found to achieve this.

        Thanks again,

        Tjipke van der Heide

        Reply
        1. zacopressadmin Post author

          Hi Tjipke van der Heide

          Yes maybe an idea is either to do the calculation in the program on the robot using the “get_inverse_kin” and send the data result to the host via a Client-Server solution – or maybe another idea is to create a calculation equation on the external host based on the Denavit–Hartenberg parameters that can be found at this link.

          http://www.universal-robots.com/how-tos-and-faqs/faq/ur-faq/actual-center-of-mass-for-robot-17264/

          Author:
          By Zacobria Lars Skovsgaard
          Accredited Universal Robots support Centre and Forum.

          Also check out the CB3 forum

          Reply
    2. Tom

      hello,
      I am trying to control ur5 running through a trajectory in windows. I want to use the script function:`servoj() `, but my data format is based on the tool space(a vector:X,Y,Z,RX,RY,RZ), so I need to translate the data to joint space. Followed my script code:
      “`
      def trajPlan():
      get_inverse_kin([0.55718 -0.04416 0.45048 -0.95300 1.49430 -0.60280]) = cmd_servo_q
      servoj([cmd_servo_q],t=2)
      end
      “`
      At [(http://www.sysaxes.com/manuels/scriptmanual_en_3.1.pdf)]
      i found the ur5 script manual,
      and one of the functions that i can give is called get_inverse_kin(). if i have a c++ program
      running on an external pc, and i send this command to the ur5 to get the joint position,
      then try to use the servoj to servo ur5 with the joint position. but the robot had no response.

      I hope someone will be able to @help,ThomasTimm
      Tom

      Reply
      1. zacopressadmin Post author

        Hello Tom

        Thanks for the question.

        When sending script command this way – it is only possible to set something on the robot – e.g. an output or a position. It is not possible to read back in this way.

        This script command get_inverse_kin() can be used inside the Polyscop enviorment.

        There are some more informations at this link.

        http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/universal-robots-script-programming/

        Author:
        By Zacobria Lars Skovsgaard
        Accredited Universal Robots support Centre and Forum.

        Also check out the CB3 forum



        Reply
  14. GANESH P

    Hi Lars,
    I can able to create single thread in UR10 Script language and i can able to run it successfully but if i create multi-thread it is only looping in the first thread it is not at all executing the second thread and so on.

    Thanks & Regards
    GANESH P

    Reply
      1. GANESH P

        Hi Lars,
        This is how my code looks.
        var_1 = 1
        var_2 = 1
        wait:0.001
        socket_open(“192.169.100.101″,3000)
        Thread_1
        wait:0.001
        if var_1 == 1
        socket_send_string(“Hi”)
        var_1 = 0
        wait:0.001
        Thread_2
        wait:0.001
        if var_2 == 1
        socket_send_string(“Hello”)
        wait:0.001
        var_2 = 0

        Thanks & Regards
        GANESH P

        Reply
        1. zacopressadmin Post author

          Hi GANESH

          What I notice is that – since Threads run virtually at the same time – and at the same time as the main program i.e. parallel to each other – and since both var_1 and var_2 is first True at the same time – then both Threads will be trying to send over the socket at the same time, but only one can – and then var_1 and var_2 is set false at almost the same time and then it will look like only one Thread is running.

          Another thing is that I do not fancy so much to have socket commands in Threads because it can tie up ressources and also because Threads runs virtually independant of the main program and therefore there is little timing control over such events inside the Threads.

          I prefer to have socket commands in the main program.

          Author:
          By Zacobria Lars Skovsgaard
          Authorised Universal-Robots Support Forum.

          Reply
  15. GANESH P

    Hi Lars,

    Thanks for your answer for the previous question. In this question i have some doubts about how to create threads in UR10 script language….
    Thanks in advance
    Regards
    GANESH P

    Reply
    1. zacopressadmin Post author

      Hi Ganesh

      I havent tried to makes threads with script commands, but maybe others on the forum have.

      Regards
      Zacobria

      Reply
  16. Zoran

    Hi Lars,
    Thank you for such a great website and support. We are using the UR5 with the CB3 controller. We have successfully been able to use script commands to control the position of our UR5 over ethernet from a PC with a 3D mouse. However, we are experiencing a Protective Stop error (C204A3) Invalid setpoints: sudden change in target speed. Our application requires that we can move the UR5 around in any direction quite quickly with the 3D mouse. The master PC updates the position commands to the UR5 at 125Hz. When using the 3D mouse, if we control the motion of the robot with rapid movements of the mouse, we receive this error. The log tells us that too high accelerations or motions are not ramped correctly down. This suggests that when the 3D mouse is moving around rapidly, with a large displacement, this causes the UR5 to ramp up its acceleration to reach the desired position. Can you please recommend how we can work around this issue?

    Thanks,
    Zoran

    Reply
  17. Karsten Michaelsen

    Hi Lars

    I am developing a program where I want to be able to controle the Robot as much as possible from my PC and dont have any program on the robot, but controlling it just by sending script-commands. After all I have come to a conclusion that this is not quite possible, so now I am wondering if there is a way to send an URprogram (.urp) including the safety configuration and script from my PC using a TCP/IP-connection, and make the robot start this program?

    Reply
    1. zacopressadmin Post author

      Hi Karsten

      Thanks for your email.

      It is possible to control the robot with script commands as shown in the example on this forum – and you can read inputs with MODBUS commands from the robot registers.

      Yes it is possible to develop a program on another robot or the simulator and create a .urp file – which then can be transferred with FTP to the target robot. However you will properly still need to acknowledge messages on the robot screen because of differences in kinematics among individual robots.

      I am not sure why you wish to have the program on hardware than the robot is running on ? because it creates risk of timing differences.

      If it is because you wish to send coordinates from another host system then you might consider the client-server example approach – then you can also read inputs etc. on the robot and send the status back to the host as variables.

      http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-client-server-example/

      Author:
      By Zacobria Lars Skovsgaard
      Authorised Universal-Robots Support Forum.

      Reply
  18. Nemeth

    I would like to have a Thread which stops the actual Action (e.g. move) if a condition exists.
    To move the Robot till a microswitch turned on. There is a build in stucture (Stacking) but in the script code I have seen that it does a Kind of small movement towards the direction and in the Background checked if the condition fullfilled with a global variable.
    Is there a easier way to do that (e.g. stopl(1.2) – but this one generates an error “Another thread Controlling the robot”) or it can be done only this way.

    Reply
    1. zacopressadmin Post author

      Hi Nemeth

      Thanks for your question.

      Is there a particular reason for you want to use Thread ?

      You might consider to use the function “Check expression continuously.” As part of an IF statement where-in you have the Move.

      You can find more about the function here

      http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/if-then-else-conditions/

      It is not advisable to have something that controls the movements of the robot including stop commands in Threads because then there will be two different program parts that is trying to control the robot. You can for example control variables in threads which are used in the main program to control the movement of the robot.

      Author:
      By Zacobria Lars Skovsgaard
      Authorised Universal-Robots Distributor.

      Reply
      1. Frdtf

        Hi, I don’t really see the point of using a continuous if statement with the purpose to avoid threads controlling movements, since when you look at the generated script, the code block contained in the if statement will be ran in a thread anyway…

        Also, I have the same issue, I want to run a sequence of movement as long as an external input is HIGH, but I run in the “Another thread is already controlling the robot” error…

        Reply
        1. zacopressadmin Post author

          Hi Francois

          Thanks for your question.

          A thread is a parallel process and the robot can only be at one location at a given time – so only one process can control the robot movements which is normally the main program. Otherwise it could result in different process trying to move the robot in different directions at the same time which is not possible.

          Whereas a sequence of If statement in the main program is not in parallel, but in sequence.

          So conditions can be monitored in threads in parallel of the main program and thereby it is possible to set variables in such thread based on conditions (for example inputs) and then these variables can be used in the main program to move the robot according the desired conditions. Since an “If” statement can have “Check expression continuously” a previous move can be interrupted by a following “IF” statement.

          I am not sure what you mean by “the code block contained in the if statement will be ran in a thread anyway…” – can you show the program code ?

          Author:
          By Zacobria Lars Skovsgaard
          Accredited Universal Robots support Centre and Forum.

          Also check out the CB3 forum

          Reply
  19. Babak

    Hi
    I have a question.
    I need to know if there is anyway of sending multiple move command to the robot from PC the way that
    it moves continues between those points.(not stop and start after each point)?
    Tank you

    Reply
    1. zacopressadmin Post author

      Hi Babak

      Thanks for your question.

      Yes there are different ways to do that.

      1. This example sends multiple move commands.

      http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-via-socket-connection/

      2. This example establishes a Client/Server connection where data is exchanged that is put into positions for the robot to move to.

      http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-client-server-example/

      Author:
      By Zacobria Lars Skovsgaard
      Authorised Universal-Robots Distributor.

      Reply
  20. Pablo

    Hi Lars,

    Is there any documentation about what the dashboard server can do? I’ve seen the “load” and “play” commands. Is there anything else? Can the robot send data through it in some way?

    Thanks a lot!

    Reply
    1. zacopressadmin Post author

      Hi Pablo

      The dashboard server is mainly for giving commands to the robot. You should be able to get the documentation from your UR provieder.

      Author:
      By Zacobria Lars Skovsgaard
      Authorised Universal-Robots Distributor.

      Reply
  21. John Goodbutter

    Dear Lars,

    Thank you for these information. Can you tell me which type of control is possible through the UR10 API :
    - joint position ?
    - Joint velocities ?
    - Joint torque ?

    Also, are the UR10 arms equipped with joint level torque measurement ?

    Thanks in advance for your answers.

    Best regards
    John

    Reply
  22. Jan Michael Due

    Hi Lars

    I am looking into using socket_get_var to communicate with a PLC.
    Do you know what the Robot expect back from the call?
    It is sending “GET VARNAME$1″

    Reply
      1. Jan Michael Due

        Ok, I think maybe the $1 is something that rslogix is adding.
        My string (not the one written above) is supposed to be 10 ascii chars long but this does not count the”1″.
        I changed to use socket_send_int but I don’t like sending only values in a message.
        I will never know if data were corrupted.
        Maybe I will look into it another time.

        Reply
        1. zacopressadmin Post author

          Hi Jan

          Yes some data check is good – and I like to create my own protocol and I prefer socket_read_ascii_float like the example shows.

          Notice that the robot expect the number of elements as stated in the command, but the variable will contain one more element as stated which is the first element that tells how many elements was received – which is also a sort of check – but more conditions can be created when creating a self made protocol.

          Author:
          By Zacobria Lars Skovsgaard
          Authorised Universal-Robots Distributor.

          Reply
          1. Micheal

            Hi I was wondering if there was a way to stop the robot from thread (safety stop), in order to wait for a command from a pushbutton and continue back where I left off in the program.

          2. zacopressadmin Post author

            Hi Micheal

            Thanks for the question.

            It might be considered the use the “Dashboard server” feature. If a “pause” is send to the Dashboard server then the program execution Pauses. The program can be resumed by pressing the play button on the teach pendant – or by sending a “play” to the dash board server from an external device. The dashboard server can be reach on the loop back IP address of 127.0.0.1 or through the robots external IP address at port 29999.

            Program
            Robot Program
            MoveJ
            Waypoint_1
            Waypoint_2
            Thread_1
            Wait: 0.1
            If digital_in[1]≟ True
            socket_open(“127.0.0.1″, 29999)
            socket_send_string(“pause”)
            socket_send_byte(10)
            socket_close()

            Some more informations about the dashboard server at this link.

            https://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/dashboard-server-port-29999-15690/

            Author:
            By Zacobria Lars Skovsgaard
            Accredited Universal Robots support Centre and Forum.

            Also check out the CB3 forum



  23. liao

    Hello, I have these questions:
    1.In our application, we need to use the velocity controller to command the UR10, and I found in the script there are two command ” speedl(xd, a,t_min) speedj(qd,a,t_min) speedj_init(qd,a,t_min)”. But these commands will block for the t_min. In my application, I will update the velocity command in real time. This requires the velocity command can be eased by the newer coming velocity command.
    while(true)
    {
    /*my algorithm which computes the velocity vector that the tcp need to achieve*/
    Apply Velocity to UR robot
    }
    and my algorithm will guarantee the velocity convergence to zero.
    I think there are two methods to obtain my desired velocity controller:
    first, to find how the speedl() function works, then to make that function not block
    second, to look for the C-API interface . there are almost no materials on how to use the C-API.
    but I have no idea how to implement the two methods.

    2. I can ssh onto UR, and I want to see how these ports works , are there any materials on how to parse the data that I receive from these ports?

    Thank you very much!

    Reply
      1. liao

        Thanks for your reply, but do you know how to use velocity controller on UR?
        or do you know how does the function “speedl(xd, a,t_min) ” implement on the UR Linux platform?
        or how to make the “speedl(xd, a,t_min) ” not block for such a duration of t_min?

        Reply
  24. Brandon

    We have an application where the robot is in a very space-constrained cylindrical space, surrounded by curved shelves from Z -700 to 1800mm. Moving from shelf to shelf, a linear move cannot be done since the robot attempts to move “through” itself. But joint moves cannot be done either since large moves from a bottom shelf to a top shelf would crash the robot as well.

    The happy medium has been to script a single Joint move (move axis 1 only to rotate the robot), followed by a Z-only linear move to move the tool up or down, and then a final joint move to finish off the desired position. My question is, is there a way to combine these two move types together? I essentially need axis 2-6 to execute the Z move while axis 1 is seeking a certain degree position so the robot can swing around within the confines of a cylindrical space and still maintain speed. Thanks!

    Reply
  25. Brandon

    Is it possible within URScript to move the tool along its Z axis relative to whatever angle it came from? (In other words, move the TCP +30mm on the TCP Z axis regardless of the robots current world or joint coordinates)

    I notice the GUI’s method for TCP relative movements generates lines like this:

    movel(pose_add(get_forward_kin(), pose_sub(p[.375871358258, -.706125864086, .362789585946, 1.279933722272, .910153653382, -.212672740657], p[.326413740688, -.611912843623, .362411222280, 1.279910384097, .910015358567, -.212698220233])), a=1.2, v=0.25)

    … but they don’t adapt to whatever the current robot position is.

    Reply
    1. zacopressadmin Post author

      Hi Brandon

      Thanks for your question.

      Try to use pose_trans instead of pose_add.

      Pose_add is with the base as reference whereas pose_trans is with the toolhead as reference.

      Regards
      Lars

      Reply
  26. Kevin

    Hello,

    I am trying to use the script command from the structure tab in the teaching pendant to program the UR5. I have successfully uploaded my script. What I am trying to do now is allow the person using the program to teach the UR5 the 3 main waypoints for the code. I would like the person to be able to teach these, then run the program, with the script reading these points and incorporating them into the script. Is this even possible? When I try just setting up the three waypoints before the script file, and name them the same as those used in the script, the values do not transfer.

    Thank you for your help.

    Kevin

    Reply
    1. zacopressadmin Post author

      Hi Kevin

      Thanks for your email.

      When you import a file into a Script command- then it becomes a static part of the program and does not change until you import a new file.

      For what you are trying to achieve you can maybe get some ideas from the client server example where new waypoint can be exchanged with external host or PC.

      http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-client-server-example/

      Author:
      By Zacobria Lars Skovsgaard
      Authorised Universal-Robots Distributor.

      Reply
  27. Mustafa Üsküdar

    Hi,
    I am working with the UR-6-85-5-A/ UR5 and using the UR-Script.
    And now I would like to use the “View coordinate system” (programmed in the Installation->Mounting menu) instead of the normally used “Base view”.
    Is there any possibility to do that and how can I use this different coordinate system?

    Best regards
    Mustafa Üsküdar

    Reply
  28. Tom Svilans

    Hi,

    Could you elaborate a little bit on the practical difference between ‘movej’ and ‘servoj’ URScript commands? They seem to be doing the same thing, but I’m wondering in what circumstances would you use servoj?
    Thanks in advance!

    Reply
  29. Luuk

    Hello Mister Lars,

    I have been trying to code my program for a couple of weeks now and I can make it via the Teach Pendant but I would like to code the .script file. But I think this file needs to be compiled to make a .urp of it. Is there anyway to do this? Or should the robot be able to open and run .script files?

    Thanks,
    Luuk

    Reply
    1. zacopressadmin Post author

      Hi Luuk

      Thanks for your question.

      No Need to compile Script files – because a Script is a command already.

      There are several different ways to program with script commands.

      1.
      You can insert Script “Lines” directly into your UR program made on the teach pendant – and the script line is executed directly when the program is running.

      2.
      Or you can import Script “Files” (which has Script Lines) into you program – and the script file is executed directly when the UR program is running.

      3.
      Or you can giver script commands from an external device (e.g. PC) via TCP port 30002. However this is a one-way command method – e.g. in this way you cannot read inputs or make loops.

      4.
      Or you can make a combination of both a UR program from teach pendant – which receives Script commands via a TCP port.

      You can see an example on this here.

      http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-client-server/

      Best Regards

      Zacobria
      Universal-Robots distributor.
      Singapore

      Reply
      1. Luuk

        Hi,

        Thank you for your quick reply.

        I’ve tried all those possibility’s but none of them will fully work here. I just keep getting errors.

        When I import the script file and try to play I get “SyntaxError: line 1 def unnamed(): ^”

        When using the TCP connection I managed to connect with 30002 and another to send back info but the info I ask sometimes terminates the connection and required a system restart to be able to make another connection.

        Thanks,

        Luuk

        Reply
          1. Luuk

            This one worked, I guess I have a programming error in my code. Am I allowed to define functions inside the script?

  30. Dorin Emanuel

    Hello Mr. Lars,

    I have some questions about using subprograms. My UR10 robot have to do the same operation in 13 different points. For this, I use a subprogram that I call after some point that robot approached. This subprogram is using as variable the latest point pose. It is something like that:
    moveJ
    point1 (fixed point)
    pCurrent=get_actual_tcp_pose()
    call subprogram
    moveJ
    intermediate_point (fixed point)
    point2 (fixed point)
    pCurrent=get_actual_tcp_pose()
    call subprogram

    ‘subprogram declarations’
    def subprogram()
    moveJ
    pCurrent (variable point)
    set digital_out(1, True)

    In order to minimize cycle time, the intermediate_point has an increased speed and acceleration and a blending radius. The problem with that is that Polyscope won’t let me change the value of blending radius. It says “The maximum value is 0.0 mm” and there is enough distance between point1 and point2. It’s like the global variable pCurrent from Robot Program transforms into local variable inside subprogram and returns to the Robot Program the local value from which the robot goes to point2. Must I mention that inside the subprogram (.urscript viewside) the pCurrent variable is seen as global variable.
    Do you have any ideea how to get thru this?
    Thanks.

    Reply
    1. zacopressadmin Post author

      Hi Dorin

      Thanks for your email

      I suggest you consider the Wizard Template “Pallet” and select the type pattern “List”.

      In there you can add waypoints and define the task to do at each Point.

      Regards
      Lars

      Reply
  31. Peter L.

    Thank You Lars,
    I think the thread is created automatically, when I programm graphically and put a while Loop to check continously before the script code. In the Log I can see that there is caused a Problem with the Ethernet Connection and that Packet are lost.

    Reply
    1. zacopressadmin Post author

      Hi Peter

      Thanks for your question.

      I am not able to create the same situation as you describe.

      When I insert a While loop then I doesn’t see a “Thread” automatically being inserted into my script file.

      The code you have in the script file was that from the blog text or from the comment section ?

      I do also not have any error messages in my log about the Ethernet communication

      Can you list the contents of your script file that is inserted into the program in the GUI ?

      Regards
      Lars

      Reply
  32. Nate

    Hello Lars,
    I would like to compare two poses along only one axis. Is there a way to do this? I have not found a way to isolate one axis of a pose looking through the URScript manual.
    Thanks,

    Reply
    1. zacopressadmin Post author

      Hi Nate

      Thanks for your question.

      There is a function that can provide the entire Pose and then you can get the axis value from that.

      pose_position = get_inverse_kin()

      (Note – Previously called get_forward_kin() and therefore you can find that in examples).

      Then your pose_position variable will contain

      p[2.57614e-06, 0.399991, 0.500199, 3.38842e-06, 3.14, -6.99365e-08]

      where

      [X, Y, Z, Rx, Ry, Rz]

      Note here X is very small – almost 0 – whereas Y is about 400mm.

      Then you need to nest out your desired data from the array e.g. X by using a pointer counter like Move_To_Pos does in our example.

      Regards
      Lars

      Reply
      1. Nate

        Thanks Lars! That was exactly what I needed to know.

        I was trying to access the value from the GUI, and didn’t realize that the pose references in the function editor expand into p[x,y,z,Rx,Ry,Rz] notation. After assigning the poses to variables I was able to do what I needed.

        Reply
  33. Peter L.

    ok I found out, that I had to delete some Labels in the Script, but now I get a Security Stop “TypeError: object does not supoort deferencing”. How is that problem to solve?
    Greets
    Peter

    Reply
    1. zacopressadmin Post author

      Hi Peter

      Thanks for your question.

      I need to see the code to fully understand, but it looks like you are using a * function (That maybe works in other languages), but is not supported here.

      Regards
      Lars

      Reply
      1. Peter L.

        Hello Lars,
        I used your Programm from http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-client-server/. I modufied it a littele bit, because it was inserted in the tree on the left sid in the Panel. You can see how it lokks like now below.
        The Tree structure looked like:
        v Robot Program
        Script
        and it worked now I put a while condition to check continously if the DI1 is true. It Looks like: Robot Program
        while DI1 = TRUE (condition checked continously)
        Script
        MoveJ
        Waypoint

        And now I get the Error “TypeError: object does not supoort dereferencing”. I looked under “Log” and I see that there is a Problem with the Ethernet connection. Should the Program be splitted ? and the first part, where the Connection is established put before the while condition?

        Move_To_Pos=p[0, 0.4, 0.4, 0, 3.14, 0]
        Pointer=0
        Receive_Data=[0, 0, 0, 0, 0, 0, 0]
        Socket_Closed=True
        $ 2 “BeforeStart”
        $ 3 “MoveJ”
        $ 4 “Waypoint_1″
        movej([-4.436072065494562, -1.3509294688607585, -1.5898662740424647, -1.7720278195761425, 1.5692639625048612, -2.8652732472940476], a=1.3962634015954636, v=1.0471975511965976)
        while (True):
        $ 5 “Robot Program”
        $ 6 “Move_To_Pos:=Move_To_Pos”
        global Move_To_Pos = Move_To_Pos
        varmsg(“Move_To_Pos”,Move_To_Pos)
        $ 7 “Receive_Data:=Receive_Data”
        global Receive_Data = Receive_Data
        varmsg(“Receive_Data”,Receive_Data)
        $ 8 “Pointer:=Pointer”
        global Pointer = Pointer
        varmsg(“Pointer”,Pointer)
        $ 9 “If Socket_Closed= True “
        if (Socket_Closed == True ):
        $ 10 “socket_open(’192.168.0.100′, 30000)”
        socket_open(“192.168.0.100″, 30000)
        $ 11 “Socket_Closed:= False “
        global Socket_Closed = False
        varmsg(“Socket_Closed”,Socket_Closed)
        end
        $ 12 “pose_position = get_forward_kin()”
        pose_position = get_forward_kin()
        $ 13 “joint_positions = get_joint_positions()”
        joint_positions = get_joint_positions()
        $ 14 “socket_send_string(pose_position)”
        socket_send_string(pose_position)
        $ 15 “Wait: 1.0″
        sleep(1.0)
        $ 16 “socket_send_string(joint_positions)”
        socket_send_string(joint_positions)
        $ 17 “Wait: 1.0″
        sleep(1.0)
        $ 18 “socket_send_string(‘Asking_Waypoint_1′)”
        socket_send_string(“Asking_Waypoint_1″)
        $ 19 “Wait: 3.0″
        sleep(3.0)
        $ 20 “Receive_Data = socket_read_ascii_float(6)”
        Receive_Data = socket_read_ascii_float(6)
        $ 21 “Pointer:=0″
        global Pointer = 0
        varmsg(“Pointer”,Pointer)
        $ 22 “While Pointer < Receive_Data[0]“
        while (Pointer < Receive_Data[0]):
        $ 23 “Move_To_Pos[Pointer] = Receive_Data[Pointer+1]“
        Move_To_Pos[Pointer] = Receive_Data[Pointer+1]
        $ 24 “Pointer:=Pointer+1″
        global Pointer = Pointer+1
        varmsg(“Pointer”,Pointer)
        end
        $ 25 “varmsg(‘Move_To_Pos’, Move_To_Pos)”
        varmsg(“Move_To_Pos”, Move_To_Pos)
        $ 26 “movel(Move_To_Pos)”
        movel(Move_To_Pos)
        $ 27 “socket_send_string(‘Asking_Waypoint_2′)”
        socket_send_string(“Asking_Waypoint_2″)
        $ 28 “Wait: 3.0″
        sleep(3.0)
        $ 29 “Receive_Data = socket_read_ascii_float(6)”
        Receive_Data = socket_read_ascii_float(6)
        $ 30 “Pointer:=0″
        global Pointer = 0
        varmsg(“Pointer”,Pointer)
        $ 31 “While Pointer < Receive_Data[0]“
        while (Pointer < Receive_Data[0]):
        $ 32 “Move_To_Pos[Pointer] = Receive_Data[Pointer+1]“
        Move_To_Pos[Pointer] = Receive_Data[Pointer+1]
        $ 33 “Pointer:=Pointer+1″
        global Pointer = Pointer+1
        varmsg(“Pointer”,Pointer)
        end
        $ 34 “varmsg(‘Move_To_Pos’, Move_To_Pos)”
        varmsg(“Move_To_Pos”, Move_To_Pos)
        $ 35 “movel(Move_To_Pos)”
        movel(Move_To_Pos)
        $ 36 “socket_send_string(‘Asking_Waypoint_3′)”
        socket_send_string(“Asking_Waypoint_3″)
        $ 37 “Wait: 3.0″
        sleep(3.0)
        $ 38 “Receive_Data = socket_read_ascii_float(6)”
        Receive_Data = socket_read_ascii_float(6)
        $ 39 “Pointer:=0″
        global Pointer = 0
        varmsg(“Pointer”,Pointer)
        $ 40 “While Pointer < Receive_Data[0]“
        while (Pointer < Receive_Data[0]):
        $ 41 “Move_To_Pos[Pointer] = Receive_Data[Pointer+1]“
        Move_To_Pos[Pointer] = Receive_Data[Pointer+1]
        $ 42 “Pointer:=Pointer+1″
        global Pointer = Pointer+1
        varmsg(“Pointer”,Pointer)
        end
        $ 43 “varmsg(‘Move_To_Pos’, Move_To_Pos)”
        varmsg(“Move_To_Pos”, Move_To_Pos)
        $ 44 “movel(Move_To_Pos)”
        movel(Move_To_Pos)
        end
        end
        and I put the Programm in a scriptfield in the tree.

        Reply
        1. zacopressadmin Post author

          Hi Peter

          Thanks for your email.

          Try to copy and paste the xxxxxx.script (after you have imported your script file into the UR program and tried to run the UR program) file to here then I can see it as it is with the new while statement.

          Regards
          Lars

          Reply
          1. Peter L.

            Hello Lars,

            the file Looks like:

            def string_lesen():
            modbus_add_signal(“192.168.2.12″, 10, 128, 2, “MODBUS_2″)
            modbus_set_signal_update_frequency(“MODBUS_2″, 10)
            set_analog_inputrange(0, 0)
            set_analog_inputrange(1, 0)
            set_analog_inputrange(2, 0)
            set_analog_inputrange(3, 0)
            set_analog_outputdomain(0, 0)
            set_analog_outputdomain(1, 0)
            set_tool_voltage(0)
            set_runstate_outputs([])
            set_payload(0.0)
            set_gravity([0.0, -1.2026031567627009E-15, -9.82])
            while (True):
            $ 1 “Roboterprogramm”
            $ 2 “Während digital_in[0] ≟ True ”
            thread Thread_while_2():
            while (True):
            Move_To_Pos=p[0, 00.4, 0.4, 0, 3.14, 0]
            Pointer=0
            Receive_Data=[0, 0, 0, 0, 0, 0, 0]
            Socket_Closed=True
            movej([-4.436072065494562, -1.3509294688607585, -1.5898662740424647, -1.7720278195761425, 1.5692639625048612, -2.8652732472940476], a=1.3962634015954636, v=1.0471975511965976)
            while (True):
            global Move_To_Pos = Move_To_Pos
            varmsg(“Move_To_Pos”,Move_To_Pos)
            global Receive_Data = Receive_Data
            varmsg(“Receive_Data”,Receive_Data)
            global Pointer = Pointer
            varmsg(“Pointer”,Pointer)
            if (Socket_Closed == True ):
            socket_open(“192.168.2.14″, 30000)
            global Socket_Closed = False
            varmsg(“Socket_Closed”,Socket_Closed)
            end
            socket_send_string(“Asking_Waypoint_1″)
            sleep(1.0)
            $ 14 “Receive_Data = socket_read_ascii_float(6)”
            Receive_Data = socket_read_ascii_float(6)
            $ 15 “Pointer:=0″
            global Pointer = 0
            varmsg(“Pointer”,Pointer)
            $ 16 “While Pointer < Receive_Data[0]"
            while (Pointer < Receive_Data[0]):
            $ 17 "Move_To_Pos[Pointer] = Receive_Data[Pointer+1]"
            Move_To_Pos[Pointer] = Receive_Data[Pointer+1]
            $ 18 "Pointer:=Pointer+1"
            global Pointer = Pointer+1
            varmsg("Pointer",Pointer)
            end
            $ 19 "varmsg("Move_To_Pos", Move_To_Pos)"
            varmsg("Move_To_Pos", Move_To_Pos)
            $ 20 "movel(Move_To_Pos)"
            movel(Move_To_Pos)
            $ 21 "socket_send_string('Asking_Waypoint_2')"
            socket_send_string("Asking_Waypoint_2")
            $ 22 "Wait: 3.0"
            sleep(1.0)
            $ 23 "Receive_Data = socket_read_ascii_float(6)"
            Receive_Data = socket_read_ascii_float(6)
            $ 24 "Pointer:=0"
            global Pointer = 0
            varmsg("Pointer",Pointer)
            $ 25 "While Pointer < Receive_Data[0]"
            while (Pointer < Receive_Data[0]):
            $ 26 "Move_To_Pos[Pointer] = Receive_Data[Pointer+1]"
            Move_To_Pos[Pointer] = Receive_Data[Pointer+1]
            $ 27 "Pointer:=Pointer+1"
            global Pointer = Pointer+1
            varmsg("Pointer",Pointer)
            end
            $ 28 "varmsg("Move_To_Pos", Move_To_Pos)"
            varmsg("Move_To_Pos", Move_To_Pos)
            $ 29 "movel(Move_To_Pos)"
            movel(Move_To_Pos)
            $ 30 "socket_send_string('Asking_Waypoint_3')"
            socket_send_string("Asking_Waypoint_3")
            $ 31 "Wait: 3.0"
            sleep(1.0)
            $ 32 "Receive_Data = socket_read_ascii_float(6)"
            Receive_Data = socket_read_ascii_float(6)
            $ 33 "Pointer:=0"
            global Pointer = 0
            varmsg("Pointer",Pointer)
            $ 34 "While Pointer < Receive_Data[0]"
            while (Pointer < Receive_Data[0]):
            $ 35 "Move_To_Pos[Pointer] = Receive_Data[Pointer+1]"
            Move_To_Pos[Pointer] = Receive_Data[Pointer+1]
            $ 36 "Pointer:=Pointer+1"
            global Pointer = Pointer+1
            varmsg("Pointer",Pointer)
            end
            $ 37 "varmsg("Move_To_Pos", Move_To_Pos)"
            varmsg("Move_To_Pos", Move_To_Pos)
            $ 38 "movel(Move_To_Pos)"
            movel(Move_To_Pos)
            end
            end
            end
            if ( digital_in[0] == True ):
            global thread_handler_2=run Thread_while_2()
            while ( digital_in[0] == True ):
            sync()
            end
            kill thread_handler_2
            end
            $ 4 "FahreAchse"
            $ 5 "Wegpunkt_1"
            movej([-4.807230084586785, -1.770494905839846, 2.4046786310693333, -2.7279828924761484, -2.0925588091455625, -1.1282008863529773], a=1.3962634015954636, v=1.0471975511965976)
            end
            end

          2. zacopressadmin Post author

            Hi Peter

            It might be the use of Thread that creates a conflict because Thread runs parallel with the main program and therefore Thread can handle external events (e.g. controlling a conveyor).

            Maybe consider to Sub routine instead of thread.

            Regards
            Lars

  34. Peter L.

    Hello Lars,
    I use a Script Code to move Robot. The Script Code works, but when I try to put The Script code unter a while condition, I get the Parse error Message “NumError: dublicate labe:l 3 NumError duplicate label 4 NumError duplicate Label: 5″
    How can I solve that Problem?
    Greets
    Peter

    Reply
  35. Brendan

    Hi Lars,

    Hoorah!!! Comms all working and looking pretty stable. Can’t thank you enough for your help.
    Can you declare an array for strings? I’ve tried StackID=["SK1","SK2","SK3","SK4","SK5","SK6"]
    but it doesn’t seem to like that. My messages out to the PC involve cycling through 6 stack identities as above, followed by the numeric status of each stack. It would be good if I could use arrays to do this, rather than have a load of seperate “IF” routines.

    I sort of understand the idea of creating/editing script in a text editor (I’ve done some of that already), and then pointing the robot program to that file. The included script then stays as a block of lines from that file. Is it possible to offline edit the entire program, including the file sourced script and the pendant entered program? I have 2 test programs, one with my communications, and one with robot moves, and I want to join the 2 together, but the position of some of the code needs to change (e.g., my comms is currently in the main program body, all pendant entered, but some of it I want to move into sub routines and threads in my movements program.

    Thanks again

    Brendan

    Reply
    1. zacopressadmin Post author

      Hi Brendan

      1.
      Strings cannot be in a list in the UR program.

      2.
      The text file containing the script code becomes embedded into the UR program.

      After including a text file with script code into a UR program – then try to look into the file “program.script” – that the robot creates by itself. Then you can see your script code as a part of the script code for entire UR program. Especially in the beginning you can see some wrapping that has been inserted automatically.

      Therefore you cannot edit the entire UR program as a script file.

      3.
      It is good to organize a program and sub routines and threads are good for that.

      Keep one thing in mind first – A robot needs to move and it can only be at one position at a time – that’s logic – and it need to have the main priority on the movement task to control the physical position of the robot – therefore you will find that some code cannot be I threads or sub routines – for example when there is a Waypoint in the main program – then a Waypoint should not be in a thread because a Thread run parallel to the main program – and it does not make sense to have two waypoint with different positions in space to be executed at the same time.

      Similar you have to consider where to put the TCP communication – if this communication needs so many recourses (time) that there is no time to move the robot – then the TCP communication must take place while the robot is not moving.

      Threads can be used to things that does not take a lot of recourses and for something that can take place while the robot is moving and doing its main program – for example to control an external conveyor that can move independently of the robot can be controlled by a Thread.

      This comes back to the question about the Strings – Strings tend to take typical more recourse and therefore the handling of strings in a robot program should be minimal – and instead maybe take place externally.
      Same with “IF” statements should be minimal – OK that contradicts a little if you need to use “IF” to handle your list of strings :) – but try to minimize the use of strings.
      Normally a robot will do tasks and things that occur which is based on numbers – for example it could be desirable to display how many pick and how many place it has been handling the last hour or day etc.. i.e. statistics – and then display them to an operator – and normally a small text (string) is good to show with such data. Maybe consider only exchanging numbers to the external device – and then have all the texts (string) on the external device and link them together on the external device that has nothing to do with the robot program execution.

      Regards
      Lars

      Reply
  36. brendan

    Hi Lars,

    Thanks for the detail. That’s pretty perfect. Just to clarify, the PC must send the parentheses and the commas? I have seen this somewhere else I am sure.
    Also, ref point 3), I am seeing these errors on the UR5 when the program gets to the ‘Receive=…. ‘ Does the array have to be defined with the same number of elements as the transmitted data (plus 1 for the length value) ? Do you think I will get this error if there is more or less data in the reception than t he array size?

    Do you know of a way to flush the socket buffer(s)?

    Thanks so much for your time.

    Brendan

    Reply
    1. zacopressadmin Post author

      Hi Brendan

      1.
      Yes the parentheses and commas should also be sent.

      3.
      When you have already assigned a variable – in your case “Receive” to a certain size – then you should not change the size of that variable later.

      It is not the amount of received elements but once you say

      Receive=socket_read_byte_list(3).

      The size should not be changed.

      You can send less data into the array, but then data is counted from left and a messages “nan” appear in the elements that has no data.

      When I send this

      c.send(“(2.1,503.0)”);

      My variable becomes this

      Received_Data : [2,2.1,503,nan]

      (Only two elements – therefore the first element in the received data is “2” – and the third is “nan” because only two elements was sent).

      It does not create any error messages.

      4.
      I would think to close and reopen is a way to clear the buffer.

      Regards
      Lars

      Reply
  37. Brendan

    Hello again Lars,

    More help needed if you can please. Firstly, is there any other end user forum available on the web? I feel bad about asking you for answers all the time. For some reason UR will not open their support pages to end users.

    I am making some progress with my UR communications, but am having big trouble trying to work out the sysntax and rules in some cases. I understand that there are no string manipulation functions, or means to change one typre of variable to another, which is making life difficult!!

    I am trying to receive some information contained in 3 digits or characters, e.g. 5,0,3 or 503. Each digit gives different information to the UR program (PC status, another machine status, and the process for the UR to run).
    I can receive this as a srtring “503″, but then cannot parse this into individual characters.
    I have tried to get socket_read_byte_list, but this is giving me an error (even before the data has been sent by the PC).
    I think that I must send (5,0,3) from the PC. With the brackets and the commas, this obviously comes out with string components. In the PC, I am assembling the following in Visual Basic:
    “(” & 5 & “,” & 0 & “,” & 3 & “)” . I am not sure whther this is correct or not, but my problem occurs before I send it out anyway. (If I use socket_read_string, I can see this come in on the robot)

    Here is the UR side of it
    I have assigned Receive=[0,0,0,0,0,0,0] in before start, and then have
    Receive=socket_read_byte_list(3).
    Receive=socket_read_byte_list(6,”Sock1″)
    In this case (I have tried many) I get “TypeError:resizing lists is not supported”
    Receive=socket_read_byte_list(“Sock1″)
    In this case I get “Type Error Not an Int”

    I have the URscript manual, but it is not very good on syntax examples or error messages, and doesn’t show how to define/handle arrays (other than the position arrays) or bytes. Is the Byte type a separate type, or is it just seen as an short int?

    Is there a way to divide strings into bytes?

    Thanks for your help

    Brendan

    Reply
    1. zacopressadmin Post author

      Hi Brendan

      Thanks for your question – I am not aware of other forums like this, but don’t worry you can ask us.

      1.
      Yeah sometimes life is difficult, but that’s also when it is possible to discover new things with an open mind. The robot is a machine and not a software platform, but it still have so many possibilities because you can design your own communication protocol – although sometimes need to work around a little.

      When I do programming – I also try to use methods I know other platform can do, but then when I discover that there is something different – I let it be and try to shift mind to – OK then lets use what is possible.

      2.
      First you have to decide whether to send characters or numbers – in this example I send numbers only.

      I tried to change the Client server example a little to just receive 3 variables.

      First on the robot side I changed at three places

      Receive_Data = socket_read_ascii_float(6)

      To

      Receive_Data = socket_read_ascii_float(3)

      Then on the PC side (in my case Python side) I changed the data to send like this

      if msg == “Asking_Waypoint_1″:
      c.send(“(1.0,1.2,503)”);
      if msg == “Asking_Waypoint_2″:
      c.send(“(2.1,2.2,503.0)”);
      if msg == “Asking_Waypoint_3″:
      c.send(“(3.1,3.2,503.1)”);

      Then in the robot program I suppress the lines with “Movel(Move_To_Pos)” because I do not want the robot to move while I am just testing this.

      Then I insert

      varmsg(“Receive_Data”,Receive_Data)

      just after all three lines of

      Receive_Data = socket_read_ascii_float(3)

      into the robot program – because then I can click on the “Variables” tab and follow the contents of the Recevie_Data variable while the programs are running.

      On the robot side I also change in the Init variable to

      Receive_Data =[0, 0, 0, 0]

      (Notice there is 4 elements – although I only expect to receive 3 – but that’s because the first element will contain the number of elements I received from the PC i.e. it will become 3 in this case.

      Then run both programs and follow the contents of variable Receive_Data

      Then I run both programs:

      Funny thing – although these variables are type “real” or “float” then when the data send out is 1.0 I receive only 1 like this

      Receive_Data = [3, 1, 1.2, 503]

      (Notice that 1 is without the .0)

      When that data has fraction different than 0 – then I receive the fraction as well.

      Receive_Data = [3, 2.1, 2.2, 503]

      (Notice that 503 is without the .0)

      Receive_Data = [3, 3.1, 3.2, 503.1]

      (Notice that 503 has the .1 as well)

      Can you use this ?

      3.
      If you are getting errors on the PC side before sending anything – then it is properly relate to your Visual basic syntax – I am not familiar with Visual basic.

      4.
      I would follow the approach to spilt in numbers and characters and only send one type at a time and then send the other type in another command.

      And receive them as such also – so it is separate already when received.

      Regards
      Lars

      Reply
  38. Dorin Emanuel

    Hello again and thanks for the answer that solved my problem.

    This time, I have 3 issues / observations.
    1. I’ve noticed lately that Polyscope won’t let me change moveL or moveJ velocity and acceleration. It simply let me introduce the new values in degrees/s or mm/s but it disables the OK confirmation button. I haven’t tried moveP command but I think at the same result. Rebooted system, but this issue continues to appear.

    2. I’ve seen that after pressing the emergency stop mushroom, and let the robot in emergency stop state for couple of minutes, when I run the program again by putting the robot in the OK state, the trajectories aren’t the ones programmed before and thereby the robot collide with below surroundings. It’s like the robotic arm falls. The remedy is to shutdown the controller and then power up again.

    3. Is there any way that robot remembers somehow the position of axes after it had been shutdown? The axis encoders aren’t absolute ones?

    Thank you

    Regards,
    Dorin

    Reply
    1. zacopressadmin Post author

      Hi Dorin

      I have not experienced such situation as you describe – maybe you need to contact your provider to get it checked.

      Regards
      Lars

      Reply
  39. Dorin Emanuel

    Hello Mr. Lars, and thank you for previous answers. I wonder if there’s a way to get the current state of the robot (robot fault, robot OK, etc.) by URscript code, in order to set an output which will be used by PLC automation program. ‘Till now, I haven’t found it. I know it this can be solved by connecting to robot controller on 29999 port and run the “robotmode” command, but this is not an option to my project.

    Regards,
    Dorin

    Reply
    1. zacopressadmin Post author

      Hi Dorin

      In the I/O setup there is an option to set Outputs to a certain state when the robot program is not running.

      So you can allocate an output and set it for example high when the program is running and if the program is stopped then check on this output which will then go low.

      Regards
      Lars

      Reply
  40. Brendan

    Hello Lars and all on the forum. I am new to the UR, and am struggling with a few things. I would be grateful of any help.

    Firstly, are the socket ports functions pre-defined? I have seen reference on here to using different ports for different functions, but I haven’t found a list of these in the manual.

    I have a socket connection set-up as per the examples I have seen on here. I open the connection in a Before Start, and then transmit a string as part of the main program. I then wait 5 secs and try to read a reply, which I display as a varmsg. The send works OK, but the read doesn’t. The popup shows ‘Message Received’ Receive Here is the structure:
    Program
    BeforeStart
    Socked_Close≔ True
    ConnectOutOK≔ False
    While ConnectOutOK≠ True
    If Socked_Close
    ‘Open socket for sending’
    ConnectOutOK=socket_open(“10.0.0.25″,30000,”Sock1″)
    If ConnectOutOK
    Socked_Close≔ False
    Else
    Popup
    Robot Program
    Loop 20 times
    socket_send_string(“Status=Waiting PlateType”,socket_name=”Sock1″)
    Wait: 5.0
    Receive=socket_read_string(socket_name=”Sock1″)
    Popup
    varmsg(“Received”,Receive)
    $ 20 “Receive”

    In connection with this, how do I add a control character (e.g. carriage return ascii 13) to the end of a send_string?

    Is it possible to set up similar comms, but with the UR as Server? I saw something to do with socket_opn LISTEN, but I cannot find it again.

    Basic I/O question. Are the output grounds all commoned, or do they have to be wired individually per output?

    That’s enough for now!!

    Cheers
    Brendan

    Reply
    1. zacopressadmin Post author

      Hi Brendan

      Thanks for your questions.

      1.
      Some Socket ports on the UR are predefined such as for example 30002 which are pre defined to listen to raw Script commands. This is mentioned in the Script manual.

      30000 are free and that’s why I use it in these examples.

      Script manual can be downloaded here

      http://www.zacobria.com/universal_robots_zacobria_customer_support_training_hints_tips.html

      2.
      Instead of line

      receive=socket_read_string(socket_name=”Sock1″)

      try

      receive=socket_read_string()

      3.
      To send a Line Feed from the UR try to use this command

      socket_send_byte(10)

      4.
      I have not seen this “socket_opn LISTEN” command or any Bind command, but maybe others have.

      The UR is server for example on port 30002 listening for script commands, but to setup a new server in a User program I have not seen.

      Bare in mind – the Robot is a machine – so the priority on the CPU load is to move the robot.

      5.
      The I/O on the Master board inside the UR cabinet are commonly connected.

      The I/O on the tool head are commonly connected.

      Regards
      Lars

      Reply
    2. zacopressadmin Post author

      Hi Brendan

      Additional to my previous answer you can also read with this command

      Receive=socket_read_string(”Sock1″)

      Be aware of the timing over the socket – maybe need some wait to make sure the data is send and received on both sides.

      Regards
      Lars

      Reply
  41. Dorin Emanuel

    Hello Mr. Lars and thank you for your answer. I didn’t found scriptmanual for version 1.8, but I will try eventually some other ideas including get_inverse_kin(x) function.

    Reply
  42. Dorin Emanuel

    Hello everybody,

    I am a new user of UR10, and I have some question about UR programming. I need to get current pose of a TCP relative to a defined plane.

    Here’s what I thought:
    current_point=pose_trans(pose_inv(defined_plane), get_forward_kin()).

    Could you tell me please if this solution is right ?
    Thanks in advance.

    Reply
      1. Dorin Emanuel

        No Mr. Lars, but I’m not really sure that that expression solves my problem. I’ve searched the URScript programming manual for those functions and I’m not sure that I got the right understanding.
        get_forward_kin -> returns the current pose of TCP by measuring robot’s joint angles
        pose_inv(defined_plane) -> returns the pose of first point of the 3 that defines the plane by measuring ?!?
        pose_trans(start_pose,final_pose) -> returns the motion of TCP between starting pose and final pose relative to defined plane ?

        Thanks.

        Reply
        1. zacopressadmin Post author

          Hi Dorin

          I think there has been an update on the command format in the recent software version – try and look in scriptmanual for version 1.8 for get_inverse_kin(x).

          The return is X, Y, Z, Rx, Ry, Rz instead of angles.

          You can also get angles by using get_actual_joint_position()

          Pose_inv and Pose_trans I have not tried to use so maybe we need help form some that has experience in using them.

          Regards
          Lars

          Reply
  43. Henrik

    Hello

    I am sending an integer (traynr) converted to string over socket
    conn.sendto(str(traynr).encode(‘utf-8′), (host,port))

    I get the stringvalue in the UR robot but now I want to convert it back to Integer. Can you do that.

    In the first place I want to send an integer from Python over socket to UR but Python don’t alow that.

    Regards

    Henrik

    Reply
    1. zacopressadmin Post author

      Hello Henrik

      Thanks for your question

      At the moment this variable types can not be converted on the UR.

      Can you consider using variable type in the UR program that also can be exchange on the socket ?

      Regards
      Lars

      Reply
  44. Nathan

    Hi Lars,

    Is it possible to power up the robot remotely, i.e. can the robot be turned on via any means other than physically pressing the button on the teach pendant?

    Thank you in advance,
    Nathan

    Reply
    1. zacopressadmin Post author

      Hi Nathan

      Tanks for your question.

      I guess you have in mind other methods than the on switch, but no not other than making some electronics together with the on switch.

      Maybe You can consider making a parallel connection for the on switch and route to another location than the teach pendant, but you will still need a wire though or make some remote controlled activation of a relay. I have not tried this so I do not have any illustrations.

      Regards
      Lars

      Reply
  45. Johannes

    Hi all.
    I’m trying to write a script that sends a string via socket connection. Now my problem is, I can’t get the script to add two strings together, for example:


    string1 = "Hello"
    string2 = " World"

    send_string = string1 + " " + string2

    thank you in advance
    Johannes

    Reply
    1. zacopressadmin Post author

      Hi Johannes

      Thanks for your question.

      Maybe I need to see all your code to understand excately your question.

      When you send via a TCP connection you need a “line feed” after each line – in Python you can use this method.

      s.send (“set_digital_out(2,False)” + “\n”)

      But I am note sure where you expect the output to show ?

      Regards
      Lars

      Reply
      1. Johannes

        Ok so here is my code:

        tcp_force = force()
        string1 = “write,”

        now I want to add these two strings together because the server expects the string to be like : “write,5.131214234″ and then send this string via a socket connection like this:

        socket_send_string(“the new string e.g. write,5.131214234″, socket_name)

        Reply
        1. zacopressadmin Post author

          Hi Johannes

          Thanks for your question.

          One way you may consider is to add the two strings together and store in a new variable – and then only send that new variable.

          Regards
          Lars

          Reply
          1. Johannes

            Thank you for your response!

            The Problem is I don’t know how to add these two string together, because the simple plus operator like this:

            temp_string = string1 + tcp_force

            doesn’t seem to work, does it?

          2. zacopressadmin Post author

            Hi Johannes

            OK in UR script you cannot add strings like this.

            And I think there is a mismatch of type because force is a float.

            Can you consider sending the variable one by one right after each other ? – Or modify the server program to accept something instead of “write,” e.g. another float ?

            Regards
            Lars

  46. Romana

    Hi all!

    I would like to know if there is a function in the UR script language that reads the current time stamp.
    Thanks in advance!

    Regards,
    Romana

    Reply
    1. zacopressadmin Post author

      Hi Romana

      Thanks for your question.

      Maybe you can consider sending the time over a socket connection as a variable.

      Regards
      Lars

      Reply
      1. Romana

        Hi Lars,

        Thanks for your reply. But I would need to know on the time stamp on the robot before a movel command starts.

        Regards,
        Romana

        Reply
  47. Ashwin

    I am trying to program UR5 externally. I cannot figure out how to give ‘move’ command. As the inputs have to be angles by which each motor is to be rotated and the inverse kinematics calculations are too tedious.
    Please Help.

    Reply
    1. zacopressadmin Post author

      Hi Ashwin

      Thanks for your email.

      You can also use a move command for a Pose and give the X, Y, Z, Rx, Ry, Rz like this

      movej(p[-0.078,-0.481,0.300,3.14,0.0,0.0],a=1.3962634015954636, v=1.0471975511965976)

      Notice the “p” which indicates that it is a pose and not angles.

      The X, Y and Z is in 1/1000 mm

      The Rx, Ry, Rz is in radians.

      Regards
      Lars

      Reply
  48. Yusuf

    Hi Lars,
    Firstly, I would like to thank you for your effort.
    We would like to purchase one UR10 for our project. We talked to the local distributor and unfortunately they couldn’t give us enough inormation. When I search through the net about URScript, I ran into this page. I am not that much good at programming, so my question might be a little strange, but to understand it is very crucial for our project.
    Here is what I need. I am using Windows operating system on my PC and also using some force sensors and some other robot and simulation environments on C/C++. Can I communicate and program the UR10 through C/C++ in windows with ethernet connection TCP/IP? If I understood correctly, there is a client in the robot that understands the strings that is sent to the robot through TCP/IP.
    I thought that for example, “get_actual_joint_positions()” is a string (a function from URScript program), and if I send just this string through a TCP/IP connection to the robot, will it understand that I ask the joint positions and it will provide me the positions through that channel, which I write a simple server subroutine in my C code in windows. Or for example, I calculated a position to feed to the robot as an output of a C program which uses information coming from sensors and other stuff. Can I send it to the robot directly, which will send position data to the robot, and robot client understands that and actuates the robot accordingly?

    If I can do this simple, or a little bit complex tasks from C environment in windows, we’ll definitely by this robot to use. But we do not want to go too much detail of the robots very low level controls. We just want to communicate with the robot, to ask/set, definitely end-effector positions, velocities, accelerations, maybe joint positions, torques etc. But not in a very deep way.
    Is it possible?

    Thanks for your help and interest in advance.

    Reply
    1. zacopressadmin Post author

      Hi Yusuf

      Thanks for your question.

      Yes you can do that and your understanding for that the PC is the server is correct, but there is mainly two different ways you can send script commands between the PC and the robot i.e. one way – or – two way.

      The robot has a build-in script interpreter and can understand your script commands via a Ethernet TCP socket from a program on your PC for example you can use the program you like e.g. C/C++, Python, Visual basic, Java etc as long you use the script commands the robot understands. (There is a UR script manual for these commands).

      You can send the script commands raw to the robot on a TCP port i.e. without having done any programming on the robot – and the robot will perform the script instruction for example move. But sending the script commands raw and without any program on the robot is a kind of one way communication and you can only use the commands that makes the robot do an action like move or set outputs. For this mode you cannot get any information’s back from the robot e.g. like asking the position or asking an input status.

      To do that you will need to a little programming on the robot i.e. you need to make your own client handler on the robot and there is an example on this here on this forum.

      Then you make a server handler on your for example C/C++ and you make a client handler on the robot – then the client establish a connection – and then you can literally make your own protocol for how information should be send between the server and robot – for example you can make the client ask for coordinates for the next moves and the server will provide the coordinates – and you can make a instruction to send back the positions and input statuses to the server from the robot.
      The programming on the robot must be done in the robot language which is very much like Python – see the examples.

      So keep in mind – just sending raw script commands to the robot – is a one way communication (there is also an example on that here

      http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-via-socket-connection/

      but that is only one way.

      Instead you need the client/server solution and there is an example on this here called client-server

      http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-client-server/

      So the client is a small program running on the robot (must be written in the robot language similar as Python).

      And the server is a small program running on the PC (can be written in your preferred language).

      And they exchange information’s and make the robot move based on the instruction from the server.

      Because of this you have very big flexibility because you can make your own method of communication over a TCP socket.

      My examples are made in Python because that is what the robot uses, but you can also use other languages for the server part.

      Regards
      Lars

      Reply
  49. alberto

    Hil Lars,

    Where can I find a complete documentation, examples or other resources in order to know what commands, and functionalities are available on port 29999 and how to use them?

    Thanks in advance
    Best regards
    Alberto

    Reply
      1. zacopressadmin Post author

        Hi Greg

        Thanks for your question.

        You can load and play programs via TCP port 29999 on the UR

        For example send to port 29999

        load /programs/test.urp

        play

        Will load the program called test
        And then play (start) the program.

        Regards
        Lars

        Reply
  50. alberto

    Hi Lars,

    I have two use cases that I would want to address:

    1) To call from the PC a subprogram that is stored in the robot memory, using socket programming and the name of the subprogram. So the robot would start to execute it.
    2) To send from the PC a UR Script file, that the robot would start to execute.

    I would want to know if the UR robot provides this capabilities and how to implement them.

    Thanks in advance.

    Regards
    Alberto

    Reply
    1. zacopressadmin Post author

      Dear Alberto

      Thanks for your question.

      1.

      1.1
      On port 29999 you can load and start programs.

      Send in clear text, terminated by a new line:
      load play

      1.2
      Another way is to make a small program on the UR with a Subroutine and then the main program checks for variables send on the Client-Server method as explained earlier and check the received variable and if the variable is e.g. True then call Subroutine.

      2.
      You can send by FTP and then use method explained above in 1.1

      Regards
      Lars

      Reply
  51. alberto

    Hi Lars,

    Thank you very much for all your support. I am looking forward to fully test and implement the robotic system in order to meet the project especifications. Of course, I will let you know about my experiences at this forum.

    Have a nice day!!

    Reply
  52. alberto

    Hi Lars,

    I have figured out the efect of the varmsg function. When you use the function varmsg(“var_name”, expression), this will make that in the Variables tab of the Program tab of the PolyScope enviroment the following information to be shown: “var_name” : expression_value.

    On the other hand, I want to ask you if I can have several socket connections open with the same IP and different ports in different threads. I need to do that in order to have the client robot main program attending the blocking movement commands, while at the same time a thread will be on charge of sending the current position of the robot as requested by the PC Server Program.

    Thanks in advance. Best regards

    Reply
    1. zacopressadmin Post author

      Hi Alberto

      Many thanks for your information on the varmsg.

      Regarding your question:
      Yes since software version 1.6 there is Support for multiple TCP/IP sockets from UR Script programs.

      However I do not fully know what is your intention, but I would try not to have too many open ends at the same time especially when using threads because the threads virtually runs at the same time (although down to details there is still only one processor) and therefore there is a high risk to get conflicts e.g. if something that happens in one thread actually affects whats going on in another thread or in the main program or affect a Sub Program.

      I would also try to keep the program on the robot as simple as possible and have the heavy computing functions on the PC side. The robot is a machine after all – not a super computer although it is really a fantastic innovative creation.

      A classical and easy to understand example of how conflicts can occur is this – The robot can only be at one absolute position at a any given time – and since threads can run parallel with the main program it will be impossible to have a waypoint at one location in a thread and at the same time have another waypoint at a different position in another thread or main program or Sub program.

      I think this could be similar if you are using multiple open sockets to different ports, but as a programmer you need can take care and manage that.

      Therefore if you need to know the robot position – then I would make sure I try to ask and report that in the same part of the program that has the control of the robot at that given time.

      It is an interesting project you got and make sure you update our forum with your valuable experiences.

      All the best.

      Regards
      Lars

      Reply
  53. alberto

    Hi Lars,

    I want to ask you about the creation of a subroutine. I know how to use it in the program once you have one created, but I don’t know how to create one from scrach and how to define its call parameters.

    Thanks in advance. Regards

    Reply
    1. zacopressadmin Post author

      Hi Alberto

      A Sub Routine can be a Sub Program or a Thread.

      There are examples on using Thread at this link

      http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/thread/

      Sub Programs are similar as Threads. The difference is that Sub Programs are called from the main program and after the Sub Program has been executed the main program resumes – whereas a Thread runs parallel to the main program – so Threads are good to use when controlling external equipment.

      You can use global variable that can be used outside and inside the Sub routine. And you can use local variable that can be used inside the subroutine.

      In the Thread example a global variable is used both outside and inside.

      The software manual is also very good to consult on this topic.

      Another good trick to learn the script programming is to create programs in the GUI on the robot and save the file because when the GUI program is saved there is automatically created a script file of the same program – and then you can see exactly how a script program should be for the same program.

      Have a great week-end

      Regards
      Lars

      Reply
  54. alberto

    Hi Lars

    Thank you very much for your help.
    I have one more question that I have not found in the UR script manual: What does the function varmsg do?

    Thanks in advance. Have a nice day!!

    Reply
    1. zacopressadmin Post author

      Hi Alberto

      I think varmsg can be used to send variable information to the PC during test. I have no documentation on this – if you find any then let me know.

      You to have a nice day.

      Regards
      Lars

      Reply
  55. alberto

    Hi Lars,

    I am programming a Server on the PC and a client on the robot communicated by TCP protocol, as you suggested.

    I would want the robot to send a float value to the PC. How can I do that?
    I would want the robot to send its current pose to the PC. How can I do that?

    Thansk in advance

    Reply
    1. zacopressadmin Post author

      Hi Alberto

      On this page

      http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-client-server/

      And scroll down to

      ” Result on PC server host for the above programs.”

      Where this below is received from the Robot and show on the PC

      The robot position is(XYZ vector)
      p[2.57614e-06, 0.399991, 0.500199, 3.38842e-06, 3.14, -6.99365e-08]

      The robot position is(Joint angle)
      [-4.43607,-1.35093,-1.58987,-1.77203,1.56926,-2.86527]

      I hope you can use this example or maybe consider sending floats one by one.

      Regards
      Lars

      Reply
  56. alberto

    Hi Lars,

    How can I send through a socket connection an array of floats from the robot (client) to the PC (server)?
    Ideally I would want to do it in a single socket send operation.

    There is a way to convert an array of floats to a string representation in the UR script language?
    Does the UR script language support string concatenation?

    Thanks in advance

    Reply
    1. zacopressadmin Post author

      Hi Alberto

      Thanks for your question. At the moment there are no such functions for these questions. Generally I think is will be good to have the more heavy computation and functions on the external computer side ?

      Regards
      Lars

      Reply
  57. alberto

    Thanks for the quick response. The response has been useful to me but I need to do something slightly different:

    I would want to send, from the PC, in just one string all the information relative to just one UR command to the robot.

    The format of the string being send to the robot could be, for intance, as follows:
    “commandTag commandVariable1, commandVariable2,…, commandVariablen”

    Where:
    – commandTag is a string that labels the command that the robot should execute. For instance, one label could be “MoveJoint” (to label a “movej” order), other could be SetDigitalOutput to label “set_digital_out”
    – commandVariablei – is a string representing the value of the i th varible of the command labeled by “commandTag”. This value should be parsed to the corresponding type (pose, int, float , bool)
    With this information the robot can “assemble” the command to be exectuted and execute it.

    For doing this, it think that I would need, at least, the following UR script functions:
    -Find a substring inside a given string (in order to know the command to be executed)
    -Split a string into serveral strings (one string for each coomandVariable and other for the commandTag)
    -Convert (or parse) a string to another type (pose, int, float, bool) value in order to properly “feed” the UR command to be executed with its parameter values.

    I think that with this string related functions it is feasible to construct a simple PC-UR interpreter.
    Thanks in advance.

    Reply
    1. zacopressadmin Post author

      Hi Alberto

      Thanks for your reply.

      I compare this a little bit with how you in some programming language uses a Sub routine with parameter transfer when you call the sub routine.

      I am not aware of such ready made function, but maybe someone already has made this.

      I still think you need to make your own program on the robot almost as an Interpreter and fetch the parts from the original master string and branch the information into smaller strings and other variable types and then let the robot execute with the value of each variable.

      You could create different sub routines on the robot depending on the tasks needs to be done by the robot and then the different sub routines are called depending on your command tag and the variables that follows in your master string.

      So you have one program block on the robot that receives the string from the PC and fetch and branch the information into the smaller portion based on the rules you have set out for the length of each information.

      Then if the command tag is for example 1 then it is sub routine 1 that is called and executed with the variables received – if command tag is 2 it is sub routine 2 that is called and so on..

      I do not have examples of this, but it is following the idea from the Client-Server example – just much bigger master string to fetch out from.

      Regards
      Lars

      Reply
      1. alberto

        Hi Lars, thanks for your answer.

        I agree with you, I need to do a program in the robot acting as a kind of interpreter.

        I had already seen the Client-Server example program but I need more flexibility in the sense that I would want to send to the robot a string encoding the funciton to be executed by the robot and the parameters that the function is going to use.

        As I have mentioned in my previous entry, in order to do that I need to extract from the string received by the robot the information needed to call the appropiate function and the parameters of this function.

        So I need to analyze in the robot client program the string sended by the PC, so I need to know if the UR Script language provides functions in order to analyze the string, as I said I think that I should need the following functions:

        -Find a substring inside a given string (in order to know the function to be executed)
        -Split a string into serveral strings (one string for each coomandVariable and other for the commandTag)
        -Convert (or parse) a string to another type (pose, int, float, bool) value in order to properly “feed” the UR command to be executed with its parameter values.

        So, does the UR script programming language provide such functions or similar in order to analyze in the robot client program the string sended by the PC?

        Thanks in advance.

        Reply
        1. zacopressadmin Post author

          Hi Alberto

          Thanks for your messages.

          No there is not a script function that can do this in one go. You need to fetch out the data one by one – similar to how the pointer is doing it in the Client-Server example, but you can do that in steps for each command tag and variables so you end up with a range of variables from the master string and then you also need to program and do your analyses manually.

          By the way do you have the script manual ? – I am sure your supplier can provide you with that.

          Regards
          Lars

          Reply
          1. alberto

            Hi Lars,

            Yes I had read the cript manual, but I thought that the manual could be incomplete because the functions I have asked you for are quite common in other programming languages, so I decided to ask you for this functionality.

            Thank you very much for your responses!!

          2. zacopressadmin Post author

            Hi Alberto

            Very good you have the script manual.

            Try also to also ask other places for recommendations – and maybe someone else has other information’s.

            Have a great day.

            Regards
            Lars

  58. alberto

    I would want to know if in the script language there are some built-in parse functions. I would want to send a string from the PC, acting as a PC server, to the robot acting as a client. And then the robot should analyze this string in order to determine the instruction that is going to execute.

    For instance, if whe send from the PC the following string to the robot:
    “movej ([-0.5405182705025187, -2.350330184112267, -1.316631037266588, -2.2775736604458237, 3.3528323423665642, -1.2291967454894914], a=1.3962634015954636, v=1.0471975511965976)”

    I would like to be able to execute this instruction by analising and parsing the string in the robot client program. I don’t want to use the execution infraestruture available through the 30002 port because i want to send more than one instruction at a time. And also I need to execute more than one type of instruction. As for example asking for the current position of the robot, or make a cirucular move, or activate a digital output of the robot.

    I would want to know what is the recomended best practice in order to do this.

    Thanks in advance.

    Reply
    1. zacopressadmin Post author

      Hi Alberto

      Thanks for your email.

      Yes the facility on port 30002 is quite simple and is like a one way communication – and if the robot does not like or understand your command on port 30002 it just discard it. And you can also not get a status back e.g. a digital I/O status from the robot on port 30002.

      I normally just use port 30002 only if I want very fast to test a command

      I understand your idea and it is very good, but there is no such Interpreter in the robot, but you can make one your self.

      You need to make a program on the robot that can receive your commands from your PC. For example you can establish a TCP socket connection on port 30000 between the robot and the PC and then construct the program on the robot so it can receive several variables in a sequence – this can also be different types of variables.

      If you need the robot to check the validity of your commands – then you need to make your own check routine on the robot – and program what the robot should do if it receives something incorrect – maybe send a message back to the PC.

      You can create your own rules and for example the first variable to receive is an array receiving the coordinates in a very simple form – and then the robot add the ”movej” and commas etc.. The next variable to receive is maybe a Boolean for an output (True or False) and so on.

      Or you can do it the other way around and let the robot ask at certain interval for new data on the PC – and if there is no new data the robot continue its execution.

      Depending on which side you want to have the simplest program.

      The very short answer to your question is – No there is not such Interpreter on the robot, but you can create one.

      The robot is very fast to program via the innovative GUI menu locally on the robot – if you need to communicate with a PC via TCP communication there is more traditional programming to do, but on the other hand you can almost make the robot communicate as you wish with external equipment.

      Regards
      Lars

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>