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)
Another example is how to have a popup message that only has an OK button and is non-blocking, this allows you to have informational messages that do not stop the program execution and that the operator cannot stop program execution from either. An example of where we use this is during programs that have a long start-up time during the before start portion of the program. We will pop up a message to tell the user that the program is in the process of starting so that they don't hit the play button repeatedly.
def infoPopup(msg):
socket_open("127.0.0.1", 29999, "popup")
socket_send_string("popup ", "popup")
socket_send_string(msg, "popup")
socket_send_byte(10, "popup")
socket_close("popup")
end
The way that you would use this is infoPopup("Some Message Here")
One last one is to programmatically close the popup, now, the caveat to this is it will close ANY open popup, it actually doesn't know what it is closing, just that popups will be closed. So you want to make sure you are only using this when there is no chance that you are closing something that should be blocking operation, user be warned.
def closeInfoPopup():
socket_open("127.0.0.1", 29999, "close")
socket_send_string("close popup", "close")
socket_send_byte(10, "close")
socket_close("close")
end
Simply use it by calling the function in your program
closeInfoPopup()
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.