-
Notifications
You must be signed in to change notification settings - Fork 0
/
unofficial rrf.cps
411 lines (362 loc) · 14.3 KB
/
unofficial rrf.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
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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
description = "Generic RRF Machine";
vendor = "Unofficial RRF";
vendorUrl = "https://forum.duet3d.com/topic/14872/fusion-360-fdm-fff-slicing/";
legal = "";
certificationLevel = 2;
minimumRevision = 45633;
longDescription = "Post to export toolpath for generic RepRap Firmware printer in gcode format";
extension = "gcode";
setCodePage("ascii");
capabilities = CAPABILITY_ADDITIVE;
highFeedrate = (unit == MM) ? 6000 : 236; //not currently used
//For G2/G3
tolerance = spatial(0.002, MM);
minimumChordLength = spatial(0.25, MM);
minimumCircularRadius = spatial(0.4, MM);
maximumCircularRadius = spatial(1000, MM);
minimumCircularSweep = toRad(0.01);
maximumCircularSweep = toRad(180);
allowHelicalMoves = false; // disable helical support
allowSpiralMoves = false; // disable spiral support
allowedCircularPlanes = 1 << PLANE_XY; // allow XY circular motion
// needed for range checking, will be effectively passed from Fusion
var printerLimits = {
x: { min: 0, max: 200.0 }, //Defines the x bed size
y: { min: 0, max: 200.0 }, //Defines the y bed size
z: { min: 0, max: 200.0 } //Defines the z bed size
};
var extruderOffsets = [[0, 0, 0], [0, 0, 0]];
var activeExtruder = 0; //Track the active extruder.
var totalExtrusionLength = 0; //Accumulate filament used
// user-defined properties
properties = {
printerModel: "Generic RRF Printer",
postHeatMacro: "",
onLayerMacro: "",
onLayerMin: 2,
heatControl: true,
fanSpeed: 100,
relExtrusion: true
};
// user-defined property definitions
propertyDefinitions = {
printerModel: {
title: "Printer model",
description: "Select the printer model for generating the gcode.",
type: "enum",
values: [
{ title: "Generic RRF Printer", id: "rrf" },
]
},
postHeatMacro: {
title: "Post Heat Macro",
description: "Macro to run after heating. Full M98 path.",
type: "string",
},
onLayerMacro: {
title: "Layer Change Macro",
description: "Macro to run at each layer change. Full M98 path.",
type: "string",
},
onLayerMin: {
title: "Layer Change Min Layer",
description: "First layer to run Layer Change Macro",
type: "integer",
},
heatControl: {
title: "Enable Heater Control",
description: "Enable heater control",
type: "boolean"
},
fanSpeed: {
title: "Fan Speed",
description: "Fan speed for duration of print",
type: "integer"
},
relExtrusion: {
title: "Relative Extrusion",
description: "Use relative motion for extrusion",
type: "boolean"
}
};
var xyzFormat = createFormat({ decimals: (unit == MM ? 3 : 4) });
var extrFormat = createFormat({ decimals: (unit == MM ? 4 : 5) }); //special 4-5 dec point format for extrusion
var xFormat = createFormat({ decimals: (unit == MM ? 3 : 4) });
var yFormat = createFormat({ decimals: (unit == MM ? 3 : 4) });
var zFormat = createFormat({ decimals: (unit == MM ? 3 : 4) });
var gFormat = createFormat({ prefix: "G", width: 1, zeropad: false, decimals: 0 });
var mFormat = createFormat({ prefix: "M", width: 2, zeropad: true, decimals: 0 });
var tFormat = createFormat({ prefix: "T", width: 1, zeropad: false, decimals: 0 });
var pFormat = createFormat({ prefix: "P", width: 1, zeropad: false, decimals: 0 });
var hFormat = createFormat({ prefix: "H", width: 1, zeropad: false, decimals: 0 });
var feedFormat = createFormat({ decimals: (unit == MM ? 0 : 1) });
var integerFormat = createFormat({ decimals: 0 });
var dimensionFormat = createFormat({ decimals: (unit == MM ? 3 : 4), zeropad: false, suffix: (unit == MM ? "mm" : "in") });
var gMotionModal = createModal({ force: true }, gFormat); // modal group 1 // G0-G3, ...
var gPlaneModal = createModal({ onchange: function () { gMotionModal.reset(); } }, gFormat); // modal group 2 // G17-19 //Actually unused
var gAbsIncModal = createModal({}, gFormat); // modal group 3 // G90-91
var xOutput = createVariable({ prefix: "X" }, xFormat);
var yOutput = createVariable({ prefix: "Y" }, yFormat);
var zOutput = createVariable({ prefix: "Z" }, zFormat);
var feedOutput = createVariable({ prefix: "F" }, feedFormat);
var eOutput = createVariable({ prefix: "E" }, xyzFormat); // Absolute Extrusion length
var eRelOutput = createIncrementalVariable({ prefix: "E" }, extrFormat); // Relative extrusion length
var sOutput = createVariable({ prefix: "S", force: true }, xyzFormat); // Parameter temperature or speed
var iOutput = createReferenceVariable({ prefix: "I", force: true }, xyzFormat); // circular output
var jOutput = createReferenceVariable({ prefix: "J", force: true }, xyzFormat); // circular output
//incremental layer count for heater workaround
var incLayerCount = 0
// Writes the specified block.
function writeBlock() {
writeWords(arguments);
}
function onOpen() {
getPrinterGeometry();
if (programName) {
writeComment(programName);
}
if (programComment) {
writeComment(programComment);
}
writeComment("Printer Name: " + machineConfiguration.getVendor() + " " + machineConfiguration.getModel());
writeComment("Generated with LittleHobbyShop's RRF Post for F360");
writeComment("Max temp: " + integerFormat.format(getExtruder(1).temperature));
writeComment("Bed temp: " + integerFormat.format(bedTemp));
//Write extruder info (reworked)
for (i = 1; i <= numberOfExtruders; i++) {
writeComment("Extruder " + i + " Filament used: " + dimensionFormat.format(getExtruder(i).extrusionLength));
totalExtrusionLength += dimensionFormat.format(getExtruder(i).extrusionLength);
writeComment("Extruder " + i + " material name: " + getExtruder(i).materialName);
writeComment("Extruder " + i + " filament diameter: " + dimensionFormat.format(getExtruder(i).filamentDiameter));
writeComment("Extruder " + i + " nozzle diameter: " + dimensionFormat.format(getExtruder(i).nozzleDiameter));
writeComment("Extruder " + i + " offset x: " + dimensionFormat.format(extruderOffsets[i - 1][0]));
writeComment("Extruder " + i + " offset y: " + dimensionFormat.format(extruderOffsets[i - 1][1]));
writeComment("Extruder " + i + " offset z: " + dimensionFormat.format(extruderOffsets[i - 1][2]));
}
writeComment("Layer Count: " + integerFormat.format(layerCount));
writeComment("width: " + dimensionFormat.format(printerLimits.x.max));
writeComment("depth: " + dimensionFormat.format(printerLimits.y.max));
writeComment("height: " + dimensionFormat.format(printerLimits.z.max));
writeComment("Count of bodies: " + integerFormat.format(partCount));
writeComment("TIME:" + xyzFormat.format(printTime));
writeComment("Version of Fusion: " + getGlobalParameter("version", "0"));
}
function getPrinterGeometry() {
machineConfiguration = getMachineConfiguration();
// Get the printer geometry from the machine configuration
printerLimits.x.min = 0 - machineConfiguration.getCenterPositionX();
printerLimits.y.min = 0 - machineConfiguration.getCenterPositionY();
printerLimits.z.min = 0 + machineConfiguration.getCenterPositionZ();
printerLimits.x.max = machineConfiguration.getWidth() - machineConfiguration.getCenterPositionX();
printerLimits.y.max = machineConfiguration.getDepth() - machineConfiguration.getCenterPositionY();
printerLimits.z.max = machineConfiguration.getHeight() + machineConfiguration.getCenterPositionZ();
//Get the extruder configuration (rework)
for (i = 1; i <= numberOfExtruders; i++) {
extruderOffsets[i - 1] = [];
extruderOffsets[i - 1][0] = machineConfiguration.getExtruderOffsetX(i);
extruderOffsets[i - 1][1] = machineConfiguration.getExtruderOffsetY(i);
extruderOffsets[i - 1][2] = machineConfiguration.getExtruderOffsetZ(i);
}
}
function onClose() {
writeBlock(mFormat.format(0), hFormat.format(1));
writeComment("END OF GCODE");
}
function onComment(message) {
writeComment(message);
}
function onSection() {
var range = currentSection.getBoundingBox();
axes = ["x", "y", "z"];
formats = [xFormat, yFormat, zFormat];
for (var element in axes) {
var min = formats[element].getResultingValue(range.lower[axes[element]]);
var max = formats[element].getResultingValue(range.upper[axes[element]]);
if (printerLimits[axes[element]].max < max || printerLimits[axes[element]].min > min) {
error(localize("A toolpath is outside of the build volume."));
}
}
// Reset extrusion distance
//writeBlock(gFormat.format(92), eOutput.format(0));
// set unit
writeBlock(gFormat.format(unit == MM ? 21 : 20));
writeBlock(gAbsIncModal.format(90)); // absolute spatial co-ordinates
writeBlock(mFormat.format(properties.relExtrusion ? 83 : 82)); // relative/absolute extrusion co-ordinates
//homing
//writeRetract(Z); // retract in Z
//lower build plate before homing in XY
//var initialPosition = getFramePosition(currentSection.getInitialPosition());
//writeBlock(gMotionModal.format(1), zOutput.format(initialPosition.z), feedOutput.format(highFeedrate));
// home XY
//writeRetract(X, Y);
//writeBlock(gFormat.format(92), eOutput.format(0));
if (properties.postHeatMacro !== "") {
writeComment("Executing post heat macro: " + properties.postHeatMacro);
writeBlock(mFormat.format(98), "P\"" + properties.postHeatMacro + "\"");
}
incLayerCount = 0
}
function onSectionEnd() {
writeComment("Section End")
}
function onRapid(_x, _y, _z) {
var x = xOutput.format(_x);
var y = yOutput.format(_y);
var z = zOutput.format(_z);
if (x || y || z) {
writeBlock(gMotionModal.format(0), x, y, z);
}
}
function onLinearExtrude(_x, _y, _z, _f, _e) {
var x = xOutput.format(_x);
var y = yOutput.format(_y);
var z = zOutput.format(_z);
var f = feedOutput.format(_f);
var e = properties.relExtrusion ? eRelOutput.format(_e) : eOutput.format(_e); // relative/absolute extrusion output
if (x || y || z || f || e) {
writeBlock(gMotionModal.format(1), x, y, z, f, e);
}
}
function onCircularExtrude(_clockwise, _cx, _cy, _cz, _x, _y, _z, _f, _e) {
var x = xOutput.format(_x);
var y = yOutput.format(_y);
var z = zOutput.format(_z);
var f = feedOutput.format(_f);
var e = properties.relExtrusion ? eRelOutput.format(_e) : eOutput.format(_e); // relative/absolute extrusion output
var start = getCurrentPosition();
var i = iOutput.format(_cx - start.x, 0); // arc center relative to start point
var j = jOutput.format(_cy - start.y, 0);
switch (getCircularPlane()) {
case PLANE_XY:
writeBlock(gMotionModal.format(_clockwise ? 2 : 3), x, y, i, j, f, e);
break;
default:
linearize(tolerance);
}
}
function onBedTemp(temp, wait) {
if (incLayerCount > 0 || properties.heatControl) {
if (wait) {
writeBlock(mFormat.format(190), sOutput.format(temp));
} else {
writeBlock(mFormat.format(140), sOutput.format(temp));
}
}
}
function onExtruderChange(id) {
if (id < numberOfExtruders) {
writeBlock(tFormat.format(id));
activeExtruder = id;
xOutput.reset();
yOutput.reset();
zOutput.reset();
} else {
error(localize("This printer doesn't support the extruder ") + integerFormat.format(id) + " !");
}
}
function onExtrusionReset(length) {
eOutput.reset();
writeBlock(gFormat.format(92), eOutput.format(length));
}
function onLayer(num) {
writeComment("Layer : " + integerFormat.format(num) + " of " + integerFormat.format(layerCount));
if (properties.onLayerMacro !== "" && properties.onLayerMin <= num) {
writeComment("Executing layer change macro: " + properties.onLayerMacro);
writeBlock(mFormat.format(98), "P\"" + properties.onLayerMacro + "\"");
}
incLayerCount = num;
}
function onExtruderTemp(temp, wait, id) {
var extruderString = "";
extruderString = pFormat.format(id);
if (incLayerCount > 0 || properties.heatControl) {
if (id < numberOfExtruders) {
if (wait) {
writeBlock(gFormat.format(10), pFormat.format(id), sOutput.format(temp));
writeBlock(mFormat.format(116));
} else {
writeBlock(gFormat.format(10), pFormat.format(id), sOutput.format(temp));
}
} else {
error(localize("This printer doesn't support the extruder ") + integerFormat.format(id) + " !");
}
}
}
function onFanSpeed(speed, id) {
// to do handle id information
if (properties.fanSpeed >= 0 && properties.fanSpeed <= 100) {
if (speed == 0) {
writeBlock(mFormat.format(106), sOutput.format(0));
} else {
writeBlock(mFormat.format(106), sOutput.format(properties.fanSpeed * 2.55));
}
} else {
error(localize("Fan speed outside range 0-100"));
return;
}
}
function onParameter(name, value) {
switch (name) {
//feedrate is set before rapid moves and extruder change
case "feedRate":
if (unit == IN) {
value /= 25.4;
}
setFeedRate(value);
break;
//warning or error message on unhandled parameter?
}
}
//user defined functions
function setFeedRate(value) {
feedOutput.reset();
writeBlock(gFormat.format(1), feedOutput.format(value));
}
function writeComment(text) {
writeln(";" + text);
var index = text.indexOf("park position");
if (index !== -1) {
incLayerCount = 0
}
}
function writeRetract() {
if (arguments.length == 0) {
error(localize("No axis specified for writeRetract()."));
return;
}
var words = []; // store all retracted axes in an array
for (var i = 0; i < arguments.length; ++i) {
let instances = 0; // checks for duplicate retract calls
for (var j = 0; j < arguments.length; ++j) {
if (arguments[i] == arguments[j]) {
++instances;
}
}
if (instances > 1) { // error if there are multiple retract calls for the same axis
error(localize("Cannot retract the same axis twice in one line"));
return;
}
switch (arguments[i]) {
case X:
words.push("X" + xyzFormat.format(machineConfiguration.hasHomePositionX() ? machineConfiguration.getHomePositionX() : 0));
xOutput.reset();
break;
case Y:
words.push("Y" + xyzFormat.format(machineConfiguration.hasHomePositionY() ? machineConfiguration.getHomePositionY() : 0));
yOutput.reset();
break;
case Z:
words.push("Z" + xyzFormat.format(0));
zOutput.reset();
retracted = true; // specifies that the tool has been retracted to the safe plane
break;
default:
error(localize("Bad axis specified for writeRetract()."));
return;
}
}
if (words.length > 0) {
gMotionModal.reset();
writeBlock(gFormat.format(28), gAbsIncModal.format(90), words); // retract
}
}