Repository navigation
sisotool small visual cleanup, new feature to show step response of different input-output than loop #531
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
sisotool small visual cleanup, new feature to show step response of different input-output than loop #531
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
26a595f
bdalg.connect now works with scalar inputv and outputv
sawyerbfuller 9b10121
sisotool's step response plot can be something other than feedback(K*…
sawyerbfuller 76b0507
relaxed fiddly click size threshold in rlocus
sawyerbfuller 77bc5c5
fixed that full 2x2 system wasn't being passed around correctly, givi…
sawyerbfuller 03cdab7
added the unit tests, which caught a bug : ) and docstring cleanup
sawyerbfuller fc8f8d7
improved test coverage, pep8 cleanup, doc clarification, removed comp…
sawyerbfuller abca69d
improved tvect test coverage
sawyerbfuller File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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 |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| """sisotool_test.py""" | ||
|
|
||
| from control.exception import ControlMIMONotImplemented | ||
| import matplotlib.pyplot as plt | ||
| import numpy as np | ||
| from numpy.testing import assert_array_almost_equal | ||
|
|
@@ -8,6 +9,7 @@ | |
| from control.sisotool import sisotool | ||
| from control.rlocus import _RLClickDispatcher | ||
| from control.xferfcn import TransferFunction | ||
| from control.statesp import StateSpace | ||
|
|
||
|
|
||
| @pytest.mark.usefixtures("mplcleanup") | ||
|
|
@@ -19,15 +21,44 @@ def sys(self): | |
| """Return a generic SISO transfer function""" | ||
| return TransferFunction([1000], [1, 25, 100, 0]) | ||
|
|
||
| def test_sisotool(self, sys): | ||
| @pytest.fixture | ||
| def sysdt(self): | ||
| """Return a generic SISO transfer function""" | ||
| return TransferFunction([1000], [1, 25, 100, 0], True) | ||
|
|
||
| @pytest.fixture | ||
| def sys222(self): | ||
| """2-states square system (2 inputs x 2 outputs)""" | ||
| A222 = [[4., 1.], | ||
| [2., -3]] | ||
| B222 = [[5., 2.], | ||
| [-3., -3.]] | ||
| C222 = [[2., -4], | ||
| [0., 1.]] | ||
| D222 = [[3., 2.], | ||
| [1., -1.]] | ||
| return StateSpace(A222, B222, C222, D222) | ||
|
|
||
| @pytest.fixture | ||
| def sys221(self): | ||
| """2-states, 2 inputs x 1 output""" | ||
| A222 = [[4., 1.], | ||
| [2., -3]] | ||
| B222 = [[5., 2.], | ||
| [-3., -3.]] | ||
| C221 = [[0., 1.]] | ||
| D221 = [[1., -1.]] | ||
| return StateSpace(A222, B222, C221, D221) | ||
|
|
||
| def test_sisotool(self, sys, sysdt, sys222, sys221): | ||
| sisotool(sys, Hz=False) | ||
| fig = plt.gcf() | ||
| ax_mag, ax_rlocus, ax_phase, ax_step = fig.axes[:4] | ||
|
|
||
| # Check the initial root locus plot points | ||
| initial_point_0 = (np.array([-22.53155977]), np.array([0.])) | ||
| initial_point_1 = (np.array([-1.23422011]), np.array([-6.54667031])) | ||
| initial_point_2 = (np.array([-1.23422011]), np.array([06.54667031])) | ||
| initial_point_2 = (np.array([-1.23422011]), np.array([6.54667031])) | ||
| assert_array_almost_equal(ax_rlocus.lines[0].get_data(), | ||
| initial_point_0, 4) | ||
| assert_array_almost_equal(ax_rlocus.lines[1].get_data(), | ||
|
|
@@ -88,7 +119,21 @@ def test_sisotool(self, sys): | |
| step_response_moved = np.array( | ||
| [0., 0.0072, 0.0516, 0.1554, 0.3281, 0.5681, 0.8646, 1.1987, | ||
| 1.5452, 1.875]) | ||
| # old: array([0., 0.0239, 0.161 , 0.4547, 0.8903, 1.407, | ||
| # 1.9121, 2.2989, 2.4686, 2.353]) | ||
| assert_array_almost_equal( | ||
| ax_step.lines[0].get_data()[1][:10], step_response_moved, 4) | ||
|
|
||
| # test supply tvect | ||
| sisotool(sys, tvect=np.arange(0, 1, .1)) | ||
|
|
||
| # test discrete-time | ||
| sisotool(sysdt, tvect=5) | ||
|
|
||
| # test MIMO compatibility | ||
| # sys must be siso or 2 input, 2 output | ||
| with pytest.raises(ControlMIMONotImplemented): | ||
| sisotool(sys221) | ||
| # does not raise an error: | ||
| sisotool(sys222) | ||
|
|
||
|
Comment on lines
+124
to
+165
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would move these to separate tests.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, thanks for the suggestions. still getting the hang of best practices for testing |
||
|
|
||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still does not cover https://coveralls.io/builds/36911686/source?filename=control%2Fsisotool.py#L168
tvectis not passed through to_SisotoolUpdateThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's see if that works