unable to create state space observer

  • #1
e0ne199
56
4
TL;DR Summary
I am unable to produce desired results using state-space model with observer for inverted pendulum
Hello everyone, I am trying to make a state-space observer of inverted pendulum 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 :
xx.png

but somehow I am only able to produce this result :
zz.png

Do you know what is actually wrong with my code?? any response and help is really appreciated..thanks before
 

Similar threads

Back
Top