Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
bw1129 committed Apr 5, 2019
1 parent 23e6e8c commit 78fe09d
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 27 deletions.
Binary file added PID_Compensation_Animated.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 12 additions & 4 deletions PIDtoolbox.m
Expand Up @@ -20,6 +20,8 @@
bgcolor=[.95 .95 .95];
set(PTfig,'color',bgcolor);

wikipage='https://github.com/bw1129/PIDtoolbox/wiki/PIDtoolbox-user-guide';

if ~exist('filenameA','var'), filenameA=[]; end
if ~exist('filenameB','var'), filenameB=[]; end

Expand Down Expand Up @@ -92,6 +94,8 @@
posInfo.TuningButton=[.9 .465 .085 .04];
posInfo.DispInfoButton=[.9 .420 .085 .04];
posInfo.saveFig=[.9 .375 .085 .04];
posInfo.wiki=[.9 .025 .085 .04];


% posInfo.AlooptimeText = [.8 .43 .18 .04];
% posInfo.BlooptimeText = [.8 .4 .18 .04];
Expand Down Expand Up @@ -132,10 +136,6 @@
'callback','guiHandles.runAll.FontWeight=''bold'';PTload;PTprocess;PTviewerUIcontrol; PTplotLogViewer;guiHandles.runAll.FontWeight=''normal'';');
guiHandles.runAll.BackgroundColor=[.3 .9 .3];

guiHandles.saveFig = uicontrol(PTfig,'string','save fig','fontsize',fontsz,'units','normalized','outerposition',[posInfo.saveFig],...
'callback','guiHandles.saveFig.FontWeight=''bold'';PTsaveFig; guiHandles.saveFig.FontWeight=''normal'';');
guiHandles.saveFig.BackgroundColor=[ .8 .8 .8];

guiHandles.Epoch1_A_text = uicontrol(PTfig,'style','text','string','[A] st(s)','fontsize',fontsz,'units','normalized','BackgroundColor',bgcolor,'outerposition',[posInfo.Epoch1_A_text]);
guiHandles.Epoch1_A_Input = uicontrol(PTfig,'style','edit','string',int2str(epoch1_A),'fontsize',fontsz,'units','normalized','outerposition',[posInfo.Epoch1_A_Input],...
'callback','@textinput_call; epoch1_A=str2num(guiHandles.Epoch1_A_Input.String);PTprocess;PTplotLogViewer; ');
Expand All @@ -162,6 +162,14 @@
'callback','PTdispSetupInfo;');
guiHandles.DispInfoButton.BackgroundColor=[ .8 .8 .8];

guiHandles.saveFig = uicontrol(PTfig,'string','save fig','fontsize',fontsz,'units','normalized','outerposition',[posInfo.saveFig],...
'callback','guiHandles.saveFig.FontWeight=''bold'';PTsaveFig; guiHandles.saveFig.FontWeight=''normal'';');
guiHandles.saveFig.BackgroundColor=[ .8 .8 .8];

guiHandles.wiki = uicontrol(PTfig,'string','Wiki','fontsize',fontsz,'units','normalized','outerposition',[posInfo.wiki],...
'callback','try, system([''start chrome '' wikipage]), catch, web(wikipage), end');
guiHandles.wiki.BackgroundColor=[1 1 .2];


%% functions

Expand Down
4 changes: 2 additions & 2 deletions PTimport.m
Expand Up @@ -69,11 +69,11 @@
end
% if more than one file
if length(files) > 1
% delete files with < 500kb - may need better work-around eventually
% delete files with < 300kb - may need better work-around eventually
x=length(files);
m=1;
for k=1:x,
if ((files(k).bytes)) < 500000 % delete if < 500kb
if ((files(k).bytes)) < 300000 % delete if < 300kb
delete(files(k).name)
else
f2(m)=files(k);
Expand Down
1 change: 1 addition & 0 deletions PTplotLogViewer.m
Expand Up @@ -39,6 +39,7 @@
guiHandles.TuningButton.FontSize=fontsz;
guiHandles.DispInfoButton.FontSize=fontsz;
guiHandles.saveFig.FontSize=fontsz;
guiHandles.wiki.FontSize=fontsz;
guiHandles.checkbox0.FontSize=fontsz;
guiHandles.checkbox1.FontSize=fontsz;
guiHandles.checkbox2.FontSize=fontsz;
Expand Down
16 changes: 8 additions & 8 deletions PTplotPIDerror.m
Expand Up @@ -21,15 +21,15 @@
guiHandlesPIDerr.saveFig3.FontSize=fontsz3;


%% PID error distributions
figure(3);
%% PID error distributions
ylab2={'roll';'pitch';'yaw'};
for p=1:3
figure(PTerrfig);
for p=1:3
delete(subplot('position',posInfo.PIDerrAnalysis(p,:)))
h1=subplot('position',posInfo.PIDerrAnalysis(p,:)); cla
hold on

if ~isempty(filenameA)
if ~isempty(filenameA)
RCRateALL_Thresh_A=abs(DATtmpA.RCRate(1,:)) < maxDegsec & abs(DATtmpA.RCRate(2,:)) < maxDegsec & abs(DATtmpA.RCRate(3,:)) < maxDegsec;
[yA xA]=hist(DATtmpA.PIDerr(p,RCRateALL_Thresh_A),-1000:1:1000); %<maxDegsec),-maxDegsec:1:maxDegsec);
yA=yA/max(yA);
Expand All @@ -51,7 +51,7 @@
set(h,'fontsize',fontsz3,'color',colorA,'fontweight','bold')
end

if ~isempty(filenameB)
if ~isempty(filenameB)
RCRateALL_Thresh_B=abs(DATtmpB.RCRate(1,:)) < maxDegsec & abs(DATtmpB.RCRate(2,:)) < maxDegsec & abs(DATtmpB.RCRate(3,:)) < maxDegsec;
[yB xB]=hist(DATtmpB.PIDerr(p,RCRateALL_Thresh_B),-1000:1:1000);
yB=yB/max(yB);
Expand Down Expand Up @@ -90,7 +90,7 @@
if ~updateErr
t=[.1 .2 .3 .4 .5 .6 .7 .8 .9 1];

cutoff=50;
cutoff=40; % ignore less frequent error at the extremes, outliers
if ~isempty(filenameA)
for i=1:length(t)
clear RCRateALL_Thresh_A
Expand Down Expand Up @@ -139,7 +139,7 @@
set(h1,'tickdir','out','xminortick','off','yminortick','on');
set(h1,'fontsize',fontsz3);
ylabel(['mean |' ylab(p) ' error| ^o/s'], 'fontweight','bold')
set(h1,'xtick',[0:2:10], 'xticklabel',{''});
set(h1,'xtick',[0:2:10], 'xticklabel',{''},'ygrid','on');
axis([0 11 minyA maxyA])
box off
if p==3
Expand All @@ -160,7 +160,7 @@
set(h1,'tickdir','out','xminortick','off','yminortick','on');
set(h1,'fontsize',fontsz3);
ylabel(['mean |' ylab(p) ' error| ^o/s'], 'fontweight','bold')
set(h1,'xtick',[0:2:10], 'xticklabel',{''});
set(h1,'xtick',[0:2:10], 'xticklabel',{''},'ygrid','on');
axis([0 11 min([minyA minyB]) max([maxyA maxyB])])
box off
if p==3
Expand Down
6 changes: 4 additions & 2 deletions PTplotSpec.m
Expand Up @@ -111,11 +111,12 @@
end

if guiHandlesSpec.checkbox2d.Value==0 && ~isempty(ampmat)
figure(PTspecfig);
%%%%% plot spec mattrices
c1=[1 1 1 2 2 2 3 3 3 4 4 4];
c2=[1 2 3 1 2 3 1 2 3 1 2 3];
ftr = fspecial('gaussian',[guiHandlesSpec.smoothFactor_select.Value*5 guiHandlesSpec.smoothFactor_select.Value],4);
for p=1:size(ampmat,2)
for p=1:size(ampmat,2)
delete(subplot('position',posInfo.SpecPos(p,:)));
if ~isempty(ampmat{p})
delete(subplot('position',posInfo.SpecPos(p,:)));
Expand All @@ -124,7 +125,7 @@
imagesc(flipud((filter2(ftr, ampmat{p}))'))
hold on

if strfind(smat{p},'DATtmpA'),
if strfind(smat{p},'DATtmpA')
lograte=A_lograte;
else
lograte=B_lograte;
Expand Down Expand Up @@ -282,6 +283,7 @@
end

if guiHandlesSpec.checkbox2d.Value==1 && ~isempty(amp2d)
figure(PTspecfig);
try
delete(hCbar1);delete(hCbar2);delete(hCbar3);delete(hCbar4)
catch
Expand Down
6 changes: 4 additions & 2 deletions PTprocess.m
Expand Up @@ -9,6 +9,8 @@


if ~isempty(filenameA) || ~isempty(filenameB)

downsampleMultiplier=5;% 5 times less resolution for faster plotting, display only

set(PTfig, 'pointer', 'watch')
if ~isempty(filenameA)
Expand Down Expand Up @@ -41,7 +43,7 @@
DATtmpA.PIDerr=DATmainA.PIDerr(:,x2);
DATtmpA.Motor=DATmainA.Motor(:,x2);

dnsampleFactor=A_lograte*10;
dnsampleFactor=A_lograte*downsampleMultiplier;% 5 times less resolution for faster plotting, display only
DATdnsmplA.tta=downsample(((tta-tta(1))/us2sec), dnsampleFactor)';
DATdnsmplA.GyroFilt=downsample(DATmainA.GyroFilt', dnsampleFactor)';
DATdnsmplA.debug=downsample(DATmainA.debug', dnsampleFactor)';
Expand Down Expand Up @@ -87,7 +89,7 @@
DATtmpB.PIDerr=DATmainB.PIDerr(:,x2);
DATtmpB.Motor=DATmainB.Motor(:,x2);

dnsampleFactor=B_lograte*10;
dnsampleFactor=B_lograte*downsampleMultiplier;% 5 times less resolution for faster plotting, display only
DATdnsmplB.ttb=downsample(((ttb-ttb(1))/us2sec), dnsampleFactor)';
DATdnsmplB.GyroFilt=downsample(DATmainB.GyroFilt', dnsampleFactor)';
DATdnsmplB.debug=downsample(DATmainB.debug', dnsampleFactor)';
Expand Down
2 changes: 1 addition & 1 deletion PTspecUIcontrol.m
Expand Up @@ -159,7 +159,7 @@

%% get estimate of phase delay (computed on roll axis only since it's typically the most active)
% note, this is an estimate, given the many dynamic filter options in BF4.0+
% the reliability of the estimate depende to some degree on the amplitude modulation of the signals
% the reliability of the estimate depend to some degree on the amplitude modulation of the signals
% (i.e., when there is stick input).
clear sampTime maxlag PhaseDelay_A PhaseDelay2_A
if A_debugmode==GYRO_SCALED
Expand Down
20 changes: 12 additions & 8 deletions PTtuningParams.m
Expand Up @@ -29,12 +29,13 @@
for p=1:3
try
if ~updateStep
[stepresp_A{p} tA rateHigh_A{p}] = PTstepcalc(DATtmpA.RCRate(p,:), DATtmpA.GyroFilt(p,:), A_lograte);
[stepresp_A{p} tA rateHigh_A{p}] = PTstepcalc(DATtmpA.RCRate(p,:), DATtmpA.GyroFilt(p,:), A_lograte);
end
catch
stepresp_A{p}=[];
rateHigh_A{p}=[];
end
figure(PTtunefig)
h1=subplot('position',posInfo.TparamsPos(p,:)); cla
hold on
if guiHandlesSpec.checkboxrateHigh.Value==1,
Expand All @@ -51,9 +52,9 @@
h3=plot(tA,m+sd,'--'); set(h3, 'color',[colorA],'linewidth',.5)
stepnfo=stepinfo(nanmean(stepresp_A{p}(rA,:)),tA,1);

eval(['PIDF=' ylab2{p} 'PIDF_A;'])
eval(['PID=' ylab2{p} 'PIDF_A;'])
h=text(320, .8, ['N=' int2str(size(stepresp_A{p}(rA,:),1)) ]);set(h,'fontsize',fontsz4)
h=text(320, .7, ['PIDF: ' char(string(PIDF(:,2)))]);set(h,'fontsize',fontsz4)
h=text(320, .7, ['PID: ' char(string(PID(:,2)))]);set(h,'fontsize',fontsz4)
h=text(320, .6, ['Peak: ' num2str(stepnfo.Peak)]);set(h,'fontsize',fontsz4)
h=text(320, .5, ['PeakTime: ' num2str(stepnfo.PeakTime)]);set(h,'fontsize',fontsz4)
h=text(320, .4, ['%Overshoot: ' num2str(stepnfo.Overshoot)]);set(h,'fontsize',fontsz4)
Expand All @@ -68,10 +69,10 @@
if p==3
set(gca,'fontsize',fontsz4,'xminortick','on','yminortick','on','xtick',[0 100 200 300 400 500],'xticklabel',{'0' '100' '200' '300' '400' '500'},'ytick',[0 .2 .4 .6 .8 1 1.2 1.4 1.6],'tickdir','out')
else
set(gca,'fontsize',fontsz4,'xminortick','on','yminortick','on','xtick',[0 100 200 300 400 500],'xticklabel',{'' '' '' '' '' ''},'ytick',[0 .2 .4 .6 .8 1 1.2 1.4 1.6],'tickdir','out')
set(gca,'fontsize',fontsz4,'xminortick','on','yminortick','on','xtick',[0 100 200 300 400 500],'xticklabel',{'' '' '' '' '' ''},'ytick',[0 .2 .4 .6 .8 1 1.2 1.4 1.6],'tickdir','out','ygrid','on')
end
box off
h=ylabel({'mean response (+/-sd)'}, 'fontweight','bold');
h=ylabel({'mean response {\pm}sd'}, 'fontweight','bold');
set(h,'fontsize',fontsz4)
if p==3, xlabel('time (ms)', 'fontweight','bold');end
if p==1, title('Step response [A]');end
Expand All @@ -80,6 +81,7 @@
h=plot([0 500],[1 1],'k--');
set(h,'linewidth',.5)
axis([0 500 0 1.6])
grid on
end
end

Expand All @@ -94,6 +96,7 @@
stepresp_B{p}=[];
rateHigh_B{p}=[];
end
figure(PTtunefig)
h1=subplot('position',posInfo.TparamsPos(p+3,:)); cla
hold on
if guiHandlesSpec.checkboxrateHigh.Value==1,
Expand All @@ -109,9 +112,9 @@
h6=plot(tB,m+sd,'--'); set(h6, 'color',[colorB],'linewidth',.5)
stepnfo=stepinfo(nanmean(stepresp_B{p}(rB,:)),tB,1);

eval(['PIDF=' ylab2{p} 'PIDF_B;'])
eval(['PID=' ylab2{p} 'PIDF_B;'])
h=text(320, .8, ['N=' int2str(size(stepresp_B{p}(rB,:),1)) ]);set(h,'fontsize',fontsz4)
h=text(320, .7, ['PIDF: ' char(string(PIDF(:,2)))]);set(h,'fontsize',fontsz4)
h=text(320, .7, ['PID: ' char(string(PID(:,2)))]);set(h,'fontsize',fontsz4)
h=text(320, .6, ['Peak: ' num2str(stepnfo.Peak)]);set(h,'fontsize',fontsz4)
h=text(320, .5, ['PeakTime: ' num2str(stepnfo.PeakTime)]);set(h,'fontsize',fontsz4)
h=text(320, .4, ['%Overshoot: ' num2str(stepnfo.Overshoot)]);set(h,'fontsize',fontsz4)
Expand All @@ -130,7 +133,7 @@
end

box off
h=ylabel({'mean response (+/-sd)'}, 'fontweight','bold');
h=ylabel({'mean response {\pm}sd'}, 'fontweight','bold');
set(h,'fontsize',fontsz4)
if p==3, xlabel('time (ms)', 'fontweight','bold');end
if p==1, title('Step response [B]');end
Expand All @@ -139,6 +142,7 @@
h=plot([0 500],[1 1],'k--');
set(h,'linewidth',.5)
axis([0 500 0 1.6])
grid on
end
end

Expand Down

0 comments on commit 78fe09d

Please sign in to comment.