diff --git a/control/nlsys.py b/control/nlsys.py index c154c0818..38efea355 100644 --- a/control/nlsys.py +++ b/control/nlsys.py @@ -706,10 +706,10 @@ def __init__(self, syslist, connections=None, inplist=None, outlist=None, # Create updfcn and outfcn def updfcn(t, x, u, params): - self.update_params(params) + self._update_params(params) return self._rhs(t, x, u) def outfcn(t, x, u, params): - self.update_params(params) + self._update_params(params) return self._out(t, x, u) # Initialize NonlinearIOSystem object diff --git a/control/tests/interconnect_test.py b/control/tests/interconnect_test.py index 285e9d096..f4b0c59a8 100644 --- a/control/tests/interconnect_test.py +++ b/control/tests/interconnect_test.py @@ -16,6 +16,7 @@ import numpy as np import scipy as sp +import math import control as ct @@ -659,3 +660,32 @@ def test_interconnect_rewrite(): outputs=['y', 'z']) assert icsys.input_labels == ['u[0]', 'u[1]', 'w[0]', 'w[1]'] + + +def test_interconnect_params(): + # Create a nominally unstable system + sys1 = ct.nlsys( + lambda t, x, u, params: params['a'] * x[0] + u[0], + states=1, inputs='u', outputs='y', params={'a': 1}) + + # Simple system for serial interconnection + sys2 = ct.nlsys( + None, lambda t, x, u, params: u[0], + inputs='r', outputs='u') + + # Create a series interconnection + sys = ct.interconnect([sys1, sys2], inputs='r', outputs='y') + + # Make sure we can call the update function + sys.updfcn(0, [0], [0], {}) + + # Make sure the serial interconnection is unstable to start + assert sys.linearize([0], [0]).poles()[0].real == 1 + + # Change the parameter and make sure it takes + assert sys.linearize([0], [0], params={'a': -1}).poles()[0].real == -1 + + # Now try running a simulation + timepts = np.linspace(0, 10) + resp = ct.input_output_response(sys, timepts, 0, params={'a': -1}) + assert resp.states[0, -1].item() < 2 * math.exp(-10)