Skip to content

Commit 43ce56b

Browse files
committed
fix params processing in I/O system + unit tests
1 parent 45c3abd commit 43ce56b

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

‎control/iosys.py‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def _update_params(self, params, warning=False):
357357
if warning:
358358
warn("Parameters passed to InputOutputSystem ignored.")
359359

360-
def _rhs(self, t, x, u, params={}):
360+
def _rhs(self, t, x, u):
361361
"""Evaluate right hand side of a differential or difference equation.
362362
363363
Private function used to compute the right hand side of an
@@ -369,7 +369,7 @@ def _rhs(self, t, x, u, params={}):
369369
NotImplemented("Evaluation not implemented for system of type ",
370370
type(self))
371371

372-
def dynamics(self, t, x, u):
372+
def dynamics(self, t, x, u, params={}):
373373
"""Compute the dynamics of a differential or difference equation.
374374
375375
Given time `t`, input `u` and state `x`, returns the value of the
@@ -400,9 +400,10 @@ def dynamics(self, t, x, u):
400400
-------
401401
dx/dt or x[t+dt] : ndarray
402402
"""
403+
self._update_params(params)
403404
return self._rhs(t, x, u)
404405

405-
def _out(self, t, x, u, params={}):
406+
def _out(self, t, x, u):
406407
"""Evaluate the output of a system at a given state, input, and time
407408
408409
Private function used to compute the output of of an input/output
@@ -414,7 +415,7 @@ def _out(self, t, x, u, params={}):
414415
# If no output function was defined in subclass, return state
415416
return x
416417

417-
def output(self, t, x, u):
418+
def output(self, t, x, u, params={}):
418419
"""Compute the output of the system
419420
420421
Given time `t`, input `u` and state `x`, returns the output of the
@@ -437,6 +438,7 @@ def output(self, t, x, u):
437438
-------
438439
y : ndarray
439440
"""
441+
self._update_params(params)
440442
return self._out(t, x, u)
441443

442444
def feedback(self, other=1, sign=-1, params={}):
@@ -2248,7 +2250,7 @@ def ss(*args, **kwargs):
22482250
Convert a linear system into space system form. Always creates a
22492251
new system, even if sys is already a state space system.
22502252
2251-
``ss(updfcn, outfucn)``
2253+
``ss(updfcn, outfcn)``
22522254
Create a nonlinear input/output system with update function ``updfcn``
22532255
and output function ``outfcn``. See :class:`NonlinearIOSystem` for
22542256
more information.

‎control/tests/type_conversion_test.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ def sys_dict():
1919
sdict['frd'] = ct.frd([10+0j, 9 + 1j, 8 + 2j, 7 + 3j], [1, 2, 3, 4])
2020
sdict['lio'] = ct.LinearIOSystem(ct.ss([[-1]], [[5]], [[5]], [[0]]))
2121
sdict['ios'] = ct.NonlinearIOSystem(
22-
sdict['lio']._rhs, sdict['lio']._out, inputs=1, outputs=1, states=1)
22+
lambda t, x, u, params: sdict['lio']._rhs(t, x, u),
23+
lambda t, x, u, params: sdict['lio']._out(t, x, u),
24+
inputs=1, outputs=1, states=1)
2325
sdict['arr'] = np.array([[2.0]])
2426
sdict['flt'] = 3.
2527
return sdict
@@ -226,4 +228,12 @@ def test_interconnect(
226228
result = ct.interconnect(syslist, connections, inplist, outlist)
227229
else:
228230
result = ct.interconnect(syslist, connections, inplist, outlist)
231+
232+
# Make sure the type is correct
229233
assert isinstance(result, type_dict[expected])
234+
235+
# Make sure we can evaluate the dynamics
236+
np.testing.assert_equal(
237+
result.dynamics(
238+
0, np.zeros(result.nstates), np.zeros(result.ninputs)),
239+
np.zeros(result.nstates))

0 commit comments

Comments
 (0)