forked from bw1129/PIDtoolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PTprocess.m
129 lines (112 loc) · 7.86 KB
/
PTprocess.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
%% PTprocess - script that extracts subset of total data based on highlighted epoch in main fig
% ----------------------------------------------------------------------------------
% "THE BEER-WARE LICENSE" (Revision 42):
% <[email protected]> wrote this file. As long as you retain this notice you
% can do whatever you want with this stuff. If we meet some day, and you think
% this stuff is worth it, you can buy me a beer in return. -Brian White
% ----------------------------------------------------------------------------------
try
if ~isempty(filenameA) ||~isempty(filenameB)
downsampleMultiplier = 5; % 5th of the resolution for faster plotting, display only
set(PTfig, 'pointer', 'watch')
if ~isempty(filenameA)
if isempty(epoch1_A) || isempty(epoch2_A)
epoch1_A = round(tta(1) / us2sec) + 2;
epoch2_A = round(tta(end) / us2sec) - 2;
guiHandles.Epoch1_A_Input = uicontrol(PTfig, 'style', 'edit', 'string', [int2str(epoch1_A)], 'fontsize', fontsz, 'units', 'normalized', 'Position', [posInfo.Epoch1_A_Input],
'callback', '@textinput_call; epoch1_A=str2num(get(guiHandles.Epoch1_A_Input, ''String'')); PTprocess;PTplotLogViewer;');
guiHandles.Epoch2_A_Input = uicontrol(PTfig, 'style', 'edit', 'string', [int2str(epoch2_A)], 'fontsize', fontsz, 'units', 'normalized', 'Position', [posInfo.Epoch2_A_Input],
'callback', '@textinput_call;epoch2_A=str2num(get(guiHandles.Epoch2_A_Input, ''String'')); PTprocess;PTplotLogViewer;');
end
if (epoch2_A > round(tta(end) / us2sec))
epoch2_A = round(tta(end) / us2sec);
guiHandles.Epoch2_A_Input = uicontrol(PTfig, 'style', 'edit', 'string', [int2str(epoch2_A)], 'fontsize', fontsz, 'units', 'normalized', 'Position', [posInfo.Epoch2_A_Input],
'callback', '@textinput_call;epoch2_A=str2num(get(guiHandles.Epoch2_A_Input, ''String'')); PTprocess;PTplotLogViewer;');
end
x = [epoch1_A * us2sec epoch2_A * us2sec];
x2 = tta > tta(find(tta > x(1), 1)) & tta < tta(find(tta > x(2), 1));
Time_A = tta(x2, 1) / us2sec;
Time_A = Time_A - Time_A(1);
DATtmpA.GyroFilt = DATmainA.GyroFilt(:, x2);
DATtmpA.debug = DATmainA.debug(:, x2);
DATtmpA.RCcommand = DATmainA.RCcommand(:, x2);
DATtmpA.Pterm = DATmainA.Pterm(:, x2);
DATtmpA.Iterm = DATmainA.Iterm(:, x2);
DATtmpA.DtermRaw = DATmainA.DtermRaw(:, x2);
DATtmpA.DtermFilt = DATmainA.DtermFilt(:, x2);
DATtmpA.Fterm = DATmainA.Fterm(:, x2);
DATtmpA.PIDsum = DATmainA.PIDsum(:, x2);
DATtmpA.RCRate = DATmainA.RCRate(:, x2);
DATtmpA.PIDerr = DATmainA.PIDerr(:, x2);
DATtmpA.Motor12 = DATmainA.Motor(1:2, x2);
DATtmpA.Motor34 = DATmainA.Motor(3:4, x2);
DATtmpA.debug12 = DATmainA.debug(1:2, x2);
DATtmpA.debug34 = DATmainA.debug(3:4, x2);
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)';
DATdnsmplA.RCcommand = downsample(DATmainA.RCcommand', dnsampleFactor)';
DATdnsmplA.Pterm = downsample(DATmainA.Pterm', dnsampleFactor)';
DATdnsmplA.Iterm = downsample(DATmainA.Iterm', dnsampleFactor)';
DATdnsmplA.DtermRaw = downsample(DATmainA.DtermRaw', dnsampleFactor)';
DATdnsmplA.DtermFilt = downsample(DATmainA.DtermFilt', dnsampleFactor)';
DATdnsmplA.Fterm = downsample(DATmainA.Fterm', dnsampleFactor)';
DATdnsmplA.RCRate = downsample(DATmainA.RCRate', dnsampleFactor)';
DATdnsmplA.PIDsum = downsample(DATmainA.PIDsum', dnsampleFactor)';
DATdnsmplA.PIDerr = downsample(DATmainA.PIDerr', dnsampleFactor)';
DATdnsmplA.Motor = downsample(DATmainA.Motor', dnsampleFactor)';
end
if ~isempty(filenameB)
if isempty(epoch1_B) || isempty(epoch2_B)
epoch1_B = round(ttb(1) / us2sec) + 2;
epoch2_B = round(ttb(end) / us2sec) - 2;
guiHandles.Epoch1_B_Input = uicontrol(PTfig, 'style', 'edit', 'string', [int2str(epoch1_B)], 'fontsize', fontsz, 'units', 'normalized', 'Position', [posInfo.Epoch1_B_Input],
'callback', '@textinput_call; epoch1_B=str2num(get(guiHandles.Epoch1_B_Input, ''String''));PTprocess;PTplotLogViewer; ');
guiHandles.Epoch2_B_Input = uicontrol(PTfig, 'style', 'edit', 'string', [int2str(epoch2_B)], 'fontsize', fontsz, 'units', 'normalized', 'Position', [posInfo.Epoch2_B_Input],
'callback', '@textinput_call; epoch2_B=str2num(get(guiHandles.Epoch2_B_Input, ''String''));PTprocess;PTplotLogViewer; ');
end
if (epoch2_B > round(ttb(end) / us2sec))
epoch2_B = round(ttb(end) / us2sec);
guiHandles.Epoch2_B_Input = uicontrol(PTfig, 'style', 'edit', 'string', [int2str(epoch2_B)], 'fontsize', fontsz, 'units', 'normalized', 'Position', [posInfo.Epoch2_B_Input],
'callback', '@textinput_call; epoch2_B=str2num(get(guiHandles.Epoch2_B_Input, ''String'')); PTprocess;PTplotLogViewer;');
end
x = [epoch1_B * us2sec epoch2_B * us2sec];
x2 = ttb > ttb(find(ttb > x(1), 1)) & ttb < ttb(find(ttb > x(2), 1));
Time_B = ttb(x2, 1) / us2sec;
Time_B = Time_B - Time_B(1);
DATtmpB.GyroFilt = DATmainB.GyroFilt(:, x2);
DATtmpB.debug = DATmainB.debug(:, x2);
DATtmpB.RCcommand = DATmainB.RCcommand(:, x2);
DATtmpB.Pterm = DATmainB.Pterm(:, x2);
DATtmpB.Iterm = DATmainB.Iterm(:, x2);
DATtmpB.DtermRaw = DATmainB.DtermRaw(:, x2);
DATtmpB.DtermFilt = DATmainB.DtermFilt(:, x2);
DATtmpB.Fterm = DATmainB.Fterm(:, x2);
DATtmpB.PIDsum = DATmainB.PIDsum(:, x2);
DATtmpB.RCRate = DATmainB.RCRate(:, x2);
DATtmpB.PIDerr = DATmainB.PIDerr(:, x2);
DATtmpB.Motor12 = DATmainB.Motor(1:2, x2);
DATtmpB.Motor34 = DATmainB.Motor(3:4, x2);
DATtmpB.debug12 = DATmainB.debug(1:2, x2);
DATtmpB.debug34 = DATmainB.debug(3:4, x2);
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)';
DATdnsmplB.RCcommand = downsample(DATmainB.RCcommand', dnsampleFactor)';
DATdnsmplB.Pterm = downsample(DATmainB.Pterm', dnsampleFactor)';
DATdnsmplB.Iterm = downsample(DATmainB.Iterm', dnsampleFactor)';
DATdnsmplB.DtermRaw = downsample(DATmainB.DtermRaw', dnsampleFactor)';
DATdnsmplB.DtermFilt = downsample(DATmainB.DtermFilt', dnsampleFactor)';
DATdnsmplB.Fterm = downsample(DATmainB.Fterm', dnsampleFactor)';
DATdnsmplB.RCRate = downsample(DATmainB.RCRate', dnsampleFactor)';
DATdnsmplB.PIDsum = downsample(DATmainB.PIDsum', dnsampleFactor)';
DATdnsmplB.PIDerr = downsample(DATmainB.PIDerr', dnsampleFactor)';
DATdnsmplB.Motor = downsample(DATmainB.Motor', dnsampleFactor)';
end
set(PTfig, 'pointer', 'arrow')
end
catch ME
errmsg.PTprocess = PTerrorMessages('PTprocess', ME);
end