Skip to content

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

Conversation

murrayrm
Copy link
Member

This PR fixes a problem that was identified in PR #785, where interconnecting a LinearIOSystem with a StateSpace system via the interconnect function did not work correctly. In particular, if you created a mixed system of this type you would get back an InterconnectedSystem 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 to interconnect() that convert StateSpace and TransferFunction objects to LinearIOSystems, mimicking what is done with operator overloading.

In addition, there was a bug where the param keyword was not allowed in the dynamics and output functions. This is now fixed and tested with a unit test.

@murrayrm murrayrm changed the title Interconnect type conversion 12 nov2022 Fix interconnect type conversion bug for StateSpace systems Nov 13, 2022
@coveralls
Copy link

coveralls commented Nov 13, 2022

Coverage Status

Coverage increased (+0.04%) to 94.801% when pulling a9a6226 on murrayrm:interconnect_type_conversion-12Nov2022 into beb629b on python-control:main.

Copy link
Contributor

@roryyorke roryyorke left a 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={}):
Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
x[t+dt] = f(t, x[t], u[t], params)
x[t+dt] = f(t, x[t], u[t][, params])

Copy link
Contributor

@sawyerbfuller sawyerbfuller left a 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).

@roryyorke
Copy link
Contributor

Like the for x in sequence or []: pattern. LGTM.

@sawyerbfuller sawyerbfuller merged commit b32e355 into python-control:main Nov 16, 2022
@murrayrm murrayrm added this to the 0.9.3 milestone Dec 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants