Home Programming

Discussion

Left ArrowBack to discussions page
matthewd92matthewd92 Founding Pro, Tactile Sensor Beta Testers Posts: 1,065 Handy
edited May 2017 in Programming
I thought that we might want a single thread where everyone can post up any handy little helper functions that they have developed over time that make programming and using the UR robots easier.  If you have any functions that you are willing to share please post the code below along with an example of how to use the code.  If you have any questions about how to use something please feel free to reach out to the author or post a question on here so that everyone can learn from each other.

Comments

  • JoseJose Posts: 11 Apprentice
    Hi,
    where I can find the list of commands like "set speed" , "popup" ... ?
  • matthewd92matthewd92 Founding Pro, Tactile Sensor Beta Testers Posts: 1,065 Handy
    The dashboard server commands can be found in this document https://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/dashboard-server-port-29999-15690/

    the other commands thay that I use regularly are sprinkled throughout the UR support website.  
  • JoseJose Posts: 11 Apprentice
    Thanks for your reply.
  • klacourtklacourt Posts: 12 Apprentice
    It appears the close popup command does not work for the "Protective Stop" popup?  I am running 3.5.3.10825 with no luck...
  • klacourtklacourt Posts: 12 Apprentice
    AHH!  Just found "unlock protective stop" is a dashboard command!  My reference must have been old.
  • lakshmip001lakshmip001 Partner Posts: 41 Apprentice
    Hi, I am controlling UR5 using PC and sometimes results in an error getinverse(): unable to find solution displayed on UR teach pendant. How can I read popup message from pc and then close the popup.
  • JstewartJstewart Posts: 33 Apprentice
    This function allows you to easily change the speed of the running robot by changing the current value of the speed slider programmatically.
    def runSlow(speed):
    
    if speed == 0:
      speed = 0.001
    end
    socket_open("127.0.0.1",30003)
    socket_send_string("set speed")
    socket_send_string(speed)
    socket_send_byte(10)
    socket_close()
    
    end
    
    
    This function takes a float between 0 and 1 as an argument, one thing to note is if you actually send 0 it pauses the program but I have not found a way to easily recover from this so I am using the if statement to verify that the speed is not 0, if so it sets it to 0.001 which basically stops motion but allows the robot program to continue to run.

    Usage in a program would be

    runSlow(0.2)

    @matthewd92 Is it normal for this to lag when changing the speed? I noticed that whenever i set my waypoints and set the speeds right before them.




  • matthewd92matthewd92 Founding Pro, Tactile Sensor Beta Testers Posts: 1,065 Handy
    edited November 2019
    Here is something that we get asked about a lot, which is creating planes in URScript.  One word of caution, these calculations result in a plane that is configured with the first point as the origin, +Y axis defined by the second point and the +X axis defined by the third point, this is not the same way that UR calculates planes in current polyscope (newer than 3.7 or e-series) but we still use it everyday in production environments.  We did not develop this code so I will not take credit for it but it has been thoroughly tested and used by us and works as expected.

    #**
    @apiglobal_plane_finder(p1,p2,p3) global_plane_finder
    @apiGroupPrivate Scripts
    @apiNameglobal_plane_finder
    @apiDescriptionThis method is used to calculate the plane on which the welds have to be made.
    #*

    def global_plane_finder(p1, p2, p3):
      V12 = [p2[0] - p1[0], p2[1] - p1[1], p2[2] - p1[2]]
      V13 = [p3[0] - p1[0], p3[1] - p1[1], p3[2] - p1[2]]
      VZ = mycross(V12, V13)
      Tmat = pose2Tmat(p1)
      VZofp1 = [Tmat[2], Tmat[6], Tmat[10]]
      value = mydot(VZ, VZofp1)
      if (value < -0.00001):
        VZ = mycross(V13, V12)
      end
      VZ = myunitised(VZ)
      VY = myunitised(V12)
      VX = mycross(VY, VZ)
      output = [VX[0], VY[0], VZ[0], p1[0], VX[1], VY[1],
      VZ[1], p1[1], VX[2], VY[2], VZ[2], p1[2], 0, 0, 0, 1]
      local pose = Tmat2pose(output)
      return pose
    end


    def mycross(a, b):
      output = [0, 0, 0]
      output[0] = a[1] * b[2] - a[2] * b[1]
      output[1] = a[2] * b[0] - a[0] * b[2]
      output[2] = a[0] * b[1] - a[1] * b[0]
      return output
    end


    def Tmat2pose(Tmat):
      output = p[0, 0, 0, 0, 0, 0]
      output[0] = Tmat[3]
      output[1] = Tmat[7]
      output[2] = Tmat[11]
      sy = mynorm([Tmat[0], Tmat[4], 0])
      if (sy > 0.00001):
        x = atan2(Tmat[9], Tmat[10])
        y = atan2(- Tmat[8], sy)
        z = atan2(Tmat[4], Tmat[0])
      else:
        x = atan2(- Tmat[6], Tmat[5])
        y = atan2(- Tmat[8], sy)
        z = 0
      end
      rotvec = rpy2rotvec([x, y, z])
      output[3] = rotvec[0]
      output[4] = rotvec[1]
      output[5] = rotvec[2]
      return output
    end


    def pose2Tmat(pose):
      if (pose[3]) == 0 and (pose[4] == 0) and (pose[5] == (0)):
        Rmat = [1, 0, 0, 0, 1, 0, 0, 0, 1]
      else:
        x = pose[3]
        y = pose[4]
        z = pose[5]
        ang = mynorm([x, y, z])
        x = x/ang
        y = y/ang
        z = z/ang
        s = sin(ang)
        c = cos(ang)
        t = 1 - c
        Rmat = [c + (t * x * x), (t * x * y) - (s * z), (t * x * z) + (s * y), (t * x * y) + (s * z),
        c + (t * y * y), (t * y * z) - (s * x), (t * x * z) - (s * y), (t * y * z) + (s * x), c + (t * z * z)]
      end
      Tmat = [Rmat[0], Rmat[1], Rmat[2], pose[0], Rmat[3], Rmat[4],
      Rmat[5], pose[1], Rmat[6], Rmat[7], Rmat[8], pose[2]]
      return Tmat
    end


    def mynorm(a):
      base = sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2])
      return base
    end


    def myunitised(a):
      output = [0, 0, 0]
      base = mynorm(a)
      output[0] = a[0] / base
      output[1] = a[1] / base
      output[2] = a[2] / base
      return output
    end


    def mydot(a, b):
      output = a[0] * b[0] + a[1] * b[1] + a[2] * b[2]
      return output
    end

  • matthewd92matthewd92 Founding Pro, Tactile Sensor Beta Testers Posts: 1,065 Handy
    Jstewart said:
    This function allows you to easily change the speed of the running robot by changing the current value of the speed slider programmatically.
    def runSlow(speed):
    
    if speed == 0:
      speed = 0.001
    end
    socket_open("127.0.0.1",30003)
    socket_send_string("set speed")
    socket_send_string(speed)
    socket_send_byte(10)
    socket_close()
    
    end
    
    
    This function takes a float between 0 and 1 as an argument, one thing to note is if you actually send 0 it pauses the program but I have not found a way to easily recover from this so I am using the if statement to verify that the speed is not 0, if so it sets it to 0.001 which basically stops motion but allows the robot program to continue to run.

    Usage in a program would be

    runSlow(0.2)

    @matthewd92 Is it normal for this to lag when changing the speed? I noticed that whenever i set my waypoints and set the speeds right before them.




    Yes, there can be a lag between issuing the command and the speed slider being adjusted, it is usually very small but I have seen it have as much as 1/2 second or so lag.  We use this primarily at the start of a program for instance when we are debugging to make sure that it runs slow, allows us to move the speed slider back to 100% when we use the move screen but not have to worry that we might start a buggy program at speed.

    We have also used in before in conjunction with a laser scanner, instead of putting the robot in a safeguard stop when someone entered the cell, we placed the robot in reduced mode and then fired a set speed command to chop the speed slider to 1%, this effectively "stops" the robot, its still moving but extremely slowly.  This was so the program could continue to run even when someone walked by so that we could monitor the machines in the cell and catch their completion status as it was only broadcast once and missing it meant we never knew the machines finished.  We no longer follow this practice but rather wire machines like that up to other systems that can catch those signals such as a PLC and then the robot communicates with the PLC to get the information it is looking for.
Sign In or Register to comment.
Left ArrowBack to discussions page