GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Describing functions by murrayrm · Pull Request #521 · python-control/python-control Conversation
|
|
Coverage increased (+0.3%) to 88.024% when pulling 93d97cc on murrayrm:describing_functions into d75c395 on python-control:master. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…be unneccesary and to avoid a merge conbflict with python-control#521
| """Check to see if a system is single input, single output""" | ||
| return self.ninputs == 1 and self.noutputs == 1 | ||
|
|
||
| def isstatic(self): |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
statespace and xferfcn have methods is_static_gain() I added. should we choose a standard conventiuon? I would lean toward isstatic() because it is shorter and matches issiso(),
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I agree we should be uniform. I'm not sure that is_static_gain() would make sense for a nonlinear system, so that is another reason to opt for isstatic().
Also: these are mainly internally used functions, so I think it is OK to stick with isstatic/issiso rather than is_static/is_siso.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Converted to _isstatic in latest push since this really is an internal function, not intended to be seen by the user.
@sawyerbfuller: when we update is_static_gain, we can either change to _isstatic if all usage is internal or change to isstatic (and update descfcn.py for consistency).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
renamed in #524
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'll try to review from describing_function_plot on later this weekend.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| # Class for nonlinearities with a built-in describing function | ||
| class DescribingFunctionNonlinearity(): | ||
| """Base class for nonlinear functions with a describing function |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| """Base class for nonlinear functions with a describing function | |
| """Base class for nonlinear systems with a describing function |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| """Base class for nonlinear functions with a describing function | ||
|
|
||
| This class is intended to be used as a base class for nonlinear functions | ||
| that have a analytically defined describing function (accessed via the |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| that have a analytically defined describing function (accessed via the | |
| that have an analytically defined describing function (accessed via the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| # | ||
|
|
||
| """The :mod:~control.descfcn` module contains function for performing | ||
| closed loop analysis of systems with static nonlinearities using |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I find the static terminology a little confusing, especially given that some of the describing functions declared here, e.g. hysteresis, return False in their _isstatic methods. Maybe "non-linearities with frequency-independent describing functions", though that is rather long-winded.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| implement a `call` method that evaluates the nonlinearity at a given point | ||
| and an `_isstatic` method that is `True` if the nonlinearity has no | ||
| internal state. | ||
|
|
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
How about: "Subclasses should override the describing_function, __call__, and _isstatic methods."
It looks like __call__ 's inputs and outputs must be scalar, since __call__ is allowed to change instance memory, so the sequence of calls matters.
Can describing_function be called with a numpy.ndarray of amplitude values? This seems like a reasonable thing to want to do.
If I understand correctly, if __call__ updates any instance state, then _isstatic must return False -- it would be good to mention that too.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I've updated the documentation a bit to address the comments above.
In terms of calling DescribingFunctionNonlinearity.description_function with an array: the intent is that this is a low level function that just evaluates the describing function at a scalar value. The describing_function function has the code to evaluate on an array.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| """ | ||
| # If there is an analytical solution, trying using that first | ||
| if try_method and hasattr(F, 'describing_function'): |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
the hasattr check will succeed for any base class of DescribingFunctionNonlinearity - shouldn't you also catch the NotImplementedError ?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Fixed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| # | ||
|
|
||
| # Evaluate over a full range of angles | ||
| theta = np.linspace(0, 2*np.pi, num_points) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
this is not something I'm not at all sure about: should this omit the final point, so it's more like a discrete Fourier transform?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Good catch. We are approximating the integral by a discrete sum with the assumption that the function is constant on each small interval. But this means that we don't want to include the value at 2pi (since we already captured the segment just before 2pi in the previous evaluation).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| # Save the scaling factor for to make the formulas simpler | ||
| scale = dtheta / np.pi / a | ||
|
|
||
| # Evaluate the function (twice) along a sinusoid (for internal state) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I don't see how this is evaluating the function twice over the sinusoid (assume that means two periods of sinusoid).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Left over from an earlier iteration (before I implemented _isstatic). Fixed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| # | ||
| # N(A) = M_1(A) e^{j \phi_1(A)} / A | ||
| # | ||
| # To compute this, we compute F(\theta) for \theta between 0 and 2 \pi, |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| # To compute this, we compute F(\theta) for \theta between 0 and 2 \pi, | |
| # To compute this, we compute F(A\sin\theta) for \theta between 0 and 2 \pi, |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| # | ||
| # and then integrate the product against \sin\theta and \cos\theta to obtain | ||
| # | ||
| # \int_0^{2\pi} F(a\sin\theta) \sin\theta d\theta = M_1 \pi \cos\phi |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| # \int_0^{2\pi} F(a\sin\theta) \sin\theta d\theta = M_1 \pi \cos\phi | |
| # \int_0^{2\pi} F(A\sin\theta) \sin\theta d\theta = M_1 \pi \cos\phi |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| # and then integrate the product against \sin\theta and \cos\theta to obtain | ||
| # | ||
| # \int_0^{2\pi} F(a\sin\theta) \sin\theta d\theta = M_1 \pi \cos\phi | ||
| # \int_0^{2\pi} F(a\sin\theta) \cos\theta d\theta = M_1 \pi \sin\phi |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| # \int_0^{2\pi} F(a\sin\theta) \cos\theta d\theta = M_1 \pi \sin\phi | |
| # \int_0^{2\pi} F(A\sin\theta) \cos\theta d\theta = M_1 \pi \sin\phi |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Searching for the intersections will be O(m * n).
We could look libraries we can pull in to find the intersection of H(jw) and N(A). I googled "numpy polyline intersection" and found pointers to https://pypi.org/project/Shapely/, but that may be over the top.
We could also look at using scipy.optimize.root, though I don't see an obvious way to bound the domain of search. And we'd have to handle the multiple roots ourselves.
When N(A) is strictly real (saturation, deadzone, relay), we could probably specialize the solver.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| self.ub = ub | ||
|
|
||
| def __call__(self, x): | ||
| return np.maximum(self.lb, np.minimum(x, self.ub)) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| return np.maximum(self.lb, np.minimum(x, self.ub)) | |
| return np.clip(x, self.lb, self.ub) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| def nyquist_plot(syslist, omega=None, plot=True, label_freq=0, | ||
| arrowhead_length=0.1, arrowhead_width=0.1, | ||
| color=None, *args, **kwargs): | ||
| mirror='--', color=None, *args, **kwargs): |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This new argument should be documented. Are we going to allow None for no mirror? Below you checked for False.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Updated documentation. Should either be a linestyle or False if you don't want to plot the mirror image at all. Setting it to (explicitly) to None will generate an error (from matplotlib).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if self.lb <= A and A <= self.ub: | ||
| return 1. | ||
| else: | ||
| alpha, beta = math.asin(self.ub/A), math.asin(-self.lb/A) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
FWIW, the expression in Slotine & Li, and also https://ocw.mit.edu/courses/aeronautics-and-astronautics/16-30-estimation-and-control-of-aerospace-systems-spring-2004/readings/gelb_ch2_ocr.pdf and https://ocw.mit.edu/resources/res-6-010-electronic-feedback-systems-spring-2013/textbook/MITRES_6-010S13_chap06.pdf are different to what you have here, but they may be equivalent. All these references restrict themselves to saturation with odd symmetry, though.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It's equivalent (I checked, but also the unit tests check this).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| # Backlash nonlinearity (#48 in Gelb and Vander Velde, 1968) | ||
| class backlash_nonlinearity(DescribingFunctionNonlinearity): | ||
| """Backlash nonlinearity for use in describing function analysis |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Friction-controlled backlash? (https://ocw.mit.edu/courses/aeronautics-and-astronautics/16-30-estimation-and-control-of-aerospace-systems-spring-2004/readings/gelb_ch2_ocr.pdf p. 68?)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I saw that, but couldn't figure out what the "friction-controlled" had to do with it exactly. It seemed to me that you just had backlash as in a gear and so the output just followed the input (modulo the backlash action).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's not important, but I remember a colleague always talking about the two backlash types (friction-controlled and inertia-controlled), and I thought it was standard nomenclature. The inertia-controlled case is discussed in the reference above immediately after friction-controlled.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I was looking at something different (probably just the table in Appendix B, which didn't have the explanation). I'll update.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| # Convert input to an array | ||
| x_array = np.array(x) | ||
|
|
||
| y = [] |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
there's an inconsistency here: you've allowed a vector input for this __call__, but not the others.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
|
|
||
| # Static function via a class | ||
| class saturation_class(): |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| class saturation_class(): | |
| class saturation_class: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| np.testing.assert_array_equal(satsys([0.]), [0.]) | ||
|
|
||
| # Test SIMO nonlinearity | ||
| def _simofcn(t, x, u, params={}): |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| def _simofcn(t, x, u, params={}): | |
| def _simofcn(t, x, u, params): |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return np.array([np.sin(u[0]) * np.cos(u[1])]) | ||
| miso_sys = ct.NonlinearIOSystem(None, outfcn=_misofcn, input=2, output=1) | ||
| np.testing.assert_array_equal(miso_sys([0, 0]), [0]) | ||
| np.testing.assert_array_equal(miso_sys([0, 0]), [0]) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| np.testing.assert_array_equal(miso_sys([0, 0]), [0]) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
|
|
||
| # Test saturation describing function in multiple ways | ||
| def test_saturation_describing_function(satsys): |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think you mean to test with the function saturation here, but this tests saturation_class twice.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| linear system and a static nonlinearity, it is possible to obtain a | ||
| generalization of Nyquist's stability criterion based on the idea of | ||
| describing functions. The basic concept involves approximating the | ||
| response of a static nonlinearity to an input :math:`u = A e^{\omega |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
e^{j\omega t} ?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
aba5b43 to
f5bca43
Compare
f5bca43 to
93d97cc
Compare
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.