improved network error handling

can now reconnect when connecting failed
This commit is contained in:
casperlamboo 2015-06-11 10:28:21 +02:00
parent dd41e6d3e7
commit 81ec036973
11 changed files with 136 additions and 125 deletions

View File

@ -4,14 +4,14 @@
"printer.dimensions.x": 200,
"printer.dimensions.y": 200,
"printer.dimensions.z": 200,
"printer.endcode": "M107 ;fan off\nG91 ;relative positioning\nG1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure\nG1 Z+0.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more\nG28 X0 Y0 ;move X/Y to min endstops, so the head is out of the way\nM84 ;disable axes / steppers\nG90 ;absolute positioning\nM104 S{preheatTemp}\n{if heatedBed}M140 S{preheatBedTemp}\nM117 Done ;display message (20 characters to clear whole screen)",
"printer.endcode": "M107 ;fan off\nG91 ;relative positioning\nG1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure\nG1 Z+0.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more\nG28 X0 Y0 ;move X/Y to min endstops, so the head is out of the way\nM84 ;disable axes / steppers\nG90 ;absolute positioning\nM104 S{preheatTemp}\n{if heatedBed}M140 S{preheatBedTemp}\nM117 Done ;display message (20 characters to clear whole screen)\n",
"printer.filamentThickness": 2.85,
"printer.heatedbed": false,
"printer.heatup.bed.temperature": 70,
"printer.heatup.enabled": true,
"printer.heatup.temperature": 180,
"printer.nozzleDiameter": 0.4,
"printer.startcode": ";Generated with Doodle3D (default)\nM109 S{printingTemp} ;set target temperature \n{if heatedBed}M190 S{printingBedTemp} ;set target bed temperature\nG21 ;metric values\nG91 ;relative positioning\nM107 ;start with the fan off\nG28 X0 Y0 ;move X/Y to min endstops\nG28 Z0 ;move Z to min endstops\nG1 Z15 F9000 ;move the platform down 15mm\nG92 E0 ;zero the extruded length\nG1 F200 E10 ;extrude 10mm of feed stock\nG92 E0 ;zero the extruded length again\nG92 E0 ;zero the extruded length again\nG1 F9000\nG90 ;absolute positioning\nM117 Printing Doodle... ;display message (20 characters to clear whole screen)",
"printer.startcode": ";Generated with Doodle3D (default)\nM109 S{printingTemp} ;set target temperature \n{if heatedBed}M190 S{printingBedTemp} ;set target bed temperature\nG21 ;metric values\nG91 ;relative positioning\nM107 ;start with the fan off\nG28 X0 Y0 ;move X/Y to min endstops\nG28 Z0 ;move Z to min endstops\nG1 Z15 F9000 ;move the platform down 15mm\nG92 E0 ;zero the extruded length\nG1 F200 E10 ;extrude 10mm of feed stock\nG92 E0 ;zero the extruded length again\nG92 E0 ;zero the extruded length again\nG1 F9000\nG90 ;absolute positioning\nM117 Printing Doodle... ;display message (20 characters to clear whole screen)\n",
"printer.type": "ultimaker"
},
"ultimaker2": {
@ -19,14 +19,14 @@
"printer.dimensions.x": 223,
"printer.dimensions.y": 223,
"printer.dimensions.z": 205,
"printer.endcode": "M107 ;fan off\nG91 ;relative positioning\nG1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure\nG1 Z+5.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more\nG28 ;home the printer\nM84 ;disable axes / steppers\nG90 ;absolute positioning\nM104 S{preheatTemp}\n{if heatedBed}M140 S{preheatBedTemp}\nM117 Done ;display message (20 characters to clear whole screen)",
"printer.endcode": "M107 ;fan off\nG91 ;relative positioning\nG1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure\nG1 Z+5.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more\nG28 ;home the printer\nM84 ;disable axes / steppers\nG90 ;absolute positioning\nM104 S{preheatTemp}\n{if heatedBed}M140 S{preheatBedTemp}\nM117 Done ;display message (20 characters to clear whole screen)\n",
"printer.filamentThickness": 2.85,
"printer.heatedbed": true,
"printer.heatup.bed.temperature": 70,
"printer.heatup.enabled": true,
"printer.heatup.temperature": 180,
"printer.nozzleDiameter": 0.4,
"printer.startcode": ";Generated with Doodle3D (ultimaker2)\nM109 S{printingTemp} ;set target temperature \n{if heatedBed}M190 S{printingBedTemp} ;set target bed temperature\nG21 ;metric values\nG90 ;absolute positioning\nM107 ;start with the fan off\nG28 ; home to endstops\nG1 Z15 F9000 ;move the platform down 15mm\nG92 E0 ;zero the extruded length\nG1 F200 E10 ;extrude 10mm of feed stock\nG92 E0 ;zero the extruded length again\nG1 F9000\nM117 Printing Doodle... ;display message (20 characters to clear whole screen)",
"printer.startcode": ";Generated with Doodle3D (ultimaker2)\nM109 S{printingTemp} ;set target temperature \n{if heatedBed}M190 S{printingBedTemp} ;set target bed temperature\nG21 ;metric values\nG90 ;absolute positioning\nM107 ;start with the fan off\nG28 ; home to endstops\nG1 Z15 F9000 ;move the platform down 15mm\nG92 E0 ;zero the extruded length\nG1 F200 E10 ;extrude 10mm of feed stock\nG92 E0 ;zero the extruded length again\nG1 F9000\nM117 Printing Doodle... ;display message (20 characters to clear whole screen)\n",
"printer.type": "ultimaker2"
},
"ultimaker2go": {
@ -34,14 +34,14 @@
"printer.dimensions.x": 120,
"printer.dimensions.y": 120,
"printer.dimensions.z": 115,
"printer.endcode": "M107 ;fan off\nG91 ;relative positioning\nG1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure\nG1 Z+5.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more\nG28 ;home the printer\nM84 ;disable axes / steppers\nG90 ;absolute positioning\nM104 S{preheatTemp}\n{if heatedBed}M140 S{preheatBedTemp}\nM117 Done ;display message (20 characters to clear whole screen)",
"printer.endcode": "M107 ;fan off\nG91 ;relative positioning\nG1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure\nG1 Z+5.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more\nG28 ;home the printer\nM84 ;disable axes / steppers\nG90 ;absolute positioning\nM104 S{preheatTemp}\n{if heatedBed}M140 S{preheatBedTemp}\nM117 Done ;display message (20 characters to clear whole screen)\n",
"printer.filamentThickness": 2.85,
"printer.heatedbed": false,
"printer.heatup.bed.temperature": 70,
"printer.heatup.enabled": true,
"printer.heatup.temperature": 180,
"printer.heatup.temperature": 20,
"printer.nozzleDiameter": 0.4,
"printer.startcode": ";Generated with Doodle3D (ultimaker2)\nM109 S{printingTemp} ;set target temperature \n{if heatedBed}M190 S{printingBedTemp} ;set target bed temperature\nG21 ;metric values\nG90 ;absolute positioning\nM107 ;start with the fan off\nG28 ; home to endstops\nG1 Z15 F9000 ;move the platform down 15mm\nG92 E0 ;zero the extruded length\nG1 F200 E10 ;extrude 10mm of feed stock\nG92 E0 ;zero the extruded length again\nG1 F9000\nM117 Printing Doodle... ;display message (20 characters to clear whole screen)",
"printer.startcode": ";Generated with Doodle3D (ultimaker2)\nM109 S{printingTemp} ;set target temperature \n{if heatedBed}M190 S{printingBedTemp} ;set target bed temperature\nG21 ;metric values\nG90 ;absolute positioning\nM107 ;start with the fan off\nG28 ; home to endstops\nG1 Z15 F9000 ;move the platform down 15mm\nG92 E0 ;zero the extruded length\nG1 F200 E10 ;extrude 10mm of feed stock\nG92 E0 ;zero the extruded length again\nG1 F9000\nM117 Printing Doodle... ;display message (20 characters to clear whole screen)\n",
"printer.type": "ultimaker2g0"
}
}

View File

@ -15,7 +15,7 @@
"printer.temperature": 210.0,
"printer.topThickness": 0.8,
"printer.travelSpeed": 200.0,
"printer.support.accaptanceSize": 1.5,
"printer.support.accaptanceMargin": 1.5,
"printer.support.distanceY": 0.4,
"printer.support.use": true,
"printer.support.gritSize": 6.0,

View File

@ -16,6 +16,8 @@ D3D.Box = function (localIp) {
"use strict";
var scope = this;
this.alive = false;
this.batchSize = 512;
this.maxBufferedLines = 4096;
@ -30,16 +32,46 @@ D3D.Box = function (localIp) {
this.loaded = false;
this.getConfigAll(function (data) {
scope.updateConfig(data);
this.init();
};
D3D.Box.prototype.init = function () {
"use strict";
var scope = this;
scope.update();
this.getNetworkAlive(function (error, data) {
if (error) {
scope.alive = false;
console.warn(error);
setTimeout(function () {
scope.init();
}, 1000);
scope.loaded = true;
if (scope.onload !== undefined) {
scope.onload();
return;
}
scope.alive = true;
scope.getConfigAll(function (error, data) {
if (error) {
console.warn(error);
scope.init();
}
scope.updateConfig(data);
if (!scope.loaded) {
scope.loaded = true;
if (scope.onload !== undefined) {
scope.onload();
}
}
scope.updateLoop();
});
});
return this;
};
D3D.Box.prototype.updateConfig = function (config) {
"use strict";
@ -50,7 +82,7 @@ D3D.Box.prototype.updateConfig = function (config) {
return this;
};
D3D.Box.prototype.update = function () {
D3D.Box.prototype.updateLoop = function () {
"use strict";
var scope = this;
//TODO
@ -73,14 +105,21 @@ D3D.Box.prototype.updateState = function () {
"use strict";
var scope = this;
this.getInfoStatus(function (data) {
this.getInfoStatus(function (error, data) {
if (error) {
console.warn(error);
scope.init();
return;
}
scope.status = data;
if (scope.onupdate !== undefined) {
scope.onupdate(data);
}
scope.update();
scope.updateLoop();
});
};
D3D.Box.prototype.print = function (gcode) {
@ -110,7 +149,15 @@ D3D.Box.prototype.printBatch = function () {
"first": ((this.currentBatch === 0) ? true : false),
"gcode": gcode.join("\n"),
"last": ((this.printBatches.length === 0) ? true : false) //only for debug purposes
}, function (data) {
}, function (error, data) {
if (error) {
scope.printBatches.unshift(gcode);
console.warn(error);
scope.init();
return;
}
console.log("batch sent: " + scope.currentBatch, data);
if (scope.printBatches.length > 0) {
@ -126,13 +173,21 @@ D3D.Box.prototype.printBatch = function () {
};
D3D.Box.prototype.stopPrint = function (printer) {
"use strict";
var scope = this;
this.printBatches = [];
this.currentBatch = 0;
this.setPrinterStop({
"gcode": printer.getEndCode().join("\n")
}, function (data) {
"gcode": printer.getEndCode()
}, function (error, data) {
if (error) {
console.warn(error);
scope.init();
return;
}
console.log("Printer stop command sent");
});

View File

@ -12,7 +12,7 @@
D3D.GCode = function () {
"use strict";
this.gcode = [];
this.gcode = "";
this.current = {};
this.extruder = 0.0;
@ -38,7 +38,7 @@ D3D.GCode.prototype.addGCode = function (command) {
str = str.join(" ");
if (str.length > 0) {
this.gcode.push(str);
this.gcode += str + "\n";
}
};
D3D.GCode.prototype.setSettings = function (printer) {
@ -180,5 +180,5 @@ D3D.GCode.prototype.retract = function () {
D3D.GCode.prototype.getGCode = function () {
"use strict";
return this.settings.getStartCode().concat(this.gcode, this.settings.getEndCode());
return this.settings.getStartCode() + this.gcode + this.settings.getEndCode();
};

View File

@ -8,7 +8,7 @@
******************************************************/
D3D.Paths = function (paths, closed) {
"use strict";
'use strict';
Array.call(this);
@ -18,7 +18,7 @@ D3D.Paths = function (paths, closed) {
};
D3D.Paths.prototype = Object.create(Array.prototype);
D3D.Paths.prototype.setPaths = function (paths) {
"use strict";
'use strict';
for (var i = 0; i < paths.length; i ++) {
var path = paths[i];
@ -30,7 +30,7 @@ D3D.Paths.prototype.setPaths = function (paths) {
return this;
};
D3D.Paths.prototype.clip = function (path, type) {
"use strict";
'use strict';
var solution = new ClipperLib.Paths();
@ -42,27 +42,27 @@ D3D.Paths.prototype.clip = function (path, type) {
return new D3D.Paths(solution, this.closed);
};
D3D.Paths.prototype.union = function (path) {
"use strict";
'use strict';
return this.clip(path, ClipperLib.ClipType.ctUnion);
};
D3D.Paths.prototype.difference = function (path) {
"use strict";
'use strict';
return this.clip(path, ClipperLib.ClipType.ctDifference);
};
D3D.Paths.prototype.intersect = function (path) {
"use strict";
'use strict';
return this.clip(path, ClipperLib.ClipType.ctIntersection);
};
D3D.Paths.prototype.xor = function () {
"use strict";
'use strict';
return this.clip(path, ClipperLib.ClipType.ctXor);
};
D3D.Paths.prototype.offset = function (offset) {
"use strict";
'use strict';
var solution = new ClipperLib.Paths();
var co = new ClipperLib.ClipperOffset(1, 1);
@ -72,28 +72,28 @@ D3D.Paths.prototype.offset = function (offset) {
return new D3D.Paths(solution);
};
D3D.Paths.prototype.scaleUp = function (factor) {
"use strict";
'use strict';
var path = ClipperLib.JS.ScaleUpPaths(this, factor);
return this;
};
D3D.Paths.prototype.scaleDown = function (factor) {
"use strict";
'use strict';
var path = ClipperLib.JS.ScaleDownPaths(this, factor);
return this;
};
D3D.Paths.prototype.lastPoint = function () {
"use strict";
'use strict';
var lastPath = this[this.length - 1];
var lastPoint = this.closed ? lastPath[0] : lastPath[lastPath.length - 1];
return new THREE.Vector2(lastPoint.X, lastPoint.Y);
};
D3D.Paths.prototype.optimizePath = function (start) {
"use strict";
'use strict';
var optimizedPaths = new D3D.Paths([], this.closed);
var donePaths = [];
@ -161,7 +161,7 @@ D3D.Paths.prototype.optimizePath = function (start) {
return optimizedPaths;
};
D3D.Paths.prototype.areas = function () {
"use strict";
'use strict';
var areas = [];
@ -176,7 +176,7 @@ D3D.Paths.prototype.areas = function () {
};
D3D.Paths.prototype.tresholdArea = function (minArea) {
//code not tested yet
"use strict";
'use strict';
for (var i = 0; i < this.length; i ++) {
var shape = this[i];
@ -192,7 +192,7 @@ D3D.Paths.prototype.tresholdArea = function (minArea) {
return areas;
};
D3D.Paths.prototype.join = function (path) {
"use strict";
'use strict';
for (var i = 0; i < path.length; i ++) {
this.push(path[i]);
@ -201,17 +201,17 @@ D3D.Paths.prototype.join = function (path) {
return this;
};
D3D.Paths.prototype.clone = function () {
"use strict";
'use strict';
return new D3D.Paths(ClipperLib.JS.Clone(this), this.closed);
};
D3D.Paths.prototype.bounds = function () {
"use strict";
'use strict';
return ClipperLib.Clipper.GetBounds(this);
};
D3D.Paths.prototype.boundSize = function () {
"use strict";
'use strict';
var bounds = this.bounds();
@ -221,7 +221,7 @@ D3D.Paths.prototype.boundSize = function () {
return width * height;
};
D3D.Paths.prototype.draw = function (context, color) {
"use strict";
'use strict';
context.strokeStyle = color;
for (var i = 0; i < this.length; i ++) {

View File

@ -27,7 +27,7 @@ D3D.Printer.prototype.getStartCode = function () {
var gcode = this.config["printer.startcode"];
gcode = this.subsituteVariables(gcode);
return gcode.split("\n");
return gcode;
};
D3D.Printer.prototype.getEndCode = function () {
"use strict";
@ -36,7 +36,7 @@ D3D.Printer.prototype.getEndCode = function () {
gcode = this.subsituteVariables(gcode);
return gcode.split("\n");
return gcode;
};
D3D.Printer.prototype.subsituteVariables = function (gcode) {
"use strict";

View File

@ -24,24 +24,26 @@ D3D.Slicer.prototype.setMesh = function (geometry, matrix) {
geometry = new THREE.Geometry().fromBufferGeometry(geometry);
}
//apply mesh matrix on geometry;
geometry.applyMatrix(matrix);
geometry.mergeVertices();
geometry.computeFaceNormals();
geometry.computeBoundingBox();
/*
geometry.computeFaceNormals();
for (var i = 0; i < geometry.faces.length; i ++) {
var face = geometry.faces[i];
var normal = face.normal;
if (normal.x === 0 && normal.y === 0 && normal.z === 0) {
geometry.faces.splice(i, 1);
console.log("Tets");
i --;
}
}
*/
//apply mesh matrix on geometry;
geometry.applyMatrix(matrix);
geometry.mergeVertices();
geometry.computeFaceNormals();
geometry.computeBoundingBox();
this.geometry = geometry;
//get unique lines from geometry;
@ -189,14 +191,17 @@ D3D.Slicer.prototype.slice = function (layerHeight, height) {
var a = new THREE.Vector2(intersection.x, intersection.y);
var b = intersections[index];
if (a.distanceTo(b) === 0) {
var faceNormal = faceNormals[Math.floor(j/2)];
console.log();
if (a.distanceTo(b) === 0 || faceNormal.equals(new THREE.Vector2(0, 0))) {
connects = connects.concat(this.lines[index].connects);
faceNormals = faceNormals.concat(this.lines[index].normals);
index = -1;
}
else {
var normal = a.sub(b).normal().normalize();
var faceNormal = faceNormals[Math.floor(j/2)];
if (normal.dot(faceNormal) >= 0) {
//if (true) {
@ -290,7 +295,7 @@ D3D.Slicer.prototype.slicesToData = function (slices, printer) {
var topThickness = printer.config["printer.topThickness"];
var useSupport = printer.config["printer.support.use"];
var supportGritSize = printer.config["printer.support.gritSize"] * scale;
var supportAccaptanceSize = printer.config["printer.support.accaptanceSize"] * scale;
var supportAccaptanceMargin = printer.config["printer.support.accaptanceMargin"] * scale;
var supportMargin = printer.config["printer.support.margin"] * scale;
var plateSize = printer.config["printer.support.plateSize"] * scale;
var supportDistanceY = printer.config["printer.support.distanceY"];
@ -441,12 +446,16 @@ D3D.Slicer.prototype.slicesToData = function (slices, printer) {
var slicePart = slice[i];
var outerLayer = slicePart.outerLayer;
var overlap = supportSkin.offset(supportAccaptanceSize).intersect(outerLayer);
var overlap = supportSkin.offset(supportAccaptanceMargin).intersect(outerLayer);
var overhang = outerLayer.difference(overlap);
if (overlap.length === 0 || overhang.length > 0) {
var supportArea = outerLayer.difference(supportSkin.intersect(outerLayer));
supportAreas = supportAreas.union(supportArea);
//var supportArea = outerLayer.difference(supportSkin.intersect(outerLayer));
//supportAreas = supportAreas.union(supportArea);
//supportAreas = supportAreas.union(overhang);
supportAreas = supportAreas.union(overhang.offset(supportAccaptanceMargin).intersect(outerLayer));
}
}
}

View File

@ -17,9 +17,12 @@ D3D.SlicerWorker = function () {
case 'GCODE':
if (scope.onfinish !== undefined) {
var gcode = event.data['gcode'];
scope.onfinish(gcode);
var reader = new FileReader();
reader.addEventListener("loadend", function() {
var gcode = reader.result.split("\n");
scope.onfinish(gcode);
});
reader.readAsBinaryString(event.data['gcode']);
}
break;
}

View File

@ -14,37 +14,6 @@ var D3D = {
function sendAPI (url, data, callback) {
"use strict";
/*
var form = new FormData();
for (var i in data) {
form.append(i, JSON.stringify(data[i]));
}
var request = new XMLHttpRequest();
request.open('POST', url, true);
request.send(data);
request.onreadystatechange = function () {
if (request.readyState === 4 && request.status === 200) {
var response = JSON.parse(request.responseText);
if (response.status === "success") {
if (callback !== undefined) {
callback(response.data);
}
}
else {
console.warn(response.msg);
}
}
else {
console.log(request);
console.warn("Failed connecting to " + url);
//sendAPI(url, data, callback);
}
};
*/
$.ajax({
url: url,
type: "POST",
@ -54,44 +23,20 @@ function sendAPI (url, data, callback) {
success: function (response) {
if (response.status === "success") {
if (callback !== undefined) {
callback(response.data);
callback(null, response.data);
}
}
else {
console.warn(response.msg);
callback(response.msg);
}
}
}).fail(function () {
console.warn("Failed connecting to " + url);
sendAPI(url, data, callback);
callback("Failed connecting to " + url);
});
}
function getAPI (url, callback) {
"use strict";
/*
var request = new XMLHttpRequest();
request.open('GET', url, true);
request.send();
request.onreadystatechange = function () {
if (request.readyState === 4 && request.status === 200) {
var response = JSON.parse(request.responseText);
if (response.status === "success") {
if (callback !== undefined) {
callback(response.data);
}
}
else {
console.warn(response.msg);
}
}
else {
console.warn("Failed connecting to " + url);
sendAPI(url, callback);
}
};*/
$.ajax({
url: url,
@ -100,18 +45,16 @@ function getAPI (url, callback) {
success: function (response) {
if (response.status === "success") {
if (callback !== undefined) {
callback(response.data);
callback(null, response.data);
}
}
else {
console.warn(response.msg);
callback(response.msg);
}
}
}).fail(function () {
console.warn("Failed connecting to " + url);
getAPI(url, callback);
});
callback("Failed connecting to " + url);
});
}
function loadSettings (url, callback) {

View File

@ -42,10 +42,11 @@ self.addEventListener("message", function (event) {
case "SLICE":
var gcode = slicer.getGCode(printer);
var blob = new Blob([gcode], {type: 'text/html'});
self.postMessage({
"cmd": "GCODE",
"gcode": gcode
"gcode": blob
});
break;

View File

@ -92,7 +92,7 @@ function init () {
};
var loader = new THREE.STLLoader();
loader.load('models/robot.stl', function (geometry) {
loader.load('models/pokemon/pikachu.stl', function (geometry) {
//var geometry = new THREE.TorusGeometry(20, 10, 30, 30).clone();
var material = new THREE.MeshPhongMaterial({color: 0x00ff00, wireframe: false});