-
Notifications
You must be signed in to change notification settings - Fork 0
/
kld.m
318 lines (317 loc) · 9.34 KB
/
kld.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
%#######################################################################
%
% * Knee Loading Device Program 1 *
%
% M-File which collects load data from the knee loading device
% (KLD).
%
% The program checks for previous data files from that day.
% If there is no file, the program will prompt the user for zero
% load data. If there is a file, it reads the previous subject ID,
% subject's weight, examiner number and zero load data. The user
% is then prompted to verify or input the subject and examiner data.
% The program reads any previous data file from the day matching the
% subject and examiner data to determine the trial number.
%
% For each trial, the program prompts and collects 10 seconds of
% load data with no applied pressure load to get the loads from the
% foot resting in the foot holder. The user is then prompted to
% collect 720 seconds (12 minutes) of load data while the subject is
% loaded at half body weight. All the load data is collected at
% 10 Hz.
%
% The load data and test information is saved in a MAT file in
% the subdirectory "Data" with file name:
%
% subjID_examN_trial?_DDMMMYYYY.mat
%
% where ID is the subject initials, N is 1 or 2 for examiner 1 or 2,
% ? is the trial number and DDMMMYYYY is the test date in day, three
% letter month and year format.
%
% NOTES: 1. For ATI Industrial Automation Mini45 force transducer
% SI-580-20 S/N FT05071 with NI USB-6210 Multifunction I/O.
%
% 2. The loadcell calibration file, FT5071cal.mat, must be
% in the current directory or path.
%
% 3. M-files cl.m, countdown_clock.m and get_data.m must
% be in the current directory or path.
%
% 16-Jul-2018 * Mack Gardner-Morse
%
% 09-Oct-2018 * Mack Gardner-Morse * New pressure calibration
%
% 07-Nov-2018 * Mack Gardner-Morse * Added plotting of tensioning
% loads in the unloaded (before
% applied pressure) state with a
% target of 15% body weight.
%
% 28-Nov-2018 * Mack Gardner-Morse * Subject ID changed to a number.
% Zero loadcell after each
% examiner.
%
%#######################################################################
%
% Clear WorkSpace
%
cl;
%
% Global Variables
% idx is the incremental index into the full data arrays fdata and ftime
%
global fdata ftime idx
%
% Data Directory
%
ddir = 'Data';
%
% Conversion from Body Weight to Pressure
% See press_cal1.xlsx
%
% wt2psi = 4.44822/10.353; % Full body weight
% wt2psi = wt2psi/2; % Half body weight
%
% Conversion from Body Weight to Pressure
% See press_cal3.xlsx
%
lbf2N = 4.448221615; % N/lbf
wt2psi = [1 10.491904]./10.7133585; % Coefficient and intercept
%
% Get Todays Date in DDMMMYYYY Format
%
dtxt = datestr(now,'ddmmmyyyy');
%
% Check for Previous MAT Files from Today for Setting Defaults
%
d = dir(fullfile(ddir,['*_' dtxt '.mat']));
if isempty(d)
defs = {'','','1'};
else
[~,ids] = sort([d.datenum]);
ids = ids(end); % Index to newest MAT file
dnam = fullfile(ddir,d(ids).name);
load(dnam,'id','idstr','wt','exam','zdat','zdata','ztime');
wt = sprintf('%5.1f',wt);
defs = {idstr,wt,int2str(exam)};
clear d dnam ids wt;
end
%
% Get Subject ID, Weight and Examiner
%
ttxt = 'Input';
prmpt = {'Subject ID', 'Subject Weight (lbs)', ...
'Examiner (1 or 2)'};
% dims = [1 3; 1 25; 1 1];
nlin = 1;
ok = false;
while ~ok
answ = inputdlg(prmpt,ttxt,nlin,defs);
id = str2double(answ{1});
wt = str2double(answ{2});
exam = str2double(answ{3});
if ~isnan(id)&&id>0&&id<100&&wt>25&&wt<=250&&(exam==1||exam==2)
ok = true;
end
end
%
% Get Subject ID as a String
%
idstr = int2str(id);
if id<10
idstr = ['0' idstr];
end
%
% Get Required Pressure Setting
%
wth = wt*lbf2N/2; % Half body weight in N
wt10 = wth/5; % 10% of body weight in N
psi = polyval(wt2psi,wth); % Target psi
psis = sprintf('%4.1f',psi);
%
uiwait(msgbox({['Please set pressure to ' psis ' psi for']; ...
'50% body weight compressive load.'}, ...
'Action Required','warn','modal'));
%
% Get Trial Number
%
d = dir(fullfile(ddir,['subj' idstr '_exam' int2str(exam) '_trial*_' ...
dtxt '.mat']));
if isempty(d)
n = 1;
izero = true;
else
fnams = {d.name}';
fnams = sort(fnams);
fnam = fnams{end};
idext = strfind(fnam,['_' dtxt]);
fnum = fnam(19); % Trial number must be less than ten (10)
n = str2double(fnum)+1;
izero = false;
end
%
% Load Loadcell Calibration Matrix
%
load FT5071cal.mat;
%
% Get DAQ
%
dev = daq.getDevices;
dev_id = dev.ID;
%
s1 = daq.createSession('ni');
%
% Setup Session
%
dur = 10; % Duration time in seconds
rate = 10;
s1.Rate = rate; % Rate in Hz
s1.DurationInSeconds = dur; % Duration time in seconds
%
% Add Channels
%
ai1 = addAnalogInputChannel(s1,dev_id,'ai2','Voltage');
ai1.TerminalConfig = 'SingleEnded';
ai1.Range = [-10 10];
ai1.Name = 'SG0';
%
ai2 = addAnalogInputChannel(s1,dev_id,'ai3','Voltage');
ai2.TerminalConfig = 'SingleEnded';
ai2.Range = [-10 10];
ai2.Name = 'SG1';
%
ai3 = addAnalogInputChannel(s1,dev_id,'ai4','Voltage');
ai3.TerminalConfig = 'SingleEnded';
ai3.Range = [-10 10];
ai3.Name = 'SG2';
%
ai4 = addAnalogInputChannel(s1,dev_id,'ai5','Voltage');
ai4.TerminalConfig = 'SingleEnded';
ai4.Range = [-10 10];
ai4.Name = 'SG3';
%
ai5 = addAnalogInputChannel(s1,dev_id,'ai6','Voltage');
ai5.TerminalConfig = 'SingleEnded';
ai5.Range = [-10 10];
ai5.Name = 'SG4';
%
ai6 = addAnalogInputChannel(s1,dev_id,'ai7','Voltage');
ai6.TerminalConfig = 'SingleEnded';
ai6.Range = [-10 10];
ai6.Name = 'SG5';
%
% Acquire Zero Data
%
if izero
%
h = msgbox({' Click "OK" to Collect'; ...
'10 seconds of Zero Load Data'},'modal');
ha = get(h,'CurrentAxes');
hc = get(ha,'Child');
set(hc,'FontSize',8,'FontWeight','bold');
uiwait(h);
%
[zdata,ztime] = startForeground(s1);
%
zdat = mean(zdata);
%
end
%
% Setup Figure for Unloaded (No Applied Pressure) Data
%
fhu = figure('Position',[1120 560 560 420]);
tld = 0.15*wt; % 15% of body weight
ht = plot([0; 1],[tld; tld],'r-','Linewidth',1); % Target load
hold on;
hd = plot([0; 1],[NaN; NaN],'b.','Linewidth',1,'MarkerSize',7);
xlabel('Time (s)','FontSize',12,'FontWeight','bold');
ylabel('Force (lbf)','FontSize',12,'FontWeight','bold');
title('Axial Force','FontSize',16,'FontWeight','bold');
hax = get(fhu,'CurrentAxes');
%
% Acquire Unloaded (No Applied Pressure) Data
%
hm = msgbox({'Please start tightening leg straps.'; ...
' Press OK when finished.'},'Unloaded Data');
ha = get(hm,'CurrentAxes');
hc = get(ha,'Child');
set(hc,'FontSize',8,'FontWeight','bold');
%
utim = [];
udat = [];
%
while isvalid(hm)
[udata,utime] = s1.inputSingleScan;
udat = [udat; udata];
ns = size(udat,1);
utim = [utim; utime];
%
datu = udat-repmat(zdat,ns,1); % Zero sensor
[~,~,~,~,m,s] = datevec(utim);
ut = 60*m+s;
ut = ut-repmat(ut(1),ns,1); % Zero time
%
ud = (cal*datu')'; % Scale data
%
tend = ut(end);
if tend==0
tend = 0.001;
end
set(ht,'XData',[0; tend]);
set(hd,'XData',ut,'YData',-ud(:,3)./4.44822);
set(hax,'Xlim',[0 tend]);
refresh(fhu);
drawnow;
end
%
% Setup Trial Session
%
dur = 720; % Duration time in seconds (12 minutes)
% dur = 30; % Duration time in seconds (half a minute) - for testing
s1.DurationInSeconds = dur; % Duration time in seconds
%
npts = dur*rate;
fdata = zeros(npts,6);
ftime = zeros(npts,1);
idx = 1;
fh = figure('Position',[1120 560 560 420]);
xlabel('Time (s)','FontSize',12,'FontWeight','bold');
ylabel('Force (lbf)','FontSize',12,'FontWeight','bold');
title('Axial Force','FontSize',16,'FontWeight','bold');
tld = wt/2;
hax = get(fh,'CurrentAxes');
ht = plot([0; 1],[tld; tld],'r-','Linewidth',1); % Target load
hold on;
hd = plot([0; 1],[NaN; NaN],'b.','Linewidth',1,'MarkerSize',7);
%
lh = s1.addlistener('DataAvailable', ...
@(src,event) get_data(event,cal,zdat,fh,hax,ht,hd));
%
% Acquire 12 minutes of Force Data
%
h = msgbox({[' Pressure is ' psis ' psi?']; ...
' Click "OK" to Collect';' 12 minutes of Data'}, ...
'modal');
ha = get(h,'CurrentAxes');
hc = get(ha,'Child');
set(hc,'FontSize',9.8,'FontWeight','bold');
uiwait(h);
%
startBackground(s1);
uiwait(countdown_clock(dur));
%
delete(lh); % Delete listener
close(fh); % Close force plot figure
s1.stop; % Be sure session has stopped
%
% Save Data
%
fnam = ['subj' idstr '_exam' int2str(exam) '_trial' int2str(n) ...
'_' dtxt '.mat'];
fnamd = fullfile(ddir,fnam); % Put in subdirectory
%
save(fnamd,'cal','dtxt','exam','fdata','ftime','id','idstr','lbf2N', ...
'psi','psis','n','wt','wt2psi','wth','ud','udat','ut','utim', ...
'zdat','zdata','ztime');
%
return