Skip to content

Commit 00962cf

Browse files
authored
Merge pull request #285 from bnavigator/timeresp-fix
Fix forced response simulation of discrete time system
2 parents e4e7a0d + 6794271 commit 00962cf

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

control/tests/timeresp_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,16 @@ def test_forced_response(self):
193193
42.3227, 44.9694, 47.1599, 48.9776]])
194194
_t, yout, _xout = forced_response(self.mimo_ss1, t, u, x0)
195195
np.testing.assert_array_almost_equal(yout, youttrue, decimal=4)
196+
197+
# Test discrete MIMO system to use correct convention for input
198+
sysc = self.mimo_ss1
199+
dt=t[1]-t[0]
200+
sysd = c2d(sysc, dt) # discrete time system
201+
Tc, youtc, _xoutc = forced_response(sysc, t, u, x0)
202+
Td, youtd, _xoutd = forced_response(sysd, t, u, x0)
203+
np.testing.assert_array_equal(Tc.shape, Td.shape)
204+
np.testing.assert_array_equal(youtc.shape, youtd.shape)
205+
np.testing.assert_array_almost_equal(youtc, youtd, decimal=4)
196206

197207
def test_lsim_double_integrator(self):
198208
# Note: scipy.signal.lsim fails if A is not invertible

control/timeresp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ def forced_response(sys, T=None, U=0., X0=0., transpose=False):
322322
else:
323323
# Discrete time simulation using signal processing toolbox
324324
dsys = (A, B, C, D, sys.dt)
325-
tout, yout, xout = sp.signal.dlsim(dsys, U, T, X0)
325+
# Transpose the input to match toolbox convention
326+
tout, yout, xout = sp.signal.dlsim(dsys, np.transpose(U), T, X0)
326327

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

0 commit comments

Comments
 (0)