Logic Program
PolyScope X applications can include a Logic Program that runs continuously in the background, independently of the main robot program. Logic Program URScript is useful for cell logic that must keep running when the arm is powered off, the main program is paused or stopped, or the operator has entered a safeguard area.
Typical uses include maintaining fieldbus communication (Modbus, Ethernet/IP, PROFINET, Socket, XmlRPC), reacting to external sensor inputs, reporting robot state to a production PLC, and controlling external equipment when the main program stops.
Logic Program cannot use functions that directly move the robot arm, change payload, or modify TCP parameters.
Program structure
A Logic Program has the same structural sections as a main program:
- Main program body — runs continuously until stopped manually, with a
haltinstruction, or by a runtime error. - Before Start — runs once when the Logic Program starts.
- Modules — functions and threads, organized the same way as in the main program. Thread functions only execute once by default; enable the loop option to run a thread continuously.
Exchanging data with the main program
The primary way to communicate between the main program and the Logic Program is through Application Variables. Application variables can be read and written from both programs and provide thread-safe data exchange.
Each program also has its own set of global variables, independent thread pool, and independent execution lifecycle. Starting, stopping, or faulting one program does not stop the other. A halt or pause instruction affects only the program in which it is executed.
Variable names must not start with the prefix _ur_. This prefix is reserved for internal constants. For compatibility with future improvements, avoid using this prefix in main program variables as well.
Logic Program supports up to approximately 300 simple variables. Exceeding this limit can stop the running program.
Reading robot state
Robot state is available through built-in RTDE output fields. Use get_rtde_value(key) to read values from the Logic Program, or use the State query methods for a higher-level interface.
Example — check whether safeguard stop is active:
safety_status = get_rtde_value("safety_status")
# check for Safeguard Stop and Automatic Mode Safeguard Stop
is_safeguard_stop_active = (safety_status == 5 or safety_status == 12)
Example — check whether the main program is paused:
is_program_paused = get_rtde_value("runtime_state") == 4
Shared communication resources
Some communication resources are shared between the main program and the Logic Program. Concurrent writes to the same resource from both programs can produce unexpected results.
Modbus — One Modbus client is shared. Signals created in either program are visible in both.
See the following:
- modbus_add_signal(IP, slave_number, signal_address, signal_type, signal_name, sequential_mode=False, register_count=1)
- modbus_add_rw_signal(IP, slave_number, read_address, read_register_count, write_address, write_register_count, signal_name, sequential_mode=False)
- modbus_delete_signal(signal_name).
Ethernet/IP flexible adapter — Each program opens its own reader or writer handle to the same instance. Handles must not write the same data fields.
See Functions.
Logic Program threads execute on the same CPU as main program threads. Heavy Logic Program thread load can contribute to a "Runtime too much behind" violation in extreme cases.
Coordinating main and Logic Program execution
When the Logic Program is an integral part of the application, use logic_program_set_watchdog(action='pause') in the main program watchdog to pause or stop the main program if the Logic Program stops running.
To control arm power, brakes, and main program lifecycle from URScript, use the Control API. The primary use case is calling Control API methods from the Logic Program to operate the main program — for example, an automatic startup sequence in remote control mode.
Limitations
- Only a subset of URScript instructions is available in the Logic Program.
- Program execution indicators and breakpoint-based debugging are not available for the Logic Program.
- Interpreter Mode is not supported in Logic Programs. Interpreter mode can still be used in the main program while a Logic Program is running.