Complete implementation of Python-KRL coordination features for seamless bidirectional communication between RSIPI and KUKA KRL programs. ## IOAPI Enhancements Added high-level I/O control methods for convenient digital I/O manipulation: - **set_output(channel, value, group='Digout')** - Set digital output by channel number - **get_input(channel, group='Digin')** - Read digital input by channel number - **pulse(channel, duration=0.1, group='Digout')** - Generate timed pulse on output Benefits: - Simpler channel-based addressing (channel 1 instead of 'Digout.o1') - Automatic channel name formatting - Built-in pulse generation for pneumatic actuators and signaling - Consistent error handling ## KRLAPI Enhancements Added coordination helper methods for Python-KRL synchronization: - **wait_for_signal(channel, timeout=5.0)** - Block until KRL sets I/O signal - **signal_complete(channel)** - Signal KRL that Python operation is complete - **write_param(slot, value)** - Write to Tech.C variables (Python → KRL) - **read_param(slot)** - Read from Tech.T variables (KRL → Python) Features: - Configurable timeouts with proper error handling - Flexible slot addressing (11, 'C11', 'c11' all work) - Slot validation (enforces 11-199 range) - Comprehensive logging for debugging - Clear docstrings with KRL code examples ## KRL Template Library Created comprehensive KRL templates demonstrating coordination patterns: **templates/krl/basic_handshake.src** - Simple I/O handshaking (KRL signals → Python waits → Python signals back) - Timeout handling and error recovery - Complete Python code examples in comments **templates/krl/parameter_passing.src** - Bidirectional Tech variable communication - KRL writes position to Tech.T, Python reads - Python calculates target, writes to Tech.C, KRL reads - Demonstrates full parameter exchange workflow **templates/krl/state_machine.src** - Multi-state coordination workflow - States: IDLE, CALIBRATING, READY, EXECUTING, COMPLETE, ERROR - Combines I/O signals and Tech variables - Error handling and timeout mechanisms - Demonstrates complex production-ready pattern **templates/krl/README.md** - Comprehensive coordination patterns documentation - Tech variable mapping conventions (C vs T variables) - I/O signal mapping standards - Timing best practices - Troubleshooting guide ## Python Coordination Examples Created production-ready Python examples demonstrating all coordination methods: **examples/coordination/01_basic_handshake.py** - Simple I/O handshake demonstration - Matches basic_handshake.src template - Command-line interface with argparse - Comprehensive logging and error handling **examples/coordination/02_parameter_passing.py** - Parameter exchange workflow - Reads position from KRL (Tech.T) - Calculates target position - Writes target to KRL (Tech.C) - Matches parameter_passing.src template **examples/coordination/03_state_machine.py** - Complex multi-state coordination - State monitoring loop with enum - Calibration routine with offset calculation - Error detection and signaling - Matches state_machine.src template **examples/coordination/README.md** - Complete usage instructions - Configuration requirements - Troubleshooting section - Customization examples - Advanced usage patterns ## Modified Files src/RSIPI/io_api.py: - Added time import - Implemented set_output() method - Implemented get_input() method with navigation of receive_variables - Implemented pulse() method with blocking time.sleep() - Comprehensive docstrings with examples src/RSIPI/krl_api.py: - Added time import - Implemented wait_for_signal() with configurable polling - Implemented signal_complete() method - Implemented write_param() with slot normalization and validation - Implemented read_param() with slot normalization and validation - KRL code examples in all docstrings ## New Directories templates/krl/ - 3 KRL program templates - Comprehensive README with patterns and conventions examples/coordination/ - 3 Python example scripts - Complete usage documentation ## Design Decisions **I/O Channel Numbering**: 1-based to match KUKA conventions **Tech Variable Slots**: Validated 11-199 range (KUKA reserves 1-10) **Blocking Operations**: wait_for_signal() and pulse() block with configurable timeouts **Error Handling**: Proper exceptions with clear messages **Logging**: Debug/Info/Warning levels for all operations **Documentation**: Every method includes KRL code examples ## Phase 3 Status: ✅ COMPLETE All planned features implemented: - ✅ High-level Digital I/O API - ✅ KRL state coordination helpers - ✅ Parameter passing via Tech variables - ✅ KRL code templates - ✅ Python coordination examples - ✅ Comprehensive documentation Next: Phase 4 (Advanced Motion Control)
126 lines
3.6 KiB
Plaintext
126 lines
3.6 KiB
Plaintext
&ACCESS RVP
|
|
&REL 1
|
|
&PARAM TEMPLATE = C:\KRC\Roboter\Template\vorgabe
|
|
&PARAM EDITMASK = *
|
|
DEF parameter_passing()
|
|
; ================================================================
|
|
; Parameter Passing via Tech Variables
|
|
; ================================================================
|
|
; Demonstrates bidirectional numerical data exchange between KRL
|
|
; and Python using RSI Tech variables.
|
|
;
|
|
; Tech Variable Conventions:
|
|
; - Tech.C[11-199]: Python writes, KRL reads (Control variables)
|
|
; - Tech.T[11-199]: KRL writes, Python reads (Transfer variables)
|
|
;
|
|
; Python-KRL Coordination Flow:
|
|
; 1. KRL writes current position to Tech.T
|
|
; 2. Python reads position from Tech.T
|
|
; 3. Python processes data and writes target to Tech.C
|
|
; 4. KRL reads target from Tech.C and executes motion
|
|
;
|
|
; Python Code Example:
|
|
; api = RSIAPI('RSI_EthernetConfig.xml')
|
|
; api.start()
|
|
;
|
|
; # Wait for KRL to signal data ready
|
|
; api.krl.wait_for_signal(1)
|
|
;
|
|
; # Read current position from KRL
|
|
; current_x = api.krl.read_param('T11')
|
|
; current_y = api.krl.read_param('T12')
|
|
; current_z = api.krl.read_param('T13')
|
|
;
|
|
; # Calculate target (e.g., move 100mm in X)
|
|
; target_x = current_x + 100.0
|
|
; target_y = current_y
|
|
; target_z = current_z
|
|
;
|
|
; # Write target back to KRL
|
|
; api.krl.write_param('C11', target_x)
|
|
; api.krl.write_param('C12', target_y)
|
|
; api.krl.write_param('C13', target_z)
|
|
;
|
|
; # Signal completion
|
|
; api.krl.signal_complete(1)
|
|
;
|
|
; api.stop()
|
|
; ================================================================
|
|
|
|
; Variable declarations
|
|
E6POS current_pos, target_pos
|
|
REAL target_x, target_y, target_z
|
|
INT i
|
|
BOOL data_ready
|
|
|
|
BAS(#INITMOV, 0)
|
|
|
|
; ============================================================
|
|
; STEP 1: KRL writes current position to Tech.T
|
|
; ============================================================
|
|
current_pos = $POS_ACT ; Get current TCP position
|
|
|
|
; Write position components to Transfer variables (Python reads)
|
|
$TECH.T[11] = current_pos.X
|
|
$TECH.T[12] = current_pos.Y
|
|
$TECH.T[13] = current_pos.Z
|
|
$TECH.T[14] = current_pos.A
|
|
$TECH.T[15] = current_pos.B
|
|
$TECH.T[16] = current_pos.C
|
|
|
|
; ============================================================
|
|
; STEP 2: Signal Python that data is ready
|
|
; ============================================================
|
|
$OUT[1] = TRUE
|
|
WAIT SEC 0.1
|
|
|
|
; ============================================================
|
|
; STEP 3: Wait for Python to process and write target
|
|
; ============================================================
|
|
data_ready = FALSE
|
|
i = 0
|
|
|
|
; Poll input 1 for Python completion signal
|
|
WHILE (data_ready == FALSE) AND (i < 100)
|
|
IF $IN[1] == TRUE THEN
|
|
data_ready = TRUE
|
|
ELSE
|
|
WAIT SEC 0.1
|
|
i = i + 1
|
|
ENDIF
|
|
ENDWHILE
|
|
|
|
IF data_ready == TRUE THEN
|
|
; ============================================================
|
|
; STEP 4: Read target position from Tech.C
|
|
; ============================================================
|
|
; Python has written to Control variables (KRL reads)
|
|
target_x = $TECH.C[11]
|
|
target_y = $TECH.C[12]
|
|
target_z = $TECH.C[13]
|
|
|
|
; Construct target pose
|
|
target_pos = current_pos ; Copy orientation
|
|
target_pos.X = target_x
|
|
target_pos.Y = target_y
|
|
target_pos.Z = target_z
|
|
|
|
; ============================================================
|
|
; STEP 5: Execute motion to target
|
|
; ============================================================
|
|
; Reset signals
|
|
$OUT[1] = FALSE
|
|
|
|
; Move to calculated target
|
|
LIN target_pos Vel=0.5 m/s CPDAT1 Tool[1] Base[0]
|
|
|
|
; Success indication
|
|
WAIT SEC 0.5
|
|
|
|
ELSE
|
|
; Timeout - halt for safety
|
|
HALT
|
|
ENDIF
|
|
|
|
END
|