- Notifications
You must be signed in to change notification settings - Fork445
Add Interactive Root Locus GUI with High-Resolution Catmull-Rom Interpolation#1175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
AndrewTrepagnier wants to merge6 commits intopython-control:mainChoose a base branch fromAndrewTrepagnier:main
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Open
Changes fromall commits
Commits
Show all changes
6 commits Select commitHold shift + click to select a range
5bc3c85 Add interactive root locus GUI with hover functionality
AndrewTrepagnier0d82245 feat: Add interactive root locus GUI with smooth cursor marker
AndrewTrepagnier09954e3 cleaned up comments
AndrewTrepagnier172d2b5 feat: Add high-resolution Catmull-Rom interpolation for ultra-smooth …
AndrewTrepagnier8f53286 precomputed lookup tables for fine resolution
AndrewTrepagnier2c95f00 refactor: Move test script to examples directory for proper package s…
AndrewTrepagnierFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
8 changes: 8 additions & 0 deletionscontrol/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletionscontrol/interactive/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| # Interactive Plotting Tools | ||
| This module provides interactive plotting capabilities for the Python Control Systems Library. | ||
| ## Root Locus GUI | ||
| The `root_locus_gui` function creates an interactive root locus plot with hover functionality. | ||
| ### Features | ||
| - **Hover Information**: Hover over the root locus to see gain, damping ratio, and frequency | ||
| - **Original Plot Style**: Uses the same visual style as the original matplotlib root locus plots | ||
| - **Interactive Info Box**: Small info box in the corner shows real-time information | ||
| - **Cursor Marker**: Green dot follows your mouse to show exactly where you are on the root locus | ||
| - **Poles and Zeros**: Visual display of open-loop poles and zeros | ||
| - **Customizable**: Various options for display and interaction | ||
| ### Basic Usage | ||
| ```python | ||
| import control as ct | ||
| # Create a system | ||
| s = ct.tf('s') | ||
| sys = 1 / (s**2 + 2*s + 1) | ||
| # Create interactive root locus plot | ||
| gui = ct.root_locus_gui(sys) | ||
| gui.show() | ||
| ``` | ||
| ### Advanced Usage | ||
| ```python | ||
| # Customize the plot | ||
| gui = ct.root_locus_gui( | ||
| sys, | ||
| title="My Root Locus", | ||
| show_grid_lines=True, | ||
| damping_lines=True, | ||
| frequency_lines=True | ||
| ) | ||
| gui.show() | ||
| ``` | ||
| ### Parameters | ||
| - `sys`: LTI system (SISO only) | ||
| - `gains`: Custom gain range (optional) | ||
| - `xlim`, `ylim`: Axis limits (optional) | ||
| - `grid`: Show s-plane grid (default: True) | ||
| - `show_poles_zeros`: Show poles and zeros (default: True) | ||
| - `show_grid_lines`: Show grid lines (default: True) | ||
| - `damping_lines`: Show damping ratio lines (default: True) | ||
| - `frequency_lines`: Show frequency lines (default: True) | ||
| - `title`: Plot title | ||
| ### Hover Information | ||
| When you hover over the root locus, you can see: | ||
| - **Gain**: The current gain value | ||
| - **Pole**: The pole location in the s-plane | ||
| - **Damping**: Damping ratio (for complex poles) | ||
| - **Frequency**: Natural frequency (for complex poles) | ||
| A green dot marker will appear on the root locus curve to show exactly where your cursor is positioned. | ||
| ### Installation | ||
| The interactive tools require matplotlib: | ||
| ```bash | ||
| pip install matplotlib | ||
| ``` | ||
| ### Examples | ||
| See the `examples/` directory for more detailed examples: | ||
| - `simple_rlocus_gui_example.py`: Basic usage | ||
| ### Comparison with MATLAB | ||
| This GUI provides similar functionality to MATLAB's root locus tool: | ||
| | Feature | MATLAB | Python Control | | ||
| |---------|--------|----------------| | ||
| | Hover information | ✓ | ✓ | | ||
| | Grid lines | ✓ | ✓ | | ||
| | Poles/zeros display | ✓ | ✓ | | ||
| | Custom gain ranges | ✓ | ✓ | | ||
| | Desktop application | ✓ | ✓ | | ||
| | Jupyter integration | ✗ | ✓ | | ||
| | Cursor marker | ✗ | ✓ | | ||
| ### Comparison with Existing Functionality | ||
| The python-control library already has some interactive features: |
30 changes: 30 additions & 0 deletionscontrol/interactive/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| """ | ||
| Interactive plotting tools for the Python Control Systems Library. | ||
| This module provides interactive plotting capabilities including root locus | ||
| analysis with hover functionality. | ||
| """ | ||
| try: | ||
| from .rlocus_gui import root_locus_gui, rlocus_gui, root_locus_gui_advanced | ||
| __all__ = ['root_locus_gui', 'rlocus_gui', 'root_locus_gui_advanced'] | ||
| except ImportError as e: | ||
| def root_locus_gui(*args, **kwargs): | ||
| raise ImportError( | ||
| f"root_locus_gui could not be imported: {e}. " | ||
| "Make sure matplotlib is installed: pip install matplotlib" | ||
| ) | ||
| def rlocus_gui(*args, **kwargs): | ||
| raise ImportError( | ||
| f"rlocus_gui could not be imported: {e}. " | ||
| "Make sure matplotlib is installed: pip install matplotlib" | ||
| ) | ||
| def root_locus_gui_advanced(*args, **kwargs): | ||
| raise ImportError( | ||
| f"root_locus_gui_advanced could not be imported: {e}. " | ||
| "Make sure matplotlib is installed: pip install matplotlib" | ||
| ) | ||
| __all__ = ['root_locus_gui', 'rlocus_gui', 'root_locus_gui_advanced'] |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.