2015-06-05 09:56:58 +02:00
|
|
|
/******************************************************
|
|
|
|
*
|
|
|
|
* GCode
|
|
|
|
*
|
|
|
|
* Manages the gcode
|
2015-06-09 21:58:22 +02:00
|
|
|
* Also handles different flavours of gcode
|
2015-06-10 18:25:49 +02:00
|
|
|
* TODO
|
|
|
|
* calculate extrusion length and total time
|
2015-06-05 09:56:58 +02:00
|
|
|
*
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
D3D.GCode = function () {
|
|
|
|
"use strict";
|
|
|
|
|
2015-06-11 10:28:21 +02:00
|
|
|
this.gcode = "";
|
2015-06-09 11:08:06 +02:00
|
|
|
this.current = {};
|
|
|
|
|
2015-06-05 09:56:58 +02:00
|
|
|
this.extruder = 0.0;
|
|
|
|
this.bottom = true;
|
|
|
|
this.isRetracted = false;
|
2015-06-09 11:08:06 +02:00
|
|
|
this.isFanOn = false;
|
2015-06-05 09:56:58 +02:00
|
|
|
this.nozzlePosition = new THREE.Vector2(0, 0);
|
|
|
|
};
|
2015-06-09 11:08:06 +02:00
|
|
|
D3D.GCode.prototype.addGCode = function (command) {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var str = [];
|
|
|
|
|
|
|
|
for (var i in command) {
|
2015-06-09 21:58:22 +02:00
|
|
|
if (i === "G") {
|
|
|
|
str.push(i + command[i]);
|
|
|
|
}
|
|
|
|
else if (this.current[i] !== command[i]) {
|
2015-06-09 11:08:06 +02:00
|
|
|
str.push(i + command[i]);
|
|
|
|
this.current[i] = command[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
str = str.join(" ");
|
|
|
|
if (str.length > 0) {
|
2015-06-11 10:28:21 +02:00
|
|
|
this.gcode += str + "\n";
|
2015-06-09 11:08:06 +02:00
|
|
|
}
|
|
|
|
};
|
2015-06-05 09:56:58 +02:00
|
|
|
D3D.GCode.prototype.setSettings = function (printer) {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
this.settings = printer;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
2015-06-09 11:08:06 +02:00
|
|
|
D3D.GCode.prototype.turnFanOn = function (fanSpeed) {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
this.isFanOn = true;
|
|
|
|
|
|
|
|
var gcode = {
|
|
|
|
"M": 106
|
|
|
|
};
|
|
|
|
|
|
|
|
if (fanSpeed !== undefined) {
|
|
|
|
gcode["S"] = fanSpeed;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.addGCode(gcode);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
D3D.GCode.prototype.turnFanOff = function () {
|
2015-06-05 09:56:58 +02:00
|
|
|
"use strict";
|
|
|
|
|
2015-06-09 11:08:06 +02:00
|
|
|
this.isFanOn = false;
|
|
|
|
|
|
|
|
this.addGCode({
|
|
|
|
"M": 107
|
|
|
|
});
|
|
|
|
|
|
|
|
return this;
|
2015-06-05 09:56:58 +02:00
|
|
|
};
|
|
|
|
D3D.GCode.prototype.moveTo = function (extrude, x, y, layer) {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var layerHeight = this.settings.config["printer.layerHeight"];
|
|
|
|
var firstLayerSlow = this.settings.config["printer.firstLayerSlow"];
|
|
|
|
var normalSpeed = this.settings.config["printer.speed"];
|
|
|
|
var bottomSpeed = this.settings.config["printer.bottomLayerSpeed"];
|
|
|
|
var normalSpeed = this.settings.config["printer.speed"];
|
|
|
|
var bottomSpeed = this.settings.config["printer.bottomLayerSpeed"];
|
|
|
|
var nozzleDiameter = this.settings.config["printer.nozzleDiameter"];
|
|
|
|
var filamentThickness = this.settings.config["printer.filamentThickness"];
|
|
|
|
var bottomFlowRate = this.settings.config["printer.bottomFlowRate"];
|
|
|
|
var normalFlowRate = this.settings.config["printer.normalFlowRate"];
|
|
|
|
var travelSpeed = this.settings.config["printer.travelSpeed"];
|
|
|
|
|
|
|
|
if (this.bottom) {
|
|
|
|
var speed = bottomSpeed * 60;
|
|
|
|
var flowRate = bottomFlowRate;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var speed = normalSpeed * 60;
|
|
|
|
var flowRate = normalFlowRate;
|
|
|
|
}
|
|
|
|
var z = (layer + 1) * layerHeight;
|
|
|
|
|
|
|
|
if (extrude) {
|
|
|
|
var lineLength = this.nozzlePosition.distanceTo(new THREE.Vector2(x, y));
|
|
|
|
|
|
|
|
var filamentSurfaceArea = Math.pow((filamentThickness/2), 2) * Math.PI;
|
|
|
|
this.extruder += lineLength * nozzleDiameter * layerHeight / filamentSurfaceArea * flowRate;
|
|
|
|
|
2015-06-09 11:08:06 +02:00
|
|
|
this.addGCode({
|
|
|
|
"G": 1,
|
|
|
|
"X": x.toFixed(3), "Y": y.toFixed(3), "Z": z.toFixed(3),
|
|
|
|
"F": speed.toFixed(3),
|
|
|
|
"E": this.extruder.toFixed(3)
|
|
|
|
});
|
2015-06-05 09:56:58 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
var speed = travelSpeed * 60;
|
|
|
|
|
2015-06-09 21:58:22 +02:00
|
|
|
this.addGCode({
|
2015-06-09 11:08:06 +02:00
|
|
|
"G": 0,
|
|
|
|
"X": x.toFixed(3), "Y": y.toFixed(3), "Z": z.toFixed(3),
|
|
|
|
"F": speed.toFixed(3)
|
|
|
|
});
|
2015-06-05 09:56:58 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.nozzlePosition = new THREE.Vector2(x, y);
|
2015-06-09 11:08:06 +02:00
|
|
|
|
|
|
|
return this;
|
2015-06-05 09:56:58 +02:00
|
|
|
};
|
|
|
|
D3D.GCode.prototype.unRetract = function () {
|
|
|
|
"use strict";
|
|
|
|
|
2015-06-09 21:58:22 +02:00
|
|
|
if (this.isRetracted) {
|
|
|
|
this.isRetracted = false;
|
2015-06-05 09:56:58 +02:00
|
|
|
|
2015-06-09 21:58:22 +02:00
|
|
|
var retractionAmount = this.settings.config["printer.retraction.amount"];
|
|
|
|
var retractionEnabled = this.settings.config["printer.retraction.enabled"];
|
|
|
|
var retractionMinDistance = this.settings.config["printer.retraction.minDistance"];
|
|
|
|
var retractionSpeed = this.settings.config["printer.retraction.speed"];
|
2015-06-05 09:56:58 +02:00
|
|
|
|
2015-06-09 21:58:22 +02:00
|
|
|
var speed = retractionSpeed * 60;
|
2015-06-05 09:56:58 +02:00
|
|
|
|
2015-06-09 21:58:22 +02:00
|
|
|
if (this.extruder > retractionMinDistance && retractionEnabled) {
|
|
|
|
this.addGCode({
|
|
|
|
"G": 0,
|
|
|
|
"E": this.extruder.toFixed(3),
|
|
|
|
"F": speed.toFixed(3)
|
|
|
|
});
|
|
|
|
}
|
2015-06-09 11:08:06 +02:00
|
|
|
|
2015-06-09 21:58:22 +02:00
|
|
|
return this;
|
|
|
|
}
|
2015-06-05 09:56:58 +02:00
|
|
|
};
|
|
|
|
D3D.GCode.prototype.retract = function () {
|
|
|
|
"use strict";
|
|
|
|
|
2015-06-09 21:58:22 +02:00
|
|
|
if (!this.isRetracted) {
|
|
|
|
this.isRetracted = true;
|
2015-06-05 09:56:58 +02:00
|
|
|
|
2015-06-09 21:58:22 +02:00
|
|
|
var retractionAmount = this.settings.config["printer.retraction.amount"];
|
|
|
|
var retractionEnabled = this.settings.config["printer.retraction.enabled"];
|
|
|
|
var retractionMinDistance = this.settings.config["printer.retraction.minDistance"];
|
|
|
|
var retractionSpeed = this.settings.config["printer.retraction.speed"];
|
2015-06-05 09:56:58 +02:00
|
|
|
|
2015-06-09 21:58:22 +02:00
|
|
|
var speed = retractionSpeed * 60;
|
2015-06-05 09:56:58 +02:00
|
|
|
|
2015-06-09 21:58:22 +02:00
|
|
|
if (this.extruder > retractionMinDistance && retractionEnabled) {
|
|
|
|
this.addGCode({
|
|
|
|
"G": 0,
|
|
|
|
"E": (this.extruder - retractionAmount).toFixed(3),
|
|
|
|
"F": speed.toFixed(3)
|
|
|
|
});
|
|
|
|
}
|
2015-06-05 09:56:58 +02:00
|
|
|
|
2015-06-09 21:58:22 +02:00
|
|
|
return this;
|
|
|
|
}
|
2015-06-05 09:56:58 +02:00
|
|
|
};
|
2015-06-09 11:08:06 +02:00
|
|
|
D3D.GCode.prototype.getGCode = function () {
|
2015-06-05 09:56:58 +02:00
|
|
|
"use strict";
|
|
|
|
|
2015-06-11 10:28:21 +02:00
|
|
|
return this.settings.getStartCode() + this.gcode + this.settings.getEndCode();
|
2015-06-05 09:56:58 +02:00
|
|
|
};
|