- 
                Notifications
    
You must be signed in to change notification settings  - Fork 128
 
Description
Feature summary
This feature request proposes a fundamental architectural enhancement to the Universal_Robots_Client_Library: the introduction of a modular URScript generation engine. The goal is to allow developers to safely and easily extend the robot's functionality by adding custom URScript commands without needing to fork or directly modify the core library.
Currently, external_control.urscript is a monolithic file, making any customization a complex and brittle process that complicates future library updates. By moving to a dynamic generation model, we can empower users to integrate custom hardware (grippers, sensors, etc.) and application-specific logic in a clean, maintainable, and robust manner.
Detailed Proposal: Self-Contained Command Primitives
The core of this proposal is to define a new C++ interface, let's call it ScriptCommand, which will serve as the base for all extensible commands. Each implementation of the ScriptCommand interface will be a self-contained module that provides all the necessary components for its execution:
- C++ Serialization: A method to serialize the command's parameters into a data packet that can be sent to the robot. This encapsulates the communication logic within the command itself.
 - URScript Snippets: Methods that return the specific URScript code required for the command's operation. This would include:
get_urscript_definitions(): Returns any helper functions or global variables the command needs.get_urscript_handler(): Returns theelifblock for the main command-handling loop, which decodes the parameters and executes the command logic.get_urscript_teardown(): (Optional) Returns code to be run when the program stops.
 
This concept could also be extended to Modal Motion Commands (like servoj, speedj) by creating a MotionCommand interface, evolving from the current MotionPrimitive. This interface would provide URScript snippets for a thread template (initCode, execCode, stoppingCode), ensuring that all motion commands adhere to the required safety patterns (e.g., being abortable by a control_mode change).
The Script Generation Engine
A new ScriptGenerator class would be introduced. Before program execution, it would:
- Start with a stable, hardcoded base template for 
external_control.urscript. This template would contain the core socket setup, the main control loops, and the hardcoded logic for complex, motion-integrated features liketool_contact. - Iterate through all 
ScriptCommandandMotionCommandmodules registered with theUrDriver. - Intelligently assemble the final URScript by injecting the snippets from each module into designated placeholders in the base template.
 
This approach isolates the core, safety-critical logic from user extensions, providing the best of both worlds: robustness and extensibility.
Related issues
none
Tasks
To complete this issue involves
-  Design and implement the 
ScriptCommandandMotionCommandC++ interfaces. -  Refactor existing commands (
set_payload,force_mode,servoj, etc.) to use the new modular interfaces. -  Implement the 
ScriptGeneratorclass to assemble the final URScript. -  Integrate the generator into the 
UrDriver's startup sequence. - Create comprehensive documentation for the new modular architecture and a guide on how to create and register custom command modules.
 - Develop unit tests for the script generator and the new command interfaces.
 - Create a new example program demonstrating how to add a custom command (e.g., a simple gripper control).
 - Validate the new architecture by testing on real hardware.