Skip to content
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

signal.step not working with mimo system #9853

Open
TobiasGlaubach opened this issue Feb 20, 2019 · 2 comments
Open

signal.step not working with mimo system #9853

TobiasGlaubach opened this issue Feb 20, 2019 · 2 comments
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.signal

Comments

@TobiasGlaubach
Copy link

the step function in scipy.signal does not work when the passed system is a MIMO system with integrator.

Reproducing code example:

Consider a simple control system plant in state space form which has 2 inputs, 2 outputs and 3 states.
(Coupled electro mechanical system)

A = np.matrix([     
                [ -R_A/L_A, 0, 0 ],
                [ -K_em / m_rot, K_pm / m_rot, 0 ],
                [ 0, 1, 0 ]
            ]);

B = np.matrix([     
                [ 1/L_A, 0],
                [ 0, 1/m_rot],
                [ 0, 0 ]
            ]);

C = np.matrix([     
                [ k_im, 0, 0 ],
                [ 0, 1, k_zm ]
            ]);

D = np.matrix([     
                [ 0, 0 ],
                [ 0, 0 ]
            ]);

where all given Parameters are real numbers.

Test the dimensions by calculationg with test vectors:


u = np.matrix([     
                [ 1 ],
                [ 1 ],
            ]);
x = np.matrix([     
                [ 1 ],
                [ 1 ],
                [ 1 ],
            ]);

try:
    B @ u
    A @ x
    A @ x + B @ u
    
    C @ x
    D @ u
    C @ x + D @ u
except:
    raise

which works. Now however, when we transform the system to a lti state space system and try to use the step method:

sys = signal.StateSpace(A, B, C, D)
print(sys)
X0 = np.array([0,0,0])
T = np.linspace(0, 0.3, 10000)
t2,y2 = signal.step(sys, T=T, X0=X0)

Error message:

ValueError: System does not define that many inputs.

Traceback (most recent call last):

  File "<ipython-input-36-e3c064c647e9>", line 6, in <module>
    t2,y2 = signal.step(sys, T=T, X0=X0)

  File "C:\Users\...\AppData\Local\Continuum\anaconda3\lib\site-packages\scipy\signal\ltisys.py", line 2269, in step
    vals = lsim(sys, U, T, X0=X0, interp=False)

  File "C:\Users\...\AppData\Local\Continuum\anaconda3\lib\site-packages\scipy\signal\ltisys.py", line 1989, in lsim
    raise ValueError("System does not define that many inputs.")

ValueError: System does not define that many inputs.

Scipy/Numpy/Python version information:

1.1.0 1.15.4 sys.version_info(major=3, minor=6, micro=7, releaselevel='final', serial=0)
@ilayn ilayn added defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.signal labels Feb 20, 2019
@ilayn
Copy link
Member

ilayn commented Feb 20, 2019

Hi @TobiasGlaubach . Thanks for taking the time to report this. Currently we have a number of missing features regarding MIMO systems, off the top of my head #2862, #4675 and #4794. I'll try to see whether this can be fixed without a major surgery. In the meantime you can use python-control or harold while we fix these.

@dstuartbryant
Copy link

dstuartbryant commented Jun 25, 2020

I recently had issues getting this to work.

Code

from scipy import signal

A = np.array([[-1,-1],[6.5,0]])
B = np.array([[1,1],[1,0]])
C = np.array([[1,0],[0,1]])
D = np.array([[0,0],[0,0]])

signal.step((A,B,C,D))

Error

ValueError                                Traceback (most recent call last)
~/.../example_malfunction.py in <module>
      7 D = np.array([[0,0],[0,0]])
      8 
----> 9 signal.step((A,B,C,D))

/usr/local/lib/python3.6/site-packages/scipy/signal/ltisys.py in step(system, X0, T, N)
   2407         T = asarray(T)
   2408     U = ones(T.shape, sys.A.dtype)
-> 2409     vals = lsim(sys, U, T, X0=X0, interp=False)
   2410     return vals[0], vals[1]
   2411 

/usr/local/lib/python3.6/site-packages/scipy/signal/ltisys.py in lsim(system, U, T, X0, interp)
   2103 
   2104     if U.shape[1] != n_inputs:
-> 2105         raise ValueError("System does not define that many inputs.")
   2106 
   2107     if not interp:

ValueError: System does not define that many inputs.

Notes

It looks like the n_states = A.shape[0] (line 2054, scipy/signal/ltisys.py) value is not incorporated
in the handling of the U array.

I attempted to fix by defining U (line 2408,scipy/signal/ltisys.py) as

U = ones((T.shape[0],A.shape[0]), sys.A.dtype)

but that did not appear to be a good solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.signal
Projects
None yet
Development

No branches or pull requests

3 participants