-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.m
188 lines (169 loc) · 5.75 KB
/
parser.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
function parser(handles,gcode_texts,D,lc,ls,rb,re,Pz)
cvector = strsplit(gcode_texts,'\n');
Xt_old = '';
Yt_old = '';
Zt_old = '';
Et_old = '';
Ft_old = '';
At_old = '';
Bt_old = '';
Ct_old = '';
clearDebugMessage(handles);
i_counter=0;
for cindex=1:length(cvector)
cline = cvector(cindex);
cline = cline{1};
[startIndex,endIndex] = regexp(cline,'^G\d*');
if(~isempty(startIndex))
% Check for cancellation
abort=get(handles.slider_abort,'Value');
if(abort==1)
set(handles.slider_abort,'Value',0);
set(handles.slider_if_running,'Value',0);
return;
end
Gcommand = cline(startIndex:endIndex);
switch Gcommand
case 'G0' % Rapid linear Move
%disp 'linear move';
linear_move(handles,cline,cline(endIndex+1:length(cline)),i_counter);
case 'G1' % Linear Move
%disp 'linear move';
linear_move(handles,cline,cline(endIndex+1:length(cline)),i_counter);
case 'G161' % Home axes to minimum
%disp 'home axes';
case 'G162' % Home axes to maximum
%disp 'home axes';
case 'G92' % Set Position
%disp 'set position';
case 'G130' % Set digital potentiometer value
%disp 'do nothing';
end
end
i_counter=i_counter+1;
end
% Finalization
handles.runnning=0;
function linear_move(handles,cline,coords,i_counter)
% disp(coords);
[x_st_index,x_end_index] = regexp(coords,'X[\d\.]*?\s');
[y_st_index,y_end_index] = regexp(coords,'Y[\d\.]*?\s');
[z_st_index,z_end_index] = regexp(coords,'Z[\d\.]*?\s');
[e_st_index,e_end_index] = regexp(coords,'E[\d\.]*?\s');
[f_st_index,f_end_index] = regexp(coords,'F[\d\.]*?\s');
[a_st_index,a_end_index] = regexp(coords,'A[\d\.]*?\s');
[b_st_index,b_end_index] = regexp(coords,'B[\d\.]*?\s');
[c_st_index,c_end_index] = regexp(coords,'C[\d\.]*?\s');
if(~isempty(x_st_index))
Xt = coords(x_st_index+1:x_end_index);
elseif(~isempty(Xt_old))
Xt = Xt_old;
else
Xt = '0';
end
if(~isempty(y_st_index))
Yt = coords(y_st_index+1:y_end_index);
elseif(~isempty(Yt_old))
Yt = Yt_old;
else
Yt = '0';
end
if(~isempty(z_st_index))
Zt = coords(z_st_index+1:z_end_index);
elseif(~isempty(Zt_old))
Zt = Zt_old;
else
Zt = '0';
end
if(~isempty(e_st_index))
Et = coords(e_st_index+1:e_end_index);
elseif(~isempty(Et_old))
Et = Et_old;
else
Et = '0';
end
if(~isempty(f_st_index))
Ft = coords(f_st_index+1:f_end_index);
elseif(~isempty(Ft_old))
Ft = Ft_old;
else
Ft = '0';
end
if(~isempty(a_st_index))
At = coords(a_st_index+1:a_end_index);
elseif(~isempty(At_old))
At = At_old;
else
At = '0';
end
if(~isempty(b_st_index))
Bt = coords(b_st_index+1:b_end_index);
elseif(~isempty(Bt_old))
Bt = Bt_old;
else
Bt = '0';
end
if(~isempty(c_st_index))
Ct = coords(c_st_index+1:c_end_index);
elseif(~isempty(Ct_old))
Ct = Ct_old;
else
Ct = '0';
end
% P = [0.1-i_time/200,0.2+i_time/200,Pz]; % Position Vector of the end effector
% phi = pi/12*(i_time/10); % rotation around X axis
% theta = pi/12*(i_time/10); % rotation around Y axis
% psi = pi/16*(i_time/10); % rotation around Z axis
Xt_n = str2double(Xt);
Yt_n = str2double(Yt);
Zt_n = str2double(Zt);
Et_n = str2double(Et);
Ft_n = str2double(Ft);
At_n = str2double(At);
Bt_n = str2double(Bt);
Ct_n = str2double(Ct);
At_rad = At_n*pi/180.0;
Bt_rad = Bt_n*pi/180.0;
Ct_rad = Ct_n*pi/180.0;
P = [Xt_n Yt_n Pz+Zt_n];
C = computeSliderControl(D,lc,ls,rb,re,P,At_rad,Bt_rad,Ct_rad);
% if check==1
% showDebugMessage(i_time,phi,theta,psi,C);
% end
drawnow;
Xt_old = Xt;
Yt_old = Yt;
Zt_old = Zt;
Et_old = Et;
Ft_old = Ft;
At_old = At;
Bt_old = Bt;
Ct_old = Ct;
checked=get(handles.checkbox_debug,'Value');
if(checked==1)
showDebugMessage(handles,cline,i_counter,At_rad,Bt_rad,Ct_rad,C);
else
clearDebugMessage(handles);
end
end
function clearDebugMessage(handles)
set(handles.text_angle,'String','');
set(handles.text_scontrol,'String','');
set(handles.text_gcode_run,'String','');
end
function showDebugMessage(handles,cline,i_time,phi,theta,psi,C)
cline = strtrim(cline);
msg = sprintf(strcat('%d frame elapsed\n',...
'x-angle: %.2f[rad]\n',...
'y-angle: %.2f[rad]\n',...
'z-angle: %.2f[rad]\n'),i_time,phi,theta,psi);
msg2 = sprintf(strcat('Slider control\n',...
'c1: %.2f, c2: %.2f\n',...
'c3: %.2f, c4: %.2f\n',...
'c5: %.2f, c6: %.2f\n'),C(1),C(2),C(3),C(4),C(5),C(6));
msg3 = sprintf(strcat('Running G-code:\n','%s'),cline);
set(handles.text_angle,'String',msg);
set(handles.text_scontrol,'String',msg2);
set(handles.text_gcode_run,'String',msg3);
end
end