-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSimP_Sequence2.cps
More file actions
388 lines (345 loc) · 12.6 KB
/
SimP_Sequence2.cps
File metadata and controls
388 lines (345 loc) · 12.6 KB
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
/**
Copyright (C) 2012-2014 by Autodesk, Inc.
All rights reserved.
Minimal post processor configuration.
$Revision: 40941 d23033c3af7c1d3a5723876fd4bd23be0cdb24b5 $
$Date: 2016-01-16 19:30:18 $
FORKID {96F3CC76-19C0-4828-BF27-6A50AED3B187}
*/
description = "Minimal Heidenhain";
vendor = "Autodesk";
vendorUrl = "http://www.autodesk.com";
legal = "Copyright (C) 2012-2014 by Autodesk, Inc.";
certificationLevel = 2;
extension = "simpl";
setCodePage("utf-8");
var spindleAxisTable = new Table(["X", "Y", "Z"], {force:true});
var radiusCompensationTable = new Table(
[" R0", " RL", " RR"],
{initial:RADIUS_COMPENSATION_OFF},
"Invalid radius compensation"
);
minimumChordLength = spatial(0.01, MM);
minimumCircularRadius = spatial(0.01, MM);
maximumCircularRadius = spatial(1000, MM);
minimumCircularSweep = toRad(0.01);
maximumCircularSweep = toRad(120);
allowHelicalMoves = true;
allowedCircularPlanes = (1 << PLANE_XY); // allow XY plane only
var xyzFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true});
var feedFormat = createFormat({decimals:(unit == MM ? 0 : 2), scale:(unit == MM ? 1 : 10)});
var rpmFormat = createFormat({decimals:0});
var mFormat = createFormat({prefix:"M", decimals:0});
var toolFormat = createFormat({decimals:0});
var workpieceFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceSign:true, trim:false});
var dimensionFormat = createFormat({decimals:(unit == MM ? 3 : 5), forceDecimal:false});
var xOutput = createVariable({prefix:" X="}, xyzFormat);
var yOutput = createVariable({prefix:" Y="}, xyzFormat);
var zOutput = createVariable({prefix:" Z="}, xyzFormat);
var iOutput = createVariable({prefix:" dX=", force : true}, feedFormat);
var jOutput = createVariable({prefix:" dY=", force : true}, feedFormat);
var kOutput = createVariable({prefix:" dZ="}, feedFormat);
var feedOutput = createVariable({prefix:"Feed="}, feedFormat);
var blockNumber = 0;
/**
Writes the specified block.
*/
function writeBlock(block) {
writeln(block);
}
function onOpen() {
writeBlock("module SimPlSequence" + (programName ? (programName) : ""));
writeBlock("");
createToolDescriptionTable();
writeBlock("");
writeWorkpiece();
writeBlock("");
writeBlock((unit == MM) ? "@ MeasuringSystem = \"Metric\" @" : " @ MeasuringSystem = \"Inch\" @");
writeBlock("");
writeBlock("sequence SimPLSequence");
writeBlock("");
writeBlock("using Base");
writeBlock("");
writeBlock("export program Main");
writeBlock(" Spindle On"); // spindle on - clockwise
writeBlock(" SimPLSequence");
writeBlock("endprogram");
writeBlock("");
writeBlock("end");
writeBlock("");
writeBlock("$$$SimPLSequence");
}
/**
Invalidates the current position and feedrate. Invoke this function to
force X, Y, Z, and F in the following block.
*/
function invalidate() {
xOutput.reset();
yOutput.reset();
zOutput.reset();
feedOutput.reset();
}
function onSection() {
//TODO
writeBlock("MoveToSafetyPosition");
var retracted = true;
writeBlock("Tool name=" + "\"" + createToolName(tool) + "\"" +
" newRpm=" + rpmFormat.format(tool.spindleRPM) +
" skipRestoring"
);
setTranslation(currentSection.workOrigin);
setRotation(currentSection.workPlane);
invalidate();
var initialPosition = getFramePosition(currentSection.getInitialPosition());
if (!retracted) {
if (getCurrentPosition().z < initialPosition.z) {
writeBlock("Rapid" + zOutput.format(initialPosition.z));
}
}
writeBlock("Line" + xOutput.format(initialPosition.x) + yOutput.format(initialPosition.y) + zOutput.format(initialPosition.z));
}
function onRapid(x, y, z) {
var xyz = xOutput.format(x) + yOutput.format(y) + zOutput.format(z);
if (xyz) {
writeBlock("Rapid" + xyz);
feedOutput.reset();
}
}
function onLinear(x, y, z, feed) {
var xyz = xOutput.format(x) + yOutput.format(y) + zOutput.format(z);
var f = feedOutput.format(feed);
if(f){
writeBlock(f);
}
if (xyz) {
writeBlock("Line" + xyz);
}
}
function onSectionEnd() {
// full retract in machine coordinate system
writeBlock("MoveToSafetyPosition");
invalidate();
}
function onClose() {
writeBlock("Spindle Off"); // stop program, spindle stop, coolant off
}
function createToolDescriptionTable() {
var toolDescriptionArray = new Array();
var toolNameList = new Array();
var numberOfSections = getNumberOfSections();
for (var i = 0; i < numberOfSections; ++i) {
var section = getSection(i);
var tool = section.getTool();
if (tool.type != TOOL_PROBE) {
var toolName = createToolName(tool);
var toolProgrammed = createToolDescription(tool);
if (toolNameList.indexOf(toolName) == -1) {
toolNameList.push(toolName);
toolDescriptionArray.push(toolProgrammed);
} else {
/*
if (toolDescriptionArray.indexOf(toolProgrammed) == -1) {
error("\r\n#####################################\r\nOne ore more tools have the same name!\r\nPlease change the tool number to make the name unique.\r\n" + toolDescriptionArray.join("\r\n") + "\r\n\r\n" +
toolNameList.join("\r\n") + "#####################################\r\n");
}
*/
}
}
}
writeBlock(toolDescriptionArray.join("\r\n"));
}
function createToolDescription(tool) {
var toolProgrammed = "@ ToolDescription : " +
"\"" + "Name" + "\"" + ":" + "\"" + createToolName(tool) + "\"" + ", " +
"\"" + "Category" + "\"" + ":" + "\"" + translateToolType(tool.type) + "\"" + ", " +
"\"" + "ArticleNr" + "\"" + ":" + "\"" + tool.productId + "\"" + ", " +
"\"" + "ToolNumber" + "\"" + ":" + toolFormat.format(tool.number) + ", " +
"\"" + "Vendor" + "\"" + ":" + "\"" + tool.vendor + "\"" + ", " +
"\"" + "Diameter" + "\"" + ":" + dimensionFormat.format(tool.diameter) + ", " +
"\"" + "TipAngle" + "\"" + ":" + dimensionFormat.format(toDeg(tool.taperAngle)) + ", " +
"\"" + "TipDiameter" + "\"" + ":" + dimensionFormat.format(tool.tipDiameter) + ", " +
"\"" + "FluteLength" + "\"" + ":" + dimensionFormat.format(tool.fluteLength) + ", " +
"\"" + "CornerRadius" + "\"" + ":" + dimensionFormat.format(tool.cornerRadius) + ", " +
"\"" + "ShoulderLength" + "\"" + ":" + dimensionFormat.format(tool.shoulderLength) + ", " +
"\"" + "ShoulderDiameter" + "\"" + ":" + dimensionFormat.format(tool.diameter) + ", " +
"\"" + "BodyLength" + "\"" + ":" + dimensionFormat.format(tool.bodyLength) + ", " +
"\"" + "NumberOfFlutes" + "\"" + ":" + toolFormat.format(tool.numberOfFlutes) + ", " +
"\"" + "ThreadPitch" + "\"" + ":" + dimensionFormat.format(tool.threadPitch) + ", " +
"\"" + "ShaftDiameter" + "\"" + ":" + dimensionFormat.format(tool.shaftDiameter) + ", " +
"\"" + "OverallLength" + "\"" + ":" + dimensionFormat.format(tool.bodyLength + 2 * tool.shaftDiameter) +
" @";
return toolProgrammed;
}
/**
Generate the logical tool name for the assignment table of used tools.
*/
function createToolName(tool) {
var toolName = toolFormat.format(tool.number);
toolName += "_" + translateToolType(tool.type);
if (tool.comment) {
toolName += "_" + tool.comment;
}
if (tool.diameter) {
toolName += "_D" + tool.diameter;
}
var description = tool.getDescription();
if (description) {
toolName += "_" + description;
}
toolName = formatVariable(toolName);
return toolName;
}
/**
Translate HSM tools to Datron tool categories.
*/
function translateToolType(toolType) {
var datronCategoryName = "";
toolCategory = toolType;
switch (toolType) {
case TOOL_UNSPECIFIED:
datronCategoryName = "Unspecified";
break;
case TOOL_DRILL:
datronCategoryName = "Drill";
break;
case TOOL_DRILL_CENTER:
datronCategoryName = "DrillCenter";
break;
case TOOL_DRILL_SPOT:
datronCategoryName = "DrillSpot";
break;
case TOOL_DRILL_BLOCK:
datronCategoryName = "DrillBlock";
break;
case TOOL_MILLING_END_FLAT:
datronCategoryName = "MillingEndFlat";
break;
case TOOL_MILLING_END_BALL:
datronCategoryName = "MillingEndBall";
break;
case TOOL_MILLING_END_BULLNOSE:
datronCategoryName = "MillingEndBullnose";
break;
case TOOL_MILLING_CHAMFER:
datronCategoryName = "Graver";
break;
case TOOL_MILLING_FACE:
datronCategoryName = "MillingFace";
break;
case TOOL_MILLING_SLOT:
datronCategoryName = "MillingSlot";
break;
case TOOL_MILLING_RADIUS:
datronCategoryName = "MillingRadius";
break;
case TOOL_MILLING_DOVETAIL:
datronCategoryName = "MillingDovetail";
break;
case TOOL_MILLING_TAPERED:
datronCategoryName = "MillingTapered";
break;
case TOOL_MILLING_LOLLIPOP:
datronCategoryName = "MillingLollipop";
break;
case TOOL_TAP_RIGHT_HAND:
datronCategoryName = "TapRightHand";
break;
case TOOL_TAP_LEFT_HAND:
datronCategoryName = "TapLeftHand";
break;
case TOOL_REAMER:
datronCategoryName = "Reamer";
break;
case TOOL_BORING_BAR:
datronCategoryName = "BoringBar";
break;
case TOOL_COUNTER_BORE:
datronCategoryName = "CounterBore";
break;
case TOOL_COUNTER_SINK:
datronCategoryName = "CounterSink";
break;
case TOOL_HOLDER_ONLY:
datronCategoryName = "HolderOnly";
break;
case TOOL_PROBE:
datronCategoryName = "XYZSensor";
break;
default:
datronCategoryName = "Unspecified";
}
return datronCategoryName;
}
function formatVariable(text) {
return String(text).replace(/[^A-Za-z0-9\-_]/g, "");
}
function writeWorkpiece() {
var workpiece = getWorkpiece();
var delta = Vector.diff(workpiece.upper, workpiece.lower);
writeBlock("# Workpiece dimensions");
writeBlock(
"# min: X: " + workpieceFormat.format(workpiece.lower.x) + ";" +
" Y: " + workpieceFormat.format(workpiece.lower.y) + ";" +
" Z: " + workpieceFormat.format(workpiece.lower.z));
writeBlock(
"# max: X: " + workpieceFormat.format(workpiece.upper.x) + ";" +
" Y: " + workpieceFormat.format(workpiece.upper.y) + ";" +
" Z: " + workpieceFormat.format(workpiece.upper.z));
writeBlock(
"# Part size X: " + workpieceFormat.format(delta.x) + ";" +
" Y: " + workpieceFormat.format(delta.y) + ";" +
" Z: " + workpieceFormat.format(delta.z));
writeBlock("@ WorkpieceGeometry : " + "\"" + "MinEdge" + "\"" + ":{" + "\"" + "X" + "\"" + ":" + workpieceFormat.format(workpiece.lower.x) + "," +
"\"" + "Y" + "\"" + ":" + workpieceFormat.format(workpiece.lower.y) + "," +
"\"" + "Z" + "\"" + ":" + workpieceFormat.format(workpiece.lower.z) + "}," +
"\"" + "MaxEdge" + "\"" + ":{" + "\"" +"X" + "\"" + ":" + workpieceFormat.format(workpiece.upper.x) + "," +
"\"" + "Y" + "\"" + ":" + workpieceFormat.format(workpiece.upper.y) + "," +
"\"" + "Z" + "\"" + ":" + workpieceFormat.format(workpiece.upper.z) + "}" +
" @");
writeBlock(" ");
}
function onCircular(clockwise, cx, cy, cz, x, y, z, feed) {
var f = feedOutput.format(feed);
if(f){
writeBlock(f);
}
// if (pendingRadiusCompensation >= 0) {
// error(localize("radius compensation cannot be activated/deactivated for a circular move."));
// return;
// }
var start = getCurrentPosition();
if (isFullCircle()) {
if (isHelical()) {
linearize(tolerance);
return;
}
// TAG: are 360deg arcs supported
switch (getCircularPlane()) {
case PLANE_XY:
writeBlock("Arc" +
(clockwise ? " CW" : " CCW") +
xOutput.format(x) +
iOutput.format(cx - start.x) +
jOutput.format(cy - start.y)
);
break;
default:
linearize(tolerance);
}
} else {
switch (getCircularPlane()) {
case PLANE_XY:
writeBlock("Arc" +
(clockwise ? " CW" : " CCW") +
xOutput.format(x) +
yOutput.format(y) +
zOutput.format(z) +
iOutput.format(cx - start.x) +
jOutput.format(cy - start.y)
);
break;
default:
linearize(tolerance);
}
}
}