-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPSI_project.m
80 lines (64 loc) · 2.31 KB
/
PSI_project.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
% This is the script for the data analysis of 2017 UROP PSI accuracy
% project at MSK lab@Imperial College London, it can calculate the error
% angles between target plane and real cutting plane; flatness of real
% cutting plane, it also plot the deviations map of cutting surface for
% local flatness visualization.
%
% The project script needs the support from several functions:
% angle_error,flatness,rgb,stlread,stlreadascii,stlreadbinary
clear all
%% reading data
prompt1 = 'start with which block?\n';
n1 =input(prompt1);%number of avaliable blocks in total
prompt2 = 'end with which block?\n';
n2 =input(prompt2);%number of avaliable blocks in total
stl_files = dir('*.stl');
stl_files = stl_files(~[stl_files.isdir]);
stl_names = {stl_files.name};
numfiles=length(stl_names);
r=rem(numfiles,3);
if r ~= 0
error('each block should have 3 files, some files are missing.')
end
if numfiles ~= 3*(n2-n1+1)
error('The number of blocks is different from blocks in the folder.')
end
%% Main code
disp('Calculating...');
BlockPartName = {};
ErrorAngle = []; %error angles results
flat = []; %flatness results
flat_at_90 = [];
for i=n1:n2
target = sprintf('%d_t.stl',i);%target up
%target1 = sprintf('%d_t_up.stl',i);%target up
%target2 = sprintf('%d_t_bo.stl',i);%target up
cutting1 = sprintf('%d_c_up.stl',i);%cutting up
cutting2 = sprintf('%d_c_bo.stl',i);%cutting botom
try
err1 = angle_error(target,cutting1);
err2 = angle_error(target,cutting2);
fprintf('Block %d up part:%d°.\n',i,err1);
fprintf('Block %d bottoom part:%d°.\n',i,err2);
BlockPartName = [BlockPartName,{cutting1}];
ErrorAngle(end+1)= err1;
[f1,f3] = flatness(cutting1);
flat(end+1)= f1;
flat_at_90(end+1)=f3;
BlockPartName = [BlockPartName,{cutting2}];
ErrorAngle(end+1) = err2;
[f2,f4] = flatness(cutting2);
flat(end+1)=f2;
flat_at_90(end+1)=f4;
catch
warning('Data of Block %d are missing.\n',i);
end
end
ErrorAngle=ErrorAngle';
BlockPartName=BlockPartName';
flat = flat';
flat_at_90=flat_at_90';
T = table(BlockPartName,ErrorAngle,flat,flat_at_90);
%writetable(T,'result_37_40.xls');
writetable(T,'result_new_new.xls');
disp('end');