Skip to content

Fix forced response simulation of discrete time system #285

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 1 commit into from
Apr 7, 2019
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
10 changes: 10 additions & 0 deletions control/tests/timeresp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@ def test_forced_response(self):
42.3227, 44.9694, 47.1599, 48.9776]])
_t, yout, _xout = forced_response(self.mimo_ss1, t, u, x0)
np.testing.assert_array_almost_equal(yout, youttrue, decimal=4)

# Test discrete MIMO system to use correct convention for input
sysc = self.mimo_ss1
dt=t[1]-t[0]
sysd = c2d(sysc, dt) # discrete time system
Tc, youtc, _xoutc = forced_response(sysc, t, u, x0)
Td, youtd, _xoutd = forced_response(sysd, t, u, x0)
np.testing.assert_array_equal(Tc.shape, Td.shape)
np.testing.assert_array_equal(youtc.shape, youtd.shape)
np.testing.assert_array_almost_equal(youtc, youtd, decimal=4)

def test_lsim_double_integrator(self):
# Note: scipy.signal.lsim fails if A is not invertible
Expand Down
3 changes: 2 additions & 1 deletion control/timeresp.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ def forced_response(sys, T=None, U=0., X0=0., transpose=False):
else:
# Discrete time simulation using signal processing toolbox
dsys = (A, B, C, D, sys.dt)
tout, yout, xout = sp.signal.dlsim(dsys, U, T, X0)
# Transpose the input to match toolbox convention
tout, yout, xout = sp.signal.dlsim(dsys, np.transpose(U), T, X0)

# Transpose the output and state vectors to match local convention
xout = sp.transpose(xout)
Expand Down