Simulink error: Time-Varying State Space block

조회 수: 4(최근 30일)
John
John 2023년 3월 18일
댓글: John 2023년 3월 22일
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.

채택된 답변

Sam Chak
Sam Chak 2023년 3월 18일
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
John
John 2023년 3월 22일
@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 :)

댓글을 달려면 로그인하십시오.

추가 답변(1개)

Paul
Paul 2023년 3월 18일
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
John
John 2023년 3월 22일
That's very helpful; thanks @Paul.

댓글을 달려면 로그인하십시오.

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by