Simulink error: Time-Varying State Space block

27 visualizaciones (últimos 30 días)
John
John el 18 de Mzo. de 2023
Comentada: John el 22 de Mzo. de 2023
I have a Simulink error I can't figure out, relating to the Time-Varying State Space block dimensions.
I'm using this block so that i can also get x : normal SS block doesn't output x.
This is a simple 2x2 system, and the system dimensions are correct, but I'm getting a port dims error -- it seems to be Output Port 2 (the length-2 "x" output). It could be any system, i happen to have a closed-loop state space, but anything triggers the same error.
Any thoughts why?
I've spent way too much time trying to figure out what's going on...
SL model attached, and Runnable code below.
Error:
Matrix multiply dimensions propagation error. Error occurred while setting output port of 'LQR_post/Varying State Space/Product1' to have the dimensions [1 x 2]. A possible cause for this error is that these dimensions do not agree with the partial dimensions information present on other ports
Component:Simulink | Category:Model error
Error in port widths or dimensions. 'Input Port 2' of 'LQR_post/Varying State Space/Sum' is a [1x2] matrix.
Component:Simulink | Category:Model error
Code:
J = 1e-5;
b = 0.0016;
k = 0.632;
A = [0, 1; -k / J, -b / J];
B = [0; 1 / J];
C = [1 0];
D = [0];
sys = ss(A, B, C, D, ...
'StateName', {'x', 'x dot'}, ...
'InputName', {'r(ref)'}, ...
'OutputName', {'theta'});
Q = [1000 0 ; 0 0.001];
R = [ 0.01 ];
[K_lqr, S1, P1] = lqr(sys, Q, R);
sys_lqr = ss(sys.A - sys.B * K_lqr, sys.B * K_lqr * [1;0], sys.C, sys.D);
sys_lqr.StateName = {'theta', 'angVel'};
sys_lqr.InputName = {'r(ref)'};
sys_lqr.OutputName = {'theta'};
sys_lqr
sys_lqr = A = theta angVel theta 0 1 angVel -3.162e+07 -3.261e+04 B = r(ref) theta 0 angVel 3.156e+07 C = theta angVel theta 1 0 D = r(ref) theta 0 Continuous-time state-space model.

Respuesta aceptada

Sam Chak
Sam Chak el 18 de Mzo. de 2023
If you want to get the state vector x, then you can consider this approach because the output vector y can be constructed from the state vector info. In your case, .
J = 1e-5;
b = 0.0016;
k = 0.632;
A = [0, 1; -k/J, -b/J];
B = [0; 1/J];
C = eye(2); % Change the Output Matrix to an Identity Matrix
D = [0; 0];
Q = [1000 0; 0 0.001];
R = [0.01];
K = lqr(A, B, Q, R)
K = 1×2
315.5964 0.3245
  3 comentarios
Sam Chak
Sam Chak el 22 de Mzo. de 2023
Hi John,
The Varying State Space block is actually a Block Mask. If you look under mask, you will see the fundamental blocks of the State-Space. It is important to understand how the matrices work in the State-Space.
By default, the option "Interpret vector parameters as 1-D" in the Constant Block is checked. Because we want the Constant block to treat that specified vector as a matrix, this option must be unchecked.
John
John el 22 de Mzo. de 2023
@Sam Chak, ah, thanks. That clarifies. So the output is x (assuming D = 0) as long as C = I. So fundamentally, the State Space block has x available for the output. Thanks :)

Iniciar sesión para comentar.

Más respuestas (1)

Paul
Paul el 18 de Mzo. de 2023
Hi John,
In the Constant blocks for sys_lqr.B and sys_lqr.C try clearing the block parameter "Interpret vector parameters as 1-D — Treat vectors as 1-D"
  5 comentarios
Paul
Paul el 21 de Mzo. de 2023
The error messages talk about a [1x2] matrix. For what Simulink calls 1D signals Simulink tries to infer dimensions. For example, those 1D signals indicated with a "2" on the signal line could be interpreted as either 1x2 or 2x1 and Simulink tries to figure that out. I thought it likely there was an issue with Simulink not being able to figure out which. By unchecking that box you take away that flexibility and it makes it easier for Simulink to figure out what's what. One tradeoff is matrix signals get logged as 3D, as discussed in your other question.
John
John el 22 de Mzo. de 2023
That's very helpful; thanks @Paul.

Iniciar sesión para comentar.

Productos


Versión

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by