unable to create state space observer

조회 수: 3 (최근 30일)
Abdul Hamzah
Abdul Hamzah 2024년 10월 13일
댓글: Umar 2024년 10월 14일
Hello everyone, I am trying to make a state-space observer using this code :
% Parameters of the system
M = 1.0; % Mass of the cart
m = 0.1; % Mass of the pendulum
g = 9.81; % Gravitational constant
l = 0.6; % Length of the pendulum
%for state-space block on top
A_ = [0 1 0 0;
0 0 -(m*g)/(M - m) 0;
0 0 0 1;
0 0 (g*M)/(l*(M - m)) 0];
B_ = [0;
1/(M - m);
0;
-1/(l*(M - m))];
C_ = eye(4); % Identity matrix as all states can be observed
D_ = [0;0;0;0]; % No direct feedthrough
sys2=ss(A_,B_,C_,D_)
%sys_ctrl = compreal(sys2,"c");
%A_ctrl = sys_ctrl.A
%B_ctrl = sys_ctrl.B
%C_ctrl = sys_ctrl.C
%D_ctrl = sys_ctrl.D
p= [-2 -2.5 -3 -3.5];
K=place(A_,B_,p)
pol= eig(A_-B_*K)
op = [-5 -6 -7 -8];
%op = [-1;-1;-1;-1];
L_mat=place(A_',C_',op)'
%for state-space block on bottom
A_new = A-L_mat*C_;
B_new = [B,L_mat];
C_new=eye(4);
D_new = 0;
sys3=ss(A_new,B_new,C_new,D_new)
and I connect it to this model :
but somehow I am only able to produce this graph:
Do you know what is actually wrong with my code?? any response and help is really appreciated..
  댓글 수: 2
Umar
Umar 2024년 10월 13일

Hi @Abdul Hamzah,

After going through your comments,the code you provided for implementing a state-space observer appears to be fundamentally sound; however, there are a few areas to check that may be causing the unexpected output graph.

Observer Gain Matrix (L_mat): Ensure that the poles specified in the op variable are appropriate for your system dynamics. If the poles are too far from the origin, the observer may not converge properly.

State-Space Representation: Verify that the matrices A_new, B_new, C_new, and D_new are correctly defined. The observer's dynamics should be stable, and the dimensions of these matrices must align with the state-space model.

Simulink Model Configuration: Check the configuration of your Simulink model. Ensure that the input signals are correctly connected and that the simulation parameters (like time step and solver) are set appropriately.

Initial Conditions: If the initial conditions for the states are not set correctly, it may lead to unexpected behavior in the output.

Graph Settings: Lastly, ensure that the graph settings in Simulink are configured to display the desired outputs. Sometimes, the wrong signals may be plotted.

By addressing these points, you should be able to identify the issue and achieve the expected results from your state-space observer.

If problems persist, consider simplifying the model to isolate the issue further.

Hope this helps.

Sam Chak
Sam Chak 2024년 10월 14일
Have you also observed that all states of the system are fully measurable, as indicated by the output matrix being an identity matrix? The linear system is controllable with a full-state feedback controller, which the OP (@Abdul Hamzah) designed using pole placement.
However, it is unclear which 4th-order system formula the OP used to "mathematically calculate" such closed-loop poles, resulting in the low-mass pendulum bob settling at around 4 seconds, which is deemed unrealistic.
% Parameters of the system
M = 1.0; % Mass of the cart
m = 0.1; % Mass of the pendulum
g = 9.81; % Gravitational constant
l = 0.6; % Length of the pendulum
%for state-space block on top
A = [0 1 0 0;
0 0 -(m*g)/(M - m) 0;
0 0 0 1;
0 0 (g*M)/(l*(M - m)) 0];
B = [0;
1/(M - m);
0;
-1/(l*(M - m))];
C = eye(4); % Identity matrix as all states can be observed
D = [0;0;0;0]; % No direct feedthrough
%% Desired closed-loop poles
p = [-2 -2.5 -3 -3.5];
%% Pole placement design of control gain matrix
K = place(A, B, p)
K = 1×4
-2.8899 -4.3899 -35.7089 -8.5739
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
%% Closed-loop system
sys = ss(A-B*K, B, C, D);
step(sys), grid on

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

답변 (1개)

Umar
Umar 2024년 10월 13일

Hi @Abdul Hamzah,

After going through your comments,the code you provided for implementing a state-space observer appears to be fundamentally sound; however, there are a few areas to check that may be causing the unexpected output graph.

Observer Gain Matrix (L_mat): Ensure that the poles specified in the op variable are appropriate for your system dynamics. If the poles are too far from the origin, the observer may not converge properly.

State-Space Representation: Verify that the matrices A_new, B_new, C_new, and D_new are correctly defined. The observer's dynamics should be stable, and the dimensions of these matrices must align with the state-space model.

Simulink Model Configuration: Check the configuration of your Simulink model. Ensure that the input signals are correctly connected and that the simulation parameters (like time step and solver) are set appropriately.

Initial Conditions: If the initial conditions for the states are not set correctly, it may lead to unexpected behavior in the output.

Graph Settings: Lastly, ensure that the graph settings in Simulink are configured to display the desired outputs. Sometimes, the wrong signals may be plotted.

By addressing these points, you should be able to identify the issue and achieve the expected results from your state-space observer.

If problems persist, consider simplifying the model to isolate the issue further.

Hope this helps.

  댓글 수: 4
Abdul Hamzah
Abdul Hamzah 2024년 10월 14일
am I feeling that my question is answered by a bot?
Umar
Umar 2024년 10월 14일
Hi @ Abdul Hamzah,
Please see my edited comments.

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

카테고리

Help CenterFile Exchange에서 Additional Math and Discrete에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by