-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
346 lines (340 loc) · 14.8 KB
/
index.php
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
<?
error_reporting(E_ALL);
$mass = isset($_POST['mass']) ? $_POST['mass'] : '2';
$offx = isset($_POST['offx']) ? $_POST['offx'] : '1959.0';
$offy = isset($_POST['offy']) ? $_POST['offy'] : '441.0';
$offz = isset($_POST['offz']) ? $_POST['offz'] : '170.0';
$scalex = isset($_POST['scalex']) ? $_POST['scalex'] : '1.0';
$scaley = isset($_POST['scaley']) ? $_POST['scaley'] : '1.0';
$scalez = isset($_POST['scalez']) ? $_POST['scalez'] : '1.0';
$transx = isset($_POST['transx']) ? $_POST['transx'] : '0';
$transy = isset($_POST['transy']) ? $_POST['transy'] : '0';
$transz = isset($_POST['transz']) ? $_POST['transz'] : '0';
$rotq1 = isset($_POST['rotq1']) ? $_POST['rotq1'] : '0';
$rotq2 = isset($_POST['rotq2']) ? $_POST['rotq2'] : '0';
$rotq3 = isset($_POST['rotq3']) ? $_POST['rotq3'] : '1';
$rotq4 = isset($_POST['rotq4']) ? $_POST['rotq4'] : '0';
$cogx = isset($_POST['cogx']) ? $_POST['cogx'] : '0';
$cogy = isset($_POST['cogy']) ? $_POST['cogy'] : '0';
$cogz = isset($_POST['cogz']) ? $_POST['cogz'] : '250';
$aomq1 = isset($_POST['aomq1']) ? $_POST['aomq1'] : '1';
$aomq2 = isset($_POST['aomq2']) ? $_POST['aomq2'] : '0';
$aomq3 = isset($_POST['aomq3']) ? $_POST['aomq3'] : '0';
$aomq4 = isset($_POST['aomq4']) ? $_POST['aomq4'] : '0';
$ix = isset($_POST['ix']) ? $_POST['ix'] : '2';
$iy = isset($_POST['iy']) ? $_POST['iy'] : '2';
$iz = isset($_POST['iz']) ? $_POST['iz'] : '2';
$uframex = isset($_POST['uframex']) ? $_POST['uframex'] : '1500';
$uframey = isset($_POST['uframey']) ? $_POST['uframey'] : '500';
$uframez = isset($_POST['uframez']) ? $_POST['uframez'] : '0';
$uframeq1 = isset($_POST['uframeq1']) ? $_POST['uframeq1'] : '1';
$uframeq2 = isset($_POST['uframeq2']) ? $_POST['uframeq2'] : '0';
$uframeq3 = isset($_POST['uframeq3']) ? $_POST['uframeq3'] : '0';
$uframeq4 = isset($_POST['uframeq4']) ? $_POST['uframeq4'] : '0';
$oframex = isset($_POST['oframex']) ? $_POST['oframex'] : '0';
$oframey = isset($_POST['oframey']) ? $_POST['oframey'] : '0';
$oframez = isset($_POST['oframez']) ? $_POST['oframez'] : '0';
$oframeq1 = isset($_POST['oframeq1']) ? $_POST['oframeq1'] : '1';
$oframeq2 = isset($_POST['oframeq2']) ? $_POST['oframeq2'] : '0';
$oframeq3 = isset($_POST['oframeq3']) ? $_POST['oframeq3'] : '0';
$oframeq4 = isset($_POST['oframeq4']) ? $_POST['oframeq4'] : '0';
$speed = isset($_POST['speed']) ? $_POST['speed'] : 'v100';
$zone = isset($_POST['zone']) ? $_POST['zone'] : 'z5';
$moveorig = isset($_POST['submit']) ? (isset($_POST['moveorig']) && $_POST['moveorig']=='on') : true;
$paramz = isset($_POST['submit']) ? (isset($_POST['paramz']) && $_POST['paramz']=='on') : false;
$tool0 = isset($_POST['tool']) && $_POST['tool']=='tool0' ? true : false;
$limit = isset($_POST['limit']) ? $_POST['limit'] : '100000';
$error = '';
if (isset($_POST['submit']) && isset($_FILES['gcodefile']['tmp_name'])) switch($_FILES["gcodefile"]["error"]) {
case UPLOAD_ERR_INI_SIZE:
$error = 'The uploaded file exceeds '.ini_get('upload_max_filesize').'<br/>';
break;
case UPLOAD_ERR_PARTIAL:
$error = 'The uploaded file was only partially uploaded.<br/>';
break;
case UPLOAD_ERR_NO_FILE:
$error = 'No file was uploaded.<br/>';
break;
case UPLOAD_ERR_OK:
// protection against uploading of serverside scripts
if (preg_match('/\.(php|asp|pl|cgi|java|cfm)$/i',$_FILES['gcodefile']['tmp_name'])) $error.= "Not allowed to upload serverside scripts!<br/>";
else {
$gcodefile = fopen($_FILES['gcodefile']['tmp_name'], "r");
if (!$gcodefile) $error.= 'Could not open the gcode file ('.$gcodefile.').<br/>';
else {
$filename = str_replace(' ', '_', pathinfo($_FILES['gcodefile']['name'])['filename']);
header('Content-Type: application/json; charset=UTF-8');
header('Content-Disposition: attachment; filename="'.$filename.'.mod'.'"');
echo "%%%\r\n";
echo " VERSION:1\r\n";
echo " LANGUAGE:ENGLISH\r\n";
echo "%%%\r\n";
echo "! gcode2rapid conversion tool by Harmen G. Zijp\r\n";
echo "! www.giplt.nl/cgode2robot\r\n";
echo "MODULE ".$filename."\r\n";
if (!$tool0) echo " LOCAL PERS tooldata gTool:=[TRUE,[[".$transx.",".$transy.",".$transz."],[".$rotq1.",".$rotq2.",".$rotq3.",".$rotq4."]],[".$mass.",[".$cogx.",".$cogy.",".$cogz."],[".$aomq1.",".$aomq2.",".$aomq3.",".$aomq4."],".$ix.",".$iy.",".$iz."]];\r\n";
echo " LOCAL PERS wobjdata gWobj:=[FALSE,TRUE,\"\",[[".$uframex.",".$uframey.",".$uframez."],[".$uframeq1.",".$uframeq2.",".$uframeq3.",".$uframeq4."]],[[".$oframex.",".$oframey.",".$oframez."],[".$oframeq1.",".$oframeq2.",".$oframeq3.",".$oframeq4."]]];\r\n";
echo "\r\n";
echo " LOCAL VAR orient gOrient:=[1,0,0,0];\r\n";
echo " LOCAL VAR confdata gConfData:=[0,-1,0,0];\r\n";
echo " LOCAL VAR extjoint gExtJoint:=[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09];\r\n";
echo "\r\n";
echo " PROC ".$filename."_proc()\r\n";
echo " VAR iodev serial;";
echo " Open \"COM3:\", serial\\Write;";
while (($line = fgets($gcodefile)) !== false) {
$words = explode(' ', $line);
switch($words[0][0]) {
case ';':
break;
case 'G':
switch(substr($words[0], 1)) {
case '0':
case '1':
foreach($words as $word) if ($word) switch($word[0]) {
case 'X':
$x = substr($word, 1);
break;
case 'Y':
$y = substr($word, 1);
break;
case 'Z':
$z = substr($word, 1);
break;
case 'F':
break;
case 'E':
$e = substr($word, 1);
break;
default:
break;
}
if (isset($x) && isset($y) && isset($z)) $path[] = Array("x"=>$x, "y"=>$y, "z"=>$z, "e"=>$e);
break;
default:
break;
}
break;
case 'M':
break;
default:
break;
}
}
$minx = $maxx = $path[0]['x'];
$miny = $maxy = $path[0]['y'];
$minz = $maxz = $path[0]['z'];
if ($paramz) {
$zvals = array();
$dzvals = array();
}
foreach($path as $position) {
if ($paramz) {
if (!isset($zvals[$position['z']])) $zvals[$position['z']] = 1;
else $zvals[$position['z']] ++;
}
$minx = min($minx, $position['x']);
$maxx = max($maxx, $position['x']);
$miny = min($miny, $position['y']);
$maxy = max($maxy, $position['y']);
$minz = min($minz, $position['z']);
$maxz = max($maxz, $position['z']);
}
if ($paramz) {
$zvals = array_keys($zvals);
$j = 0;
for($i=1; $i<count($zvals); $i++) {
$dz = $zvals[$i] - $zvals[$i-1];
if (!isset($dzvals[$dz])) {
$dzvals[$dz] = 'dh'.$j;
$j++;
}
}
foreach($dzvals as $dz => $varname) echo " LOCAL VAR num ".$varname.":=".$dz.";\r\n";
}
$steps = 0;
$lastz = 0;
foreach($path as $position) {
$x = $moveorig ? $position['x'] - $minx : $position['x'];
$y = $moveorig ? $position['y'] - $miny : $position['y'];
$z = $moveorig ? $position['z'] - $minz : $position['z'];
if ($paramz) {
if($steps==0) echo " LOCAL VAR num h:=".$z.";\r\n";
elseif($z!=$lastz) echo " h:=h+".$dzvals[$z-$lastz].";\r\n";
}
echo " Write serial, NumToStr(".$position['e'].", 3);";
if ($tool0) echo " MoveL [[".$x.",".$y.",".($paramz?"h":$z)."],gOrient,gConfData,gExtJoint],".$speed.",".$zone.",tool0\\WObj:=gWobj;\r\n";
else echo " MoveL [[".$x.",".$y.",".($paramz?"h":$z)."],gOrient,gConfData,gExtJoint],".$speed.",".$zone.",gTool\\WObj:=gWobj;\r\n";
$lastz = $z;
$steps++;
if ($steps==$limit) {
$error = 'Rapid output limited to '.$limit.' move instructions.<br/>';
break;
}
}
fclose($gcodefile);
echo " Close serial;";
echo " ENDPROC\r\n";
echo "\r\n";
echo " PROC Main()\r\n";
echo " ENDPROC\r\n";
echo "ENDMODULE\r\n";
exit;
}
}
break;
default:
$error = 'Unknown error with uploading file.<br/>';
break;
}
if (isset($rapidfile) && file_exists($filename.".mod")) {
header('Content-Type: application/octet-stream');
header("Content-Disposition: attachment; filename=".$filename.".mod");
readfile($filename.".mod");
exit;
}
?>
<!DOCTYPE html>
<html lang="nl">
<head>
<meta charset="UTF-8" />
<title>gcode2robot</title>
<style>
th td {vertical-align:top;}
.l {text-align:left;}
.r {text-align:right;}
.number {width:70px; text-align:right;}
.tool {display:none;}
</style>
<script>
function setToolState(state) {
var trs = document.getElementsByTagName("tr");
for(var i=0; i<trs.length; i++) if(trs[i].className=="tool") trs[i].style.display = (state=="show" ? "table-row" : "none");
}
</script>
</head>
<body>
<h1>gcode2robot conversion</h1>
<?if ($error) echo '<span style="color:red;">Error: '.$error.'</span>';?>
<form method="post" action="" enctype="multipart/form-data">
<table>
<tr>
<td class="r">Source file</td>
<td class="l" colspan="7"><input type="file" name="gcodefile"/></td>
</tr>
<tr>
<td class="r">Limit (steps)</td>
<td class="l"><input type="text" class="number" name="limit" value="<?echo $limit;?>"/></td>
<td class="r">Speed</td>
<td class="l"><input type="text" class="number" name="speed" value="<?echo $speed;?>"/></td>
<td class="r">Zone</td>
<td class="l"><input type="text" class="number" name="zone" value="<?echo $zone;?>"/></td>
</tr>
<tr>
<td></td>
<td class="l" colspan="5"><input type="checkbox" name="moveorig" <?if ($moveorig) echo 'checked="checked"';?>/> Offset gcode to origin of work object</td>
</tr>
<tr>
<td></td>
<td class="l" colspan="5"><input type="checkbox" name="paramz" <?if ($paramz) echo 'checked="checked"';?>/> Parametrize layer height</td>
<td colspan="2"><input type="submit" name="submit" value="Create ABB RAPID file"/></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<th class="l">Tool data</th>
<td colspan=7><input type="radio" name="tool" value="tool0" checked="checked" onclick="setToolState('hide');"/>tool0 <input type="radio" name="tool" value="gtool" onclick="setToolState('show');"/>custom</td>
</tr>
<tr class="tool">
<th></th>
<th colspan="3" style="text-align:center;">coordinates (mm)</th>
<th colspan="4" style="text-align:center;">orientation (quaternions)</th>
</tr>
<tr class="tool">
<td></td>
<th>x</th>
<th>y</th>
<th>z</th>
<th>q1</th>
<th>q2</th>
<th>q3</th>
<th>q4</th>
</tr>
<tr class="tool">
<td class="r">Tool Center Point</td>
<td><input type="text" class="number" name="transx" value="<?echo $transx;?>"/></td>
<td><input type="text" class="number" name="transy" value="<?echo $transy;?>"/></td>
<td><input type="text" class="number" name="transz" value="<?echo $transz;?>"/></td>
<td><input type="text" class="number" name="rotq1" value="<?echo $rotq1;?>"/></td>
<td><input type="text" class="number" name="rotq2" value="<?echo $rotq2;?>"/></td>
<td><input type="text" class="number" name="rotq3" value="<?echo $rotq3;?>"/></td>
<td><input type="text" class="number" name="rotq4" value="<?echo $rotq4;?>"/></td>
</tr>
<tr class="tool">
<td class="r">Center Of Gravity</td>
<td><input type="text" class="number" name="cogx" value="<?echo $cogx;?>"/></td>
<td><input type="text" class="number" name="cogy" value="<?echo $cogy;?>"/></td>
<td><input type="text" class="number" name="cogz" value="<?echo $cogz;?>"/></td>
<td><input type="text" class="number" name="aomq1" value="<?echo $aomq1;?>"/></td>
<td><input type="text" class="number" name="aomq2" value="<?echo $aomq2;?>"/></td>
<td><input type="text" class="number" name="aomq3" value="<?echo $aomq3;?>"/></td>
<td><input type="text" class="number" name="aomq4" value="<?echo $aomq4;?>"/></td>
</tr>
<tr class="tool">
<td class="r">Moment Of Inertia</td>
<td><input type="text" class="number" name="ix" value="<?echo $ix;?>"/></td>
<td><input type="text" class="number" name="iy" value="<?echo $iy;?>"/></td>
<td><input type="text" class="number" name="iz" value="<?echo $iz;?>"/></td>
</tr>
<tr class="tool">
<td class="r">Mass (kg)</td>
<td class="l"><input type="text" class="number" name="mass" value="<?echo $mass;?>"/></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<th class="l">Work object data</th>
<th colspan="3" style="text-align:center;">coordinates (mm)</th>
<th colspan="4" style="text-align:center;">orientation (quaternions)</th>
</tr>
<tr>
<td></td>
<th>x</th>
<th>y</th>
<th>z</th>
<th>q1</th>
<th>q2</th>
<th>q3</th>
<th>q4</th>
</tr>
<tr>
<td class="r">User Frame</td>
<td><input type="text" class="number" name="uframex" value="<?echo $uframex;?>"/></td>
<td><input type="text" class="number" name="uframey" value="<?echo $uframey;?>"/></td>
<td><input type="text" class="number" name="uframez" value="<?echo $uframez;?>"/></td>
<td><input type="text" class="number" name="uframeq1" value="<?echo $uframeq1;?>"/></td>
<td><input type="text" class="number" name="uframeq2" value="<?echo $uframeq2;?>"/></td>
<td><input type="text" class="number" name="uframeq3" value="<?echo $uframeq3;?>"/></td>
<td><input type="text" class="number" name="uframeq4" value="<?echo $uframeq4;?>"/></td>
</tr>
<tr>
<td class="r">Object Frame</td>
<td><input type="text" class="number" name="oframex" value="<?echo $oframex;?>"/></td>
<td><input type="text" class="number" name="oframey" value="<?echo $oframey;?>"/></td>
<td><input type="text" class="number" name="oframez" value="<?echo $oframez;?>"/></td>
<td><input type="text" class="number" name="oframeq1" value="<?echo $oframeq1;?>"/></td>
<td><input type="text" class="number" name="oframeq2" value="<?echo $oframeq2;?>"/></td>
<td><input type="text" class="number" name="oframeq3" value="<?echo $oframeq3;?>"/></td>
<td><input type="text" class="number" name="oframeq4" value="<?echo $oframeq4;?>"/></td>
</tr>
<tr>
<td></td>
<td colspan="7" rowspan="4"><img src="http://developercenter.robotstudio.com/BlobProxy/manuals/RapidIFDTechRefManual/images/xx0500002369-47702-604.png" /></td>
</tr>
</table>
</form>
<?if (isset($rapidfile) && file_exists($filename.".mod")) echo '<p/>download <a href="'.$filename.'.mod">'.$filename.'.mod</a></br/>';?>
</body>
</html>