-
Notifications
You must be signed in to change notification settings - Fork 438
Fix interconnect type conversion bug for StateSpace systems #788
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
Fix interconnect type conversion bug for StateSpace systems #788
Conversation
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.
LGTM, except for the one comment.
control/iosys.py
Outdated
@@ -369,23 +369,24 @@ def _rhs(self, t, x, u, params={}): | |||
NotImplemented("Evaluation not implemented for system of type ", | |||
type(self)) | |||
|
|||
def dynamics(self, t, x, u): | |||
def dynamics(self, t, x, u, params={}): |
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.
Is there a reason not to use the params=None
, if params is None: params={}
pattern here? Using mutable objects for default parameters is usually not a good idea.
Also, why not **kwargs?
control/iosys.py
Outdated
"""Compute the dynamics of a differential or difference equation. | ||
|
||
Given time `t`, input `u` and state `x`, returns the value of the | ||
right hand side of the dynamical system. If the system is continuous, | ||
returns the time derivative | ||
|
||
dx/dt = f(t, x, u) | ||
dx/dt = f(t, x, u, params) |
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.
dx/dt = f(t, x, u, params) | |
dx/dt = f(t, x, u[, params]) |
control/iosys.py
Outdated
|
||
where `f` is the system's (possibly nonlinear) dynamics function. | ||
If the system is discrete-time, returns the next value of `x`: | ||
|
||
x[t+dt] = f(t, x[t], u[t]) | ||
x[t+dt] = f(t, x[t], u[t], params) |
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.
x[t+dt] = f(t, x[t], u[t], params) | |
x[t+dt] = f(t, x[t], u[t][, params]) |
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.
One other thought: currently, StateSpace.dynamics
does not have params
as a kwarg, but it probably should (maybe with a warning that it will be ignored).
Like the |
This PR fixes a problem that was identified in PR #785, where interconnecting a
LinearIOSystem
with aStateSpace
system via theinterconnect
function did not work correctly. In particular, if you created a mixed system of this type you would get back anInterconnectedSystem
that would generate an error is you tried to simulate it or evaluate the dynamics. This was fixed by adding a few lines of code tointerconnect()
that convertStateSpace
andTransferFunction
objects toLinearIOSystems
, mimicking what is done with operator overloading.In addition, there was a bug where the
param
keyword was not allowed in thedynamics
andoutput
functions. This is now fixed and tested with a unit test.