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) |
||
|---|---|---|
| examples | ||
| src | ||
| templates/krl | ||
| tests | ||
| LICENSE | ||
| MANIFEST.in | ||
| PHASE_2_SUMMARY.md | ||
| pyproject.toml | ||
| README.md | ||
| ROADMAP.md | ||
| RSI_EthernetConfig.xml | ||
| setup.py | ||
RSIPI: Robot Sensor Interface - Python Integration
RSIPI is a high-performance, Python-based communication and control system designed for real-time interfacing with KUKA robots using the Robot Sensor Interface (RSI) protocol. It provides both a robust API for developers and a powerful Command Line Interface (CLI) for researchers and engineers who need to monitor, control, and analyse robotic movements in real time.
🛡️ Safety Notice RSIPI is a powerful tool that directly interfaces with industrial robotic systems. Improper use can lead to dangerous movements, property damage, or personal injury.
⚠️ Safety Guidelines
- Test in Simulation First: Always verify your RSI communication and trajectories using simulation tools before deploying to a live robot.
- Enable Emergency Stops: Ensure all safety hardware (E-Stop, fencing, light curtains) is active and functioning correctly.
- Supervised Operation Only: Run RSIPI only in supervised environments with trained personnel present.
- Limit Movement Ranges: Use KUKA Workspaces or software limits to constrain movement, especially when testing new code.
- Use Logging for Debugging: Avoid debugging while RSI is active; instead, enable CSV logging and review logs post-run.
- Secure Network Configuration: Ensure your RSI network is on a closed, isolated interface to avoid external interference or spoofing.
- Never Rely on RSIPI for Safety: RSIPI is not a safety-rated system. Do not use it in applications where failure could result in harm.
📄 Description
RSIPI allows users to:
- Communicate with KUKA robots using the RSI XML-based protocol.
- Dynamically update control variables (TCP position, joint angles, I/O, external axes, etc.).
- Log and visualise robot movements with live graphs and static plots.
- Analyse motion data and compare planned vs actual trajectories.
- Parse and inject RSI into KRL programs.
- Simulate robot behaviour using a realistic Echo Server.
- Enforce safety limits and manage emergency stops.
Target Audience
- Researchers working on advanced robotic applications, control algorithms, and feedback systems.
- Engineers developing robotic workflows or automated processes.
- Educators using real robots in coursework or lab environments.
- Students learning about robot control systems and data-driven motion planning.
📊 Features
- Real-time network communication with KUKA RSI over UDP.
- Structured logging to CSV with British date formatting.
- Background execution and live variable updates.
- Fully-featured Python API for scripting or external integration.
- CLI for interactive control, trajectory planning, and live monitoring.
- Real-time and post-analysis graphing (live TCP, joints, force, acceleration).
- Safety management: emergency stop, limit enforcement, safety override.
- KUKA KRL
.src/.datparsing and RSI injection tools. - Echo Server and GUI for offline simulation and testing.
- Deviation and force spike alerts during live operation.
📊 API Overview (rsi_api.py)
Initialization
from src.RSIPI import rsi_api
api = rsi_api.RSIAPI(config_file='examples/RSI_EthernetConfig.xml')
Selected Methods
| Method | CLI | API | Description |
|---|---|---|---|
start_rsi() |
✅ | ✅ | Starts RSI communication (non-blocking). |
stop_rsi() |
✅ | ✅ | Stops RSI communication. |
update_variable(path, value) |
✅ | ✅ | Dynamically updates a send variable (e.g. RKorr.X). |
get_variable(path) |
✅ | ✅ | Retrieves the latest value of any variable. |
plan_linear_cartesian(start, end, steps) |
✅ | ✅ | Create Cartesian paths. |
plan_linear_joint(start, end, steps) |
✅ | ✅ | Create Joint-space paths. |
execute_trajectory(traj, rate) |
✅ | ✅ | Execute planned trajectory live. |
enable_alerts(True/False) |
✅ | ✅ | Enable or disable deviation/force alerts. |
start_live_plot(mode) |
✅ | ✅ | Live graph position, velocity, force, etc. |
generate_plot(csv, type) |
✅ | ✅ | Static graphing from CSV files. |
export_movement_data(filename) |
✅ | ✅ | Export recorded motion as CSV. |
parse_krl_to_csv(src, dat, output) |
✅ | ✅ | Extract TCP points from KRL programs. |
inject_rsi(input, output, config) |
✅ | ✅ | Add RSI startup code to a KRL file. |
(Full API details available in rsi_api.py.)
🔧 CLI Overview (rsi_cli.py)
Start the CLI:
python main.py --cli
Selected Commands
| Command | Description |
|---|---|
start / stop |
Start or stop RSI client. |
set <var> <value> |
Update send variable. |
get <var> |
Get latest receive variable. |
move_cartesian, move_joint |
Move robot using planned trajectories. |
queue_cartesian, queue_joint |
Queue trajectory steps. |
execute_queue |
Run queued trajectories. |
alerts on/off |
Enable or disable alerts. |
graph show/compare |
Plot or compare test runs. |
log start/stop/status |
Manage CSV logging. |
plot <type> <csv> |
Static plotting (position, velocity, deviation, etc.). |
safety-stop, safety-reset, safety-status |
Emergency stop and limit management. |
krlparse <src> <dat> <out> |
Parse KRL to CSV. |
inject_rsi <src> [out] [config] |
Inject RSI code into KRL file. |
📃 Example Usage
Update TCP position live
api.start_rsi()
api.update_variable('RKorr.X', 100.0)
api.update_variable('RKorr.Y', 50.0)
Plan and execute a Cartesian move
start_pose = {'X': 0, 'Y': 0, 'Z': 500}
end_pose = {'X': 200, 'Y': 0, 'Z': 500}
traj = api.plan_linear_cartesian(start_pose, end_pose, steps=100)
api.execute_trajectory(traj, rate=0.012)
CLI session sample
> start
> set RKorr.X 150
> move_cartesian X=0,Y=0,Z=500 X=200,Y=0,Z=500 steps=100 rate=0.012
> graph show my_log.csv
> log start
> stop
📅 Output and Logs
- CSV logs saved to
logs/folder. - Each log includes British timestamp, sent/received variables.
- Static plots exportable as PNG/PDF.
- Live plots include alert messages and deviation tracking.
🚀 Getting Started
- Connect robot and PC via Ethernet.
- Deploy KUKA RSI program with matching config.
- Install Python dependencies:
pip install -r requirements.txt
- Run
main.pyor importRSIAPIin your Python scripts.
🔖 Citation
If you use RSIPI in your research, please cite:
@software{rsipi2025,
author = {RSIPI Development Team},
title = {RSIPI: Robot Sensor Interface - Python Integration},
year = {2025},
url = {https://github.com/your-org/rsipi},
note = {Accessed: [insert date]}
}
⚖️ License
RSIPI is licensed under the MIT License.
🚧 Disclaimer
RSIPI is intended for research and experimental purposes only. Always ensure safe operation with appropriate safety measures in place.