-
Notifications
You must be signed in to change notification settings - Fork 442
Closed
Labels
Description
It seems that t_eval
is ignored when simulating a system with nstates=0
.
The bug seems to be located at:
python-control/control/iosys.py
Lines 1767 to 1777 in 3b5f199
if nstates == 0: | |
# No states => map input to output | |
u = U[0] if len(U.shape) == 1 else U[:, 0] | |
y = np.zeros((np.shape(sys._out(T[0], X0, u))[0], len(T))) | |
for i in range(len(T)): | |
u = U[i] if len(U.shape) == 1 else U[:, i] | |
y[:, i] = sys._out(T[i], [], u) | |
return TimeResponseData( | |
T, y, None, U, issiso=sys.issiso(), | |
output_labels=sys.output_index, input_labels=sys.input_index, | |
transpose=transpose, return_x=return_x, squeeze=squeeze) |
Instead, the following lines are expected to be used, I think:
python-control/control/iosys.py
Lines 1798 to 1825 in 3b5f199
def ufun(t): | |
# Find the value of the index using linear interpolation | |
# Use clip to allow for extrapolation if t is out of range | |
idx = np.clip(np.searchsorted(T, t, side='left'), 1, len(T)-1) | |
dt = (t - T[idx-1]) / (T[idx] - T[idx-1]) | |
return U[..., idx-1] * (1. - dt) + U[..., idx] * dt | |
# Check to make sure this is not a static function | |
if nstates == 0: # No states => map input to output | |
# Make sure the user gave a time vector for evaluation (or 'T') | |
if t_eval is None: | |
# User overrode t_eval with None, but didn't give us the times... | |
warn("t_eval set to None, but no dynamics; using T instead") | |
t_eval = T | |
# Allocate space for the inputs and outputs | |
u = np.zeros((ninputs, len(t_eval))) | |
y = np.zeros((noutputs, len(t_eval))) | |
# Compute the input and output at each point in time | |
for i, t in enumerate(t_eval): | |
u[:, i] = ufun(t) | |
y[:, i] = sys._out(t, [], u[:, i]) | |
return TimeResponseData( | |
t_eval, y, None, u, issiso=sys.issiso(), | |
output_labels=sys.output_index, input_labels=sys.input_index, | |
transpose=transpose, return_x=return_x, squeeze=squeeze) |