Design and Simulation of Full Order Observer: Program
Design and Simulation of Full Order Observer: Program
Design and Simulation of Full Order Observer: Program
OUTPUT:
2. SIMULATION OF DISCRETIZATION USING MATLAB
PROGRAM:
G = tf([1 -2],[1 3 20],'inputdelay',1);
Ts = 0.1;
Gd = c2d(G,Ts);
step(G,'b',Gd,'r')
legend('Continuous','Discretized')
Gc = d2c(Gd);
step(G,'b',Gd,'r',Gc,'g--')
legend('Original','Discretized','D2C Interpolant')
Ts = 1;
Hd = c2d(G,Ts);
Hc = d2c(Hd);
step(G,'b',Hd,'r',Hc,'g--',10)
legend('Original','Discretized','D2C Interpolant')
Gr = d2d(Gd,0.025);
step(G,'b',Gr,'r',c2d(G,0.025),'g--',4)
legend('Continuous','Resampled from 0.1 to 0.025','Discretized with
Ts=0.025')
OUTPUT:
3. LQR DESIGN AND SIMULATION USING MATLAB
PROGRAM:
M =
0.5;
m =
0.2;
b =
0.1;
I =
0.006;
g =
9.8;
l =
0.3;
p =
I*(M+m)+M*m*l^2;
A =
[0 1 0 0;
0 -(I+m*l^2)*b/p (m^2*g*l^2)/p 0;
0 0 0 1;
0 -(m*l*b)/p m*g*l*(M+m)/p 0];
B = [ 0;
(I+m*l^2)/p;
0;
m*l/p];
C = [1 0 0 0;
0 0 1 0];
D = [0;
0];
states = {'x' 'x_dot' 'phi' 'phi_dot'};
inputs = {'u'};
outputs = {'x'; 'phi'};
sys_ss =
ss(A,B,C,D,'statename',states,'inputname',inputs,'outputname',outputs);
pole = eig(A);
co = ctrb(sys_ss);
controllability = rank(co);
Q = C'*C;
R = 1;
K = lqr(A,B,Q,R);
Ac = (A-B*K);
Bc = B;
Cc = C;
Dc = D;
states = {'x' 'x_dot' 'phi' 'phi_dot'};
inputs = {'r'};
outputs = {'x'; 'phi'};
sys_cl =
ss(Ac,Bc,Cc,Dc,'statename',states,'inputname',inputs,'outputname',outputs);
t = 0:0.01:5;
r =0.2*ones(size(t));
[y,t,X3]=lsim(sys_cl,r,t);
[AX,h3,H7] = plotyy(t,y(:,1),t,y(:,2),'plot');
set(get(AX(1),'Ylabel'),'String','cart position (m)')
set(get(AX(2),'Ylabel'),'String','pendulum angle (radians)')
title('Step Response with LQR Control')
Q = C'*C;
Q(1,1) = 5000;
Q(3,3) = 100;
R = 1;
K = lqr(A,B,Q,R);
Ac = (A-B*K);
Bc = B;
Cc = C;
Dc = D;
states = {'x' 'x_dot' 'phi' 'phi_dot'};
inputs = {'r'};
outputs = {'x'; 'phi'};
sys_cl =
ss(Ac,Bc,Cc,Dc,'statename',states,'inputname',inputs,'outputname',outputs);
t = 0:0.01:5;
r =0.2*ones(size(t));
[y,t,X1]=lsim(sys_cl,r,t);
[AX,h1,H3] = plotyy(t,y(:,1),t,y(:,2),'plot');
set(get(AX(1),'Ylabel'),'String','cart position (m)')
set(get(AX(2),'Ylabel'),'String','pendulum angle (radians)')
title('Step Response with LQR Control')
Cn = [1 0 0 0];
sys_ss = ss(A,B,Cn,0);
Nbar = rscale(sys_ss,K);
sys_cl =
ss(Ac,Bc*Nbar,Cc,Dc,'statename',states,'inputname',inputs,'outputname',output
s);
t = 0:0.01:5;
r =0.2*ones(size(t));
[y,t,X]=lsim(sys_cl,r,t);
[AX,h,H] = plotyy(t,y(:,1),t,y(:,2),'plot');
set(get(AX(1),'Ylabel'),'String','cart position (m)')
set(get(AX(2),'Ylabel'),'String','pendulum angle (radians)')
title('Step Response with Precompensation and LQR Control')
ob = obsv(sys_ss);
observability = rank(ob);
poles = eig(Ac);
P = [-40 -41 -42 -43];
L = place(A',C',P);
Ace = [(A-B*K) (B*K);
zeros(size(A)) (A-L*C)];
Bce = [B*Nbar;
zeros(size(B))];
Cce = [Cc zeros(size(Cc))];
Dce = [0;0];
states = {'x' 'x_dot' 'phi' 'phi_dot' 'e1' 'e2' 'e3' 'e4'};
inputs = {'r'};
outputs = {'x'; 'phi'};
sys_est_cl =
ss(Ace,Bce,Cce,Dce,'statename',states,'inputname',inputs,'outputname',outputs
);
t = 0:0.01:5;
r = 0.2*ones(size(t));
[y,t,x]=lsim(sys_est_cl,r,t);
[AX,H1,H2] = plotyy(t,y(:,1),t,y(:,2),'plot');
set(get(AX(1),'Ylabel'),'String','cart position (m)')
set(get(AX(2),'Ylabel'),'String','pendulum angle (radians)')
title('Step Response with Observer-Based State-Feedback Control')
OUTPUT: