Skip to content

Fix typo in ICSystem updfcn, outfcn: update_params -> _update_params #990

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions control/nlsys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions control/tests/interconnect_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import numpy as np
import scipy as sp
import math

import control as ct

Expand Down Expand Up @@ -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)
Loading