URScript is a language developed by UR, which has many similarities to Python.
All functions are explained in the script manual.
URScript is not a compiled language, thus an error will first occur when it is executed, in contrast to e.g. C or C++ where the compilation will discover the error.
Thus, your script program can run until an error (syntax error or similar) occurs.
Two simple ways of debugging your script code might be:
- Using global step-counter variables
- Writing status messages to the logfile
1) Step-counter variables
Using global dummy variables in your program makes it possible to see the progress in the Variables tab in PolyScope.
If you have a script code like:
global DebugStatus = "Start of script code"
def function1():
# Some function definition
end
global DebugStatus = "Function 1 defined"
def function2():
# Some function definition
end
global DebugStatus = "Function 2 defined"
function1()
global DebugStatus = "Function 1 executed successfully"
Thus we are using the DebugStatus
string variable to show how far the execution of the script code has gotten.
When the variable is declared as global
it will be shown in the “Variables” tab in PolyScope.
When the code is operational, the variable can be deleted from the script program.
2) Using the logfile for debugging
The script code textmsg()
sends a string message to the logfile of the robot.
It is convenient when you have a variable, that you would like to declare and store the result of for debugging, this function can be useful.
You might have a script code like:
def function1():
socket_open("127.0.0.1", 33000, "my_socket")
var1 = socket_read_ascii_float(3, "my_socket")
textmsg("var1 read as: ", var1)
end
In the logfile and thus also the Log tab, you might now read:
YYYY-MM-DD HH:MM:SS.sss RTMachine var1 read as: [3, 1.23, 2.34, 3.45]
Hence, textmsg()
is useful for storing replies from a socket connection or a measured variable that might soon be overwritten.
Note:
Remember to remove the textmsg()
in your operational script code.
Many unnecessary writes to the log file makes it less readable and uses unnecessary disk space.