-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dynapath.cps
322 lines (281 loc) · 9.32 KB
/
Dynapath.cps
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
/*
Dynapath Generic Post Processor
License: GPLv2
Original author: Chris Purola
*/
/*
Additional Info:
This script uses writeWords2 as the Dynapath controllers only allow lines
containing sequence numbers, thus this is the recommended method.
Dynapath controllers do not have concept of comment lines and they must
be omitted.
Text is a maximum of 16 characters of uppercase-only A-Z 0-9, + and .
Tool numbers are 00-99, with Diameter and Height offsets 000-200
*/
// ************************************
// Global needed values for the Post
// ************************************
setCodePage("ascii");
var defaultMachineVendor = "Autocon, Inc";
var defaultMachineModel = "DynaPath 50M";
var defaultMachineDescription = "DynaPath 50M Control System on 3-axis mill";
// Position for manual tool change operation. Machine coordinate relative.
var toolChangePosition = {x: 14, y: 1, z: 14}
allowedCircularPlanes = undefined;
allowHelicalMoves = true;
allowSpiralMoves = true;
capabilities = CAPABILITY_MILLING;
certificationLevel = 2;
description = "Dynapath Generic Post Processor (Milling)";
longDescription = "Dynapath (10/20/30/40/50) Milling Post-Processor";
extension = "nc";
programNameIsInteger = false;
tolerance = 0.0001;
// Current state
var sequenceNumber;
// ******************************************************************
// User-accessible properties in the post configuration setup page
// ******************************************************************
properties = {
useConversational: true,
forceInitialToolChange: false,
useHDToolTable: false,
useM06ForToolChange: true,
startSequenceNumber: 1.000,
// Dynapath control has support to 9999.999 or 10M lines
incrementSequenceAmount: 0.001,
realTolerance: 0.0001,
useWordSeparator: false
};
// ****************************************************
// User-friendly definitions of the above properties
// ****************************************************
propertyDefinitions = {
useConversational: {
title: "Use Conversational",
description: "By default, the DynaPath controller uses a conversational " +
"method of storing programs. This allows easy editing of program on the " +
"onboard editor. The post processor can output in this conversational " +
"language, or in standard EIA/ISO G-Code.",
type: "boolean"
},
forceInitialToolChange: {
title: "Force Initial Tool Change",
description: "Force a full tool change cycle on first programmed tool",
type: "boolean"
},
useHDToolTable: {
title: "Use H and D Tool Numbers",
description: "Some Dynapath controls are set up to use H (height) and " +
"D (diameter) settings as well as T (tool). Use this to output T, H, and D " +
"numbers corresponding to the selected tool if using controller-based height " +
"and/or radius compensation.",
type: "boolean"
},
useM06ForToolChange: {
title: "Use M06 for Tool Change",
description: "If programmed, M06 will call a controller-run subroutine to " +
"initiate a toolchange operation. Setting this will call M06 for every " +
"requested tool change.",
type: "boolean"
},
startSequenceNumber: {
title: "Start Sequenece Number",
description: "Beginning sequence number to use. Setting this greater than 0 " +
"allows adding events before program later. Keep in mind the controller has " +
"a maximum sequence number of 9999.999. (0-9999)",
type: "number"
},
incrementSequenceAmount: {
title: "Incremental Sequence Number Amount",
description: "Amount to increment the sequence number for each line in the " +
"program. This can vary if other commands will be inserted without the need " +
"for renumbering the entire program.",
type: "number"
},
realTolerance: {
title: "Tolerance for calculations",
description: "Smallest increment the machine can produce, numbers will be " +
"truncated to this size when calculating.",
type: "number"
},
useWordSeparator: {
title: "Use Spaces Between Words",
description: "Insert spaces between codes within the block to improve readability",
type: "boolean"
}
};
// ************************
// Helper functions
// ************************
function incSequence() {
// If the max valid sequence number is reached
if (sequenceNumber >= 9999.999) {
// Reset back to default start
sequenceNumber = properties.sequenceNumberStart;
} else {
sequenceNumber += properties.incrementSequenceAmount;
}
}
function writeBlock() {
writeWords2("N" + (sequenceFormat.format(sequenceNumber)), arguments, "$");
incSequence();
}
// *************************
// Format Definitions
// *************************
// N Number sequence
var sequenceFormat = createFormat({decimals:3, trim:false, forceDecimal:true});
// T tool specifier
var toolTFormat = createFormat({decimals:0, zeropad:true, width:2});
// H and D tool specifiers
var toolHDFormat = createFormat({decimals:0, zeropad:true, width:3});
// Unit format
var unitOutputFormat = createFormat({decimals:0});
// XYZ format
var xyzFormat = createFormat({decimals:4, trim:false});
// Feedrate format
var fFormat = createFormat({decimals:4, trim:false});
// *************************
// Modal Variables
// *************************
var unitOutput = createVariable({prefix: "P"}, unitOutputFormat);
var toolOutput = createVariable({prefix: "T"}, toolTFormat);
var coolantOutput = createVariable({prefix: "C"});
var xOutput = createVariable({prefix: "X"}, xyzFormat);
var yOutput = createVariable({prefix: "Y"}, xyzFormat);
var zOutput = createVariable({prefix: "Z"}, xyzFormat);
var fOutput = createVariable({prefix: "F"}, fFormat)
// *************************
// Format Functions
// *************************
// Format comments (output text)
function formatComment(text) {
// Delete all the non-accepted characters, uppercase and truncate
var fixedString = String(text).replace(/[^a-zA-Z0-9\+\.]/gi, "");
return fixedString.substr(0,15).toUpperCase();
}
// Format tool identifiers
function formatTool(toolNum) {
if (properties.useHDToolTable) {
return "T" + toolTFormat.format(toolNum) +
"H" + toolHDFormat.format(toolNum) +
"D" + toolHDFormat.format(toolNum);
} else {
return ("T" + toolTFormat.format(toolNum));
}
}
// ************************
// Writer functions
// ************************
function writeComment(text) {
writeBlock("(T)", formatComment(text));
}
function writeTool(toolNum) {
if (properties.useM06ForToolChange) {
// Call toolchange function
writeBlock("(9)", "M06", formatTool(toolNum));
} else {
writeBlock("(9)", formatTool(toolNum));
}
}
function writeCoolant(coolant) {
// Only output if changed since last command
var coolantCheck = coolantOutput.format(coolant)
if (coolantCheck) {
// Dynapath only turns coolant on or off, 0 = off, 1> = on
if (coolant) {
writeBlock("(9)", "M08");
} else {
writeBlock("(9)", "M09");
}
}
}
// Write spindle on/off/speed codes
// writeSpindle(true,false)
function writeSpindle(spindle) {
// Turn on spindle
if (spindle) {
if (tool.clockwise) {
writeBlock("(9)", "M03", "S" + tool.spindleRPM);
} else {
writeBlock("(9)", "M04", "S" + tool.spindleRPM);
}
} else {
// Spindle off
writeBlock("(9)", "M05");
}
}
// Pause for specified seconds (.1 to 999)
// (spindle spin up, coolant start, etc)
function writeDwell(time) {
writeBlock("(8)", "L" + time);
}
// Write units
function writeUnits(metric) {
writeBlock("(S)", metric);
}
// ****************************
// Sequenced event functions
// ****************************
// Depending on how your controller is programmed and configured,
// you may need to alter the sequence of events by adding or subtracting
// blocks from these sequences.
function changeTool() {
// Figure out if toolchange is needed
var newTool = toolOutput.format(tool.number)
if (newTool) {
if (properties.useM06ForToolChange) {
// Automated tool change
// Coolant off
writeCoolant(0);
// Tell the operator what tool to load
writeComment(tool.getProductId());
// Change tool
writeTool(tool.getNumber());
//Spindle on
writeSpindle(true);
// Coolant on
writeCoolant(tool.getCoolant());
// Optionally dwell to allow spindle and coolant to get going
//writeDwell(2)
} else {
// Manual tool change
}
}
};
// ****************************
// Main event handlers
// ****************************
function onOpen() {
// Handle word separators
if (properties.useWordSeparator) {
setWordSeparator(" ");
} else {
setWordSeparator("");
}
// Set starting sequence
sequenceNumber = properties.startSequenceNumber;
}
function onSection() {
// Check and set units
if (currentSection.hasParameter("operation:metric")) {
writeUnits(unitOutput.format(currentSection.getParameter("operation:metric")));
}
// New section = new action, so call toolchange
changeTool();
}
// Handle Rapid movements
function onRapid(x, y, z) {
var xMove = xOutput.format(x);
var yMove = yOutput.format(y);
var zMove = zOutput.format(z);
writeBlock("(0)", xMove, yMove, zMove);
}
function onLinear(x, y, z, f) {
var xMove = xOutput.format(x);
var yMove = yOutput.format(y);
var zMove = zOutput.format(z);
var fRate = fOutput.format(f);
writeBlock("(1)", xMove, yMove, zMove, fRate);
}