This repository has been archived by the owner on Apr 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 274
/
Copy pathPolyPathGCodeTools.js
125 lines (109 loc) · 3.75 KB
/
PolyPathGCodeTools.js
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
/*
Copyright 2013 Google Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
exports.PolyPathGCodeTools = {};
var PolyPathGCodeTools = exports.PolyPathGCodeTools;
//similar to drawPolyPath() but generates a gcode program
exports.PolyPathGCodeTools.gcodeFromPolyPath = function(polyPath) {
var gcode = '';
function appendLine(str) {
gcode += str + '\n';
}
function appendComment(str) {
appendLine('( ' + str + ' )');
}
function appendCommand(args) {
var cmdStr = args.cmd;
for (var n in args) {
if (n != 'cmd') {
cmdStr += ' ' + n;
if (Math.round(args[n]).toString() == args[n].toString())
cmdStr += (n + '.0');
else
cmdStr += n.toString();
}
}
}
var xOffset = 0; - 1 * (ConfigParams.CAM_X / 2);
var yOffset = 0; - 1 * (ConfigParams.CAM_Y / 2);
appendComment('Generated by robotcontrol');
appendComment('');
var fDrawing = 900; // feed rate while drawing
var fTraveling = 3000; // feed rate while traveling
var zDrawing = 0; // Z axis for drawing moves (mm)
var zTraveling = 100; // Z axis for travel moves (mm)
var eDrawing = 1; // (e)xtruder setting while drawing
var eTraveling = 0; // (e)xtruder setting while traveling
// preamble
appendComment('prepare machine state');
appendCommand({
cmd: 'G92',
e: 0
}); // reset extruder
appendCommand({
cmd: 'G90'
}); // absolute coordinate system
appendCommand({
cmd: 'M82'
}); // absolute mode for extruder, too
appendCommand({
cmd: 'G21'
}); // units are mm
appendCommand({
cmd: 'G92',
e: 0.0
}); // reset extruder again... not sure why this is needed, but most gcode does this
appendComment('beginning of drawing');
for (var i = 0; i < polyPath.length; i++) {
appendComment('beginning of line segment ' + i + ' of ' + polyPath.length);
var path = polyPath[i];
appendCommand({
cmd: 'G1',
z: zTraveling,
f: fTraveling
});
var point = null;
for (var j = 0; j < path.length; j++) {
point = path[j];
if (j == 0) {
//first point on a new path, so move the tool above the drawing point but above the workpiece
appendCommand({
cmd: 'G1',
x: (point.x + xOffset),
y: (point.y + yOffset),
z: zTraveling,
f: fTraveling
});
}
appendCommand({
cmd: 'G1',
x: (point.x + xOffset),
y: (point.y + yOffset),
z: zDrawing,
f: fDrawing
});
}
if (point != null) {
//end of line, raise the tool
appendCommand({
cmd: 'G1',
x: (point.x + xOffset),
y: (point.y + yOffset),
z: zTraveling,
f: fTraveling
});
}
appendComment('end of line segment ' + i + ' of ' + polyPath.length);
}
appendComment('end of drawing');
return gcode;
};