unable to create state space observer

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 Commenti

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.

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

Accedi per commentare.

Risposte (1)

Umar
Umar il 13 Ott 2024

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 Commenti

how about the simulink side? is there any problem on it too?
Umar
Umar il 13 Ott 2024
Modificato: Umar il 14 Ott 2024

Hi @Abdul Hamzah,

You asked, “how about the simulink side? is there any problem on it too?”

I was tired from work. If I was going to design state space observer in Simulink, I will implement the following blocks.

State-Space Block: This will represent your system dynamics. Gain Block: To scale the output of the observer.

Sum Block: To compute the difference between the actual output and the estimated output.

Integrator Block: To integrate the state error.

Configure the State-Space Block: Double-click the State-Space block and enter the system matrices (A, B, C, D) that define your state-space representation.

Connect the Blocks: Connect the blocks appropriately:

The output of the State-Space block goes to the Sum block.

The output of the Sum block feeds into the Gain block.

The output of the Gain block is then integrated to update the state estimate.

Display Results: Use a Scope Block or Display Block to visualize the estimated states. Connect it to the output of the Integrator block.

Run the Simulation: Set the simulation parameters and run the model to observe the results.

So, in your simulink model I don’t see “integrator block”.

https://www.mathworks.com/help/simulink/slref/integrator.html

Also, @Sam Chak provided comments as well.

Hope this helps.

Hope this helps.

am I feeling that my question is answered by a bot?
Hi @ Abdul Hamzah,
Please see my edited comments.

Accedi per commentare.

Categorie

Scopri di più su General Applications in Centro assistenza e File Exchange

Prodotti

Release

R2024a

Richiesto:

il 13 Ott 2024

Commentato:

il 14 Ott 2024

Community Treasure Hunt

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

Start Hunting!

Translated by