changed gcode implementation from array to string

Makes more sense to store it as string rather then store it as array.
Doesn’t work with the doodle box though; think the doodle box adds \n
after each batch
This commit is contained in:
casperlamboo 2015-05-19 17:15:59 +02:00
parent ec447ab56e
commit 20e80b390e
8 changed files with 40 additions and 53 deletions

2
.gitignore vendored
View File

@ -19,3 +19,5 @@ bower_components/
src/oldcode.js
test.html
print_manager.html

View File

@ -1578,6 +1578,18 @@ THREE.Vector2.prototype = {
return new THREE.Vector2( this.x, this.y );
},
normal : function () {
var x = this.y;
var y = -this.x;
this.x = x;
this.y = y;
return this;
}
};

Binary file not shown.

View File

@ -28,7 +28,7 @@ canvas {border: 1px solid black;}
<script>
//nieuwe config
//geimplimenteerd worden in de doodlebox?
var printerConfig = {
var printer = new D3D.Printer({
"printer.baudrate": "115200", //wat is dit?
"printer.bottomFlowRate": 1.0,
"printer.bottomLayerSpeed": 35,
@ -56,8 +56,7 @@ var printerConfig = {
"printer.speed": 50,
"printer.wallThickness": 0.4, //nozzle
"printer.layerHeight": 0.2,
"printer.layerHeight": 0.3,
//variabele toevoegen;
//-snelheid, retraction etc voor verschillende types (outerlayer, innerlayer, fill)
@ -66,8 +65,7 @@ var printerConfig = {
"printer.shellThickness": 0.4,
"printer.fillSize": 5, //dit is het raster aan de binnen kant van de geometry
"printer.brimOffset": 5
};
var printer = new D3D.Printer(printerConfig);
});
var localIp = location.hash.substring(1);
var doodleBox = new D3D.Box(localIp);
@ -75,7 +73,7 @@ var doodleBox = new D3D.Box(localIp);
var scene = new THREE.Scene();
var renderer = new THREE.WebGLRenderer({canvas: document.getElementById("3d-preview")});
var renderer = new THREE.WebGLRenderer({canvas: document.getElementById("3d-preview"), antialias: true});
renderer.setClearColor(0xffffff, 1);
var camera = new THREE.PerspectiveCamera(75, renderer.domElement.width/renderer.domElement.height, 1, 10000);
@ -90,7 +88,7 @@ camera.add(directionalLight);
applyMouseControls(renderer, camera, new THREE.Vector3(100, 0, 100), 1000);
var loader = new THREE.STLLoader();
loader.load("models/d20.stl", function (geometry) {
loader.load("models/pikachu.stl", function (geometry) {
//var geometry = new THREE.BoxGeometry(10, 10, 10, 1, 1, 1);
//var geometry = new THREE.SphereGeometry(10, 10, 10);
//var geometry = new THREE.TorusGeometry(20, 10, 30, 30);
@ -119,7 +117,6 @@ loader.load("models/d20.stl", function (geometry) {
return geometry;
})();
*/
var material = new THREE.MeshPhongMaterial({color: 0x00ff00});
var mesh = new THREE.Mesh(geometry, material);
@ -128,11 +125,10 @@ loader.load("models/d20.stl", function (geometry) {
mesh.scale.x = mesh.scale.y = mesh.scale.z = 1;
mesh.position.x = 100;
mesh.position.z = 100;
//mesh.position.y = -2;
scene.add(mesh);
var slicer = new D3D.Slicer().setMesh(mesh);
slicer = new D3D.Slicer().setMesh(mesh);
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");

View File

@ -16,13 +16,15 @@ D3D.Box = function (localIp) {
"use strict";
var self = this;
this.batchSize = 512;
this.maxBufferedLines = 4096;
this.batchSize = 1024 * 10; //10kb
this.maxBufferSize = 1024 * 1024 * 2; //2mb
this.bytesSend = 0;
this.localIp = localIp;
this.api = "http://" + localIp + "/d3dapi/";
this.config = {};
this.status = {};
this.printBatches = [];
this.currentBatch = 0;
@ -59,7 +61,7 @@ D3D.Box.prototype.update = function () {
//Bij error wordt gelijk zelfde data opnieuw gestuurd
//Als DoodleBox ontkoppeld wordt komt er een error in de loop waardoor pagina breekt en ververst moet worden
if (this.printBatches.length > 0 && (this.printer.status["buffered_lines"] + this.batchSize) <= this.maxBufferedLines) {
if (this.printBatches.length > 0 && (this.status["buffered_lines"]*30 + this.batchSize) <= this.maxBufferSize) {
//if (this.printBatches.length > 0 ) {
this.printBatch();
}
@ -73,7 +75,7 @@ D3D.Box.prototype.updateState = function () {
var self = this;
this.getInfoStatus(function (data) {
self.printer.status = data;
self.status = data;
if (self.onupdate !== undefined) {
self.onupdate(data);
@ -87,12 +89,9 @@ D3D.Box.prototype.print = function (gcode) {
this.currentBatch = 0;
//clone gcode to remove array links
gcode = gcode.clone();
//gcode split in batches
while (gcode.length > 0) {
var gcodeBatch = gcode.splice(0, Math.min(this.batchSize, gcode.length));
for (var i = 0; i < gcode.length; i += this.batchSize) {
var gcodeBatch = gcode.substring(i, Math.min(i + this.batchSize, gcode.length));
this.printBatches.push(gcodeBatch);
}
@ -107,7 +106,7 @@ D3D.Box.prototype.printBatch = function () {
this.setPrinterPrint({
"start": ((this.currentBatch === 0) ? true : false),
"first": ((this.currentBatch === 0) ? true : false),
"gcode": gcode.join("\n")
"gcode": gcode
}, function (data) {
console.log("batch sent: " + self.currentBatch, data);

View File

@ -8,7 +8,6 @@
D3D.Printer = function (config) {
"use strict";
this.status = {};
this.config = {};
this.updateConfig(config);
@ -30,7 +29,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";
@ -38,7 +37,7 @@ D3D.Printer.prototype.getEndCode = function () {
var gcode = this.config["printer.endcode"];
gcode = this.subsituteVariables(gcode);
return gcode.split("\n");
return gcode;
};
D3D.Printer.prototype.subsituteVariables = function (gcode) {
"use strict";

View File

@ -163,7 +163,7 @@ D3D.Slicer.prototype.slice = function (height, step) {
index = connects[j];
if (intersections[index] && done.indexOf(index) === -1) {
var a = new THREE.Vector2().set(intersection.x, intersection.y);
var a = new THREE.Vector2(intersection.x, intersection.y);
var b = intersections[index];
var normal = a.sub(b).normal().normalize();
var faceNormal = faceNormals[Math.floor(j/2)];
@ -248,13 +248,13 @@ D3D.Slicer.prototype.slicesToData = function (slices, printer) {
var layerHeight = printer.config["printer.layerHeight"] * scale;
var dimensionsZ = printer.config["printer.dimensions.z"] * scale;
var wallThickness = printer.config["printer.wallThickness"] * scale;
var wallThickness = printer.config["printer.wallThickness"] * scale / 2;
var shellThickness = printer.config["printer.shellThickness"] * scale;
var fillSize = printer.config["printer.fillSize"] * scale;
var brimOffset = printer.config["printer.brimOffset"] * scale;
var bottomThickness = printer.config["printer.bottomThickness"] * scale;
var topThickness = printer.config["printer.topThickness"] * scale;
var bottomSkinCount = Math.ceil(bottomThickness/layerHeight);
var topSkinCount = Math.ceil(topThickness/layerHeight);
@ -452,7 +452,7 @@ D3D.Slicer.prototype.dataToGcode = function (data, printer) {
return gcode;
}
var gcode = printer.getStartCode();
var gcode = printer.getStartCode().split("\n");
var extruder = 0.0;
var speed = firstLayerSlow ? (bottomSpeed*60).toFixed(3) : (normalSpeed*60).toFixed(3);
@ -480,8 +480,7 @@ D3D.Slicer.prototype.dataToGcode = function (data, printer) {
}
}
gcode = gcode.concat(printer.getEndCode());
return gcode;
return gcode.join("\n") + "\n" + printer.getEndCode();
};
//only for debug purposes
D3D.Slicer.prototype.drawPaths = function (printer, min, max) {

View File

@ -11,16 +11,6 @@ var D3D = {
"contact": "develop@doodle3d.com"
};
//add normal function to Three.js Vector class
THREE.Vector2.prototype.normal = function () {
"use strict";
var x = this.y;
var y = -this.x;
return this.set(x, y);
};
function sendAPI (url, data, callback) {
"use strict";
@ -72,20 +62,10 @@ function getAPI (url, callback) {
function downloadFile (file, data) {
"use strict";
var blob = new Blob([data], {type:'text/plain'});
var button = document.createElement("a");
button.download = file;
button.href = "data:text/plain," + data;
button.href = window.URL.createObjectURL(blob);
button.click();
}
Array.prototype.clone = function () {
"use strict";
var array = [];
for (var i = 0; i < this.length; i ++) {
array[i] = this[i];
}
return array;
};
}