runfile.m

Objective-C source code icon runfile.m — Objective-C source code, 4 kB (4559 bytes)

File contents

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Feedback gain estimation using direct approach in a closed loop system 
% the plant is double link inverted pendulum with linearized equations of
% motion (at the upright position), the controller is PD
% Data is generated using this closed loop system and this data is used to
% identify the feedback controller gains 
% Author: Samin Askarian
% Creation: May 2014
% MATLAB version: R2013b
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clc
clear


global M
a   = 0:0.001:0.4;   % Platform acceleration 

M   = 100;           % Number of Brownian paths
P   =system_prop;
randn('state',80) 

%% Predefining gain means([k11 k12 k13 k14;k21 k22 k23 k24]) and standard deviation([S11 S12 S13 S14;S21 S22 S23 S24])

k11 = zeros(1,length(a));
k12 = zeros(1,length(a));
k13 = zeros(1,length(a));
k14 = zeros(1,length(a));
k21 = zeros(1,length(a));
k22 = zeros(1,length(a));
k23 = zeros(1,length(a));
k24 = zeros(1,length(a));

S11 = zeros(1,length(a));
S12 = zeros(1,length(a));
S13 = zeros(1,length(a));
S14 = zeros(1,length(a));
S21 = zeros(1,length(a));
S22 = zeros(1,length(a));
S23 = zeros(1,length(a));
S24 = zeros(1,length(a));

SE11=zeros(1,length(a));
SE12=zeros(1,length(a));
SE13=zeros(1,length(a));
SE14=zeros(1,length(a));
SE21=zeros(1,length(a));
SE22=zeros(1,length(a));
SE23=zeros(1,length(a));
SE24=zeros(1,length(a));



for i=1:length(a)
[Kemean,Kestd,Xs,TT,KeM]=inverted_pendulum_time_domain(a(i),P);

k11(i)    = Kemean(1,1);
S11(i)    = Kestd(1,1);
SE11(i)   = 1.9647*S11(i)/M^0.5;             %standard error


k12(i)    = Kemean(1,2);
S12(i)    = Kestd(1,2);
SE12(i)   = 1.9647*S12(i)/M^0.5;


k13(i)    = Kemean(1,3);
S13(i)    = Kestd(1,3);
SE13(i)   = 1.9647*S13(i)/M^0.5;


k14(i)    = Kemean(1,4);
S14(i)    = Kestd(1,4);
SE14(i)   = 1.9647*S14(i)/M^0.5;


k21(i)    = Kemean(2,1);
S21(i)    = Kestd(2,1);
SE21(i)   = 1.9647*S21(i)/M^0.5;


k22(i)    = Kemean(2,2);
S22(i)    = Kestd(2,2);
SE22(i)   = k22(i)+1.9647*S22(i)/M^0.5;



k23(i)    = Kemean(2,3);
S23(i)    = Kestd(2,3);
SE23(i)   = k23(i)+1.9647*S23(i)/M^0.5;



k24(i)    = Kemean(2,4);
S24(i)    = Kestd(2,4);
SE24(i)   = k24(i)+1.9647*S24(i)/M^0.5;
end

%% plotting

%Figure(1)
fh = figure(1); 
set(fh, 'color', 'white'); 
d = 1:2:401;
h1= errorbar(a(d),k11(d),cup11(d),'b.','MarkerSize',16);
errorbar_tick(h1,100);
hold on
h2 = plot(a(d),P.K(1,1)*ones(1,length(a(d))),'*','MarkerSize', 4.0,'MarkerFaceColor', [0.8 0 0.8],'MarkerEdgeColor', [0.8 0 1]);
set(gca, 'Box', 'off' );
xlim([0 0.4])
xlabel('W(m/s^2\surdHz)','FontSize', 14)
ylabel('K_{11}','FontSize', 14, 'Rotation', 90 )
hl = legend('Estimated gain','Gain used in data generation','Location','NorthEast');
set(hl,'box','off')
LEG = findobj(hl,'type','text');
set(LEG,'FontSize',14)
set(gca, 'TickDir', 'out', 'XTick', 0:0.05:0.4); 
set(gca,'fontsize',14)
print -depsc -r0 fig1.eps

%Figure(2)
fh = figure(2); 
set(fh, 'color', 'white'); 
d =1:2:401;
h1=errorbar(a(d),k12(d),cup12(d),'b.','MarkerSize',16);
errorbar_tick(h1,100);
hold on
h2 =plot(a(d),P.K(1,2)*ones(1,length(a(d))),'*','MarkerSize', 4.0,'MarkerFaceColor', [0.8 0 0.8],'MarkerEdgeColor', [0.8 0 1]);
set(gca, 'Box', 'off' );
xlim([0 0.4])
xlabel('W(m/s^2\surdHz)','FontSize', 14)
ylabel('K_{12}','FontSize', 14, 'Rotation', 90 )
hl = legend('Estimated gain','Gain used in data generation','Location','NorthEast');
set(hl,'box','off')
LEG = findobj(hl,'type','text');
set(LEG,'FontSize',14)
set(gca, 'TickDir', 'out', 'XTick', 0:0.05:0.4);
set(gca,'fontsize',14)
print -depsc -r0 fig2.eps


%Figure(3)
fh = figure(3); 
set(fh, 'color', 'white'); 
d=1:2:401;
h1=errorbar(a(d),k13(d),cup13(d),'b.','MarkerSize',16);
errorbar_tick(h1,100);
hold on
h2=plot(a(d),P.K(1,3)*ones(1,length(a(d))),'*','MarkerSize', 4.0,'MarkerFaceColor', [0.8 0 0.8],'MarkerEdgeColor', [0.8 0 1]);
set(gca, 'Box', 'off' );
xlim([0 0.4])
xlabel('W(m/s^2\surdHz)','FontSize', 14)
ylabel('K_{13}','FontSize', 14, 'Rotation', 90 )
hl=legend('Estimated gain','Gain used in data generation','Location','NorthEast');
set(hl,'box','off')
LEG = findobj(hl,'type','text');
set(LEG,'FontSize',14)
set(gca, 'TickDir', 'out', 'XTick', 0:0.05:0.4); 
set(gca,'fontsize',14)
print -depsc -r0 fig3.eps