- #1
e0ne199
- 56
- 5
- 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 :
but somehow I am only able to produce this result :
Do you know what is actually wrong with my code?? any response and help is really appreciated..thanks before
and I connect it to this model :% 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)
but somehow I am only able to produce this result :
Do you know what is actually wrong with my code?? any response and help is really appreciated..thanks before