Interpreter mode
UR Script Interpreter mode
Create Date: February 25th, 2020
SW versions: 5.10 above
Robots: e-Series only
?
Introduction
The interpreter mode enables the programmer to send and execute any valid script statement at runtime. For Interpreter Mode the controller opens an interpreter socket (30020) where it accepts complete valid URScript statements, appends them to the running program and executes in the scope of the dedicated interpreter thread. These statements become part of the running program. Interpreter mode is allowed only in the main thread.
For further details, please take a look at "Interpreter Mode" section in URScript manual.
Examples are written in python, and should be executed with python3 interpreter. Most examples take single parameter: robot IP address. Optional -v parameter prints additional information about script execution, and -d parameter shows all interpreter requests and responses.
Examples don't include synchronization between program running on the robot, and python scripts. Implementing synchronization is developer responsibility.
Code is split to common part - InterpreterHelper class - and configuration code for each example
Read URScript commands from a file
It is possible to execute multiple UR script commands inside a file through the interpreter socket . This example python script demonstrates how to read and execute the commands defined in a separate file.
Run program that enters interpreter mode:
hen execute example:
python3 sendInterpreterFromFile.py <robot_ip> commands.txt -v
After each 500 commands sent script waits until they are fully executed, and clears interpreter buffer
Using 'skipbuffer' and 'abort' commands
Interpreter mode is also capable of
- deleting the buffer of commands waiting to be executed.
- aborting the currently executed motion (NOTE: abort command limitations are explained in URScript manual).
These features make it possible to delete and redefine the actions to be taken in future. The following python script demonstrates how robot could skip from a "waving trajectory" to execute a new set of actions in an entirely different trajectory.
Run program that enters interpreter mode. Then execute example:
python3 skipbuffer.py <robot_ip> -v
Controlling IO python script
This sample aims to demonstrate how to control I/O, fieldbus, Tool-com, etc. synchronous and asynchronous with robot movements.
Run program that enters interpreter mode. Then execute example:
python3 controlio.py <robot_ip> -v
Each command is interpreted and executed.
interpreter.execute_command("set_analog_outputdomain(1, 0)") time.sleep(0.1)
Running multiple interpreter mode sessions, and sharing function definitions
You can create multiple interpreter mode calls in the main program. Program on robot should have following structure:
In this example, the robot program creates a global variable and calls two interpreter modes sequentially. After entering interpreter mode controller will await commands from interpreter socket in a blocking fashion. Then just run the following python script:
python3 two_interpreter.py <robot_ip> -v
This python script
- Creates definition for a thread and a function. Then starts just defined thread.
- Calls end_interpreter(). This will end the first interpreter_mode call without cleaning the internally defined program items.
- Lastly, commands are being executed from the second interpreter_mode() call. This time script calls previously defined function to exit the thread that was created in the first session.
- Script waits until thread terminates, and exits second interpreter mode.
Interpreter Helper class
InterpreterHelper class contains a number of methods which allow to connect to the robot and send interpreter commands.
It also contains methods for sending status commands.
Each command returns numerical response (interpreted command id, or status command response) or raises exception on error. Class is imported, and used in all examples.