From d0cef6eedcd92f6657979dbd9fd0d0490ec7ef6a Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Sat, 9 Jan 2021 21:08:24 -0500 Subject: [PATCH] checkpoint belt work --- src/kiri/main.js | 14 +++++------ src/kiri/print.js | 17 +++++-------- src/kiri/worker.js | 8 ++++-- src/mode/fdm/export.js | 2 +- src/mode/fdm/prepare.js | 56 ++++++++++++++++++----------------------- src/mode/fdm/slice.js | 6 ----- 6 files changed, 44 insertions(+), 59 deletions(-) diff --git a/src/kiri/main.js b/src/kiri/main.js index d2195253..2142ae15 100644 --- a/src/kiri/main.js +++ b/src/kiri/main.js @@ -938,11 +938,11 @@ setOpacity(color.preview_opacity); } - let segtimes = {}, + let now = Date.now(), segNumber = 0, + segtimes = {}, startTime, lastMsg, - now = Date.now(), output = []; KIRI.client.prepare(settings, function(progress, message, layer) { @@ -966,7 +966,6 @@ API.show.progress(0); if (!isCam) setOpacity(0); - // output = KIRI.codec.decode(output); if (feature.preview && output.length) { startTime = Date.now(); STACKS.clear(); @@ -977,10 +976,9 @@ // rotate stack for belt beds if (settings.device.bedBelt && WIDGETS[0].rotinfo) { let ri = WIDGETS[0].rotinfo; - // console.log(ri) - // ri.dy = ri.dz = 0; - // ri.dy = settings.device.bedDepth / 2 - ri.ypos; - // stack.obj.rotate(WIDGETS[0].rotinfo); + ri.dz = 0; + ri.dy = settings.device.bedDepth / 2; + stack.obj.rotate(WIDGETS[0].rotinfo); } segtimes[`${segNumber}_draw`] = Date.now() - startTime; } @@ -1688,7 +1686,7 @@ if (isBelt) { let bounds = platformUpdateBounds(), movey = -(dev.bedDepth / 2 + bounds.min.y); - forAllWidgets(widget => widget.move(0, movey + 0, 0)); + forAllWidgets(widget => widget.move(0, movey + 10, 0)); } platform.update_origin(); diff --git a/src/kiri/print.js b/src/kiri/print.js index 307d221a..b45fab6a 100644 --- a/src/kiri/print.js +++ b/src/kiri/print.js @@ -85,9 +85,9 @@ return scope.output; }; - PRO.parseGCode = function(gcode, offset, progress, done, options) { - const opts = options || {}; + PRO.parseGCode = function(gcode, offset, progress, done, opts = {}) { const fdm = opts.fdm; + const belt = opts.belt; const lines = gcode .toUpperCase() .replace("X", " X") @@ -126,13 +126,13 @@ let dz = 0, abs = true, absE = true, - belt = false, defh = 0, height = 0, factor = 1, tool = 0, maxf = 0, seq = [], + autolayer = true, newlayer = false; const output = scope.output = [ seq ]; @@ -201,7 +201,7 @@ // non-move in a new plane means burp out // the old sequence and start a new one - if (newlayer || (!belt && seq.Z != pos.Z)) { + if (newlayer || (autolayer && seq.Z != pos.Z)) { newlayer = false; let nh = (defh || pos.Z - seq.Z); seq = []; @@ -228,10 +228,9 @@ } lines.forEach(function(line, idx) { -if (idx < 10) console.log({line}) if (line.indexOf(';LAYER:') === 0) { newlayer = true; -if (idx < 100) console.log({newlayer}); + autolayer = false; } if (line.indexOf('- LAYER ') > 0) { seq.height = defh; @@ -239,11 +238,7 @@ if (idx < 100) console.log({newlayer}); defh = parseFloat(hd[4]); if (fdm) dz = -defh / 2; newlayer = true; -if (idx < 100) console.log({layer: defh}); - } - if (line.indexOf("BED TYPE: BELT") > 0) { - belt = true; -if (idx < 100) console.log({isbelt: belt}); + autolayer = false; } line = line.split(";")[0].split(" ").filter(v => v); let cmd = line.shift(); diff --git a/src/kiri/worker.js b/src/kiri/worker.js index 87ab317f..8ebf74e4 100644 --- a/src/kiri/worker.js +++ b/src/kiri/worker.js @@ -212,8 +212,9 @@ KIRI.worker = { y: -origin.y, z: origin.z }; + const device = settings.device; const print = current.print = KIRI.newPrint(settings, Object.values(cache)); - const tools = settings.device.extruders; + const tools = device.extruders; const mode = settings.mode; const thin = settings.controller.lineType === 'line' || mode !== 'FDM'; const flat = settings.controller.lineType === 'flat' && mode === 'FDM'; @@ -225,7 +226,10 @@ KIRI.worker = { send.data({ progress: 0.25 + progress * 0.75 }); }, { thin: thin || print.belt, flat, tools }); send.done({parsed: KIRI.codec.encode(layers), maxSpeed}); - }, { fdm : mode === 'FDM' }); + }, { + fdm: mode === 'FDM', + belt: device.bedBelt + }); }, parse_svg: function(parsed, send) { diff --git a/src/mode/fdm/export.js b/src/mode/fdm/export.js index de6c6d5d..41c85a26 100644 --- a/src/mode/fdm/export.js +++ b/src/mode/fdm/export.js @@ -77,7 +77,7 @@ bytes = 0, bcos = Math.cos(Math.PI/4), icos = 1 / bcos; -console.log({isBelt, offset}); + (process.gcodePauseLayers || "").split(",").forEach(function(lv) { let v = parseInt(lv); if (v >= 0) pause.push(v); diff --git a/src/mode/fdm/prepare.js b/src/mode/fdm/prepare.js index dbb10e4c..a1b77a20 100644 --- a/src/mode/fdm/prepare.js +++ b/src/mode/fdm/prepare.js @@ -47,8 +47,7 @@ isFlat = settings.controller.lineType === "flat", isBelt = device.bedBelt, beltYoff = device.bedDepth / 2, - bcos = Math.cos(Math.PI/4), - icos = 1 / bcos; + beltfact = Math.cos(Math.PI/4); // compute bounds if missing if (!bounds) { @@ -196,32 +195,27 @@ bounds.max.y = Math.max(bounds.max.y, bbounds.maxy); } - // synthesize a support widget, if needed - if (!isBelt) { - let swidget = KIRI.newWidget(); - let sslices = swidget.slices = []; - widgets.forEach(function(widget) { - let slices = widget.slices; - while (sslices.length < slices.length) { - let sslice = KIRI.newSlice(slices[sslices.length].z); - sslice.extruder = process.sliceSupportNozzle; - sslices.push(sslice); + // synthesize support widgets when needed + // so that they can use a separate extruder + for (let widget of widgets.slice()) { + let sslices = []; + for (let slice of widget.slices) { + if (!slice.supports) { + continue; } - slices.forEach((slice,index) => { - if (!slice.supports) return; - if (!sslices[index].supports) { - sslices[index].supports = []; - } - sslices[index].supports.appendAll(slice.supports.map(p => { - if (p.fill) p.fill.forEach(p => p.move(widget.track.pos)); - return p.move(widget.track.pos); - })); - }); - }); - swidget.support = true; - swidget.mesh = { widget: swidget }; // fake for lookup - settings.widget[swidget.id] = { extruder: process.sliceSupportNozzle }; - widgets.push(swidget); + let sslice = KIRI.newSlice(slice.z); + sslice.extruder = process.sliceSupportNozzle; + sslice.supports = slice.supports.slice(); + sslices.push(sslice); + } + if (sslices.length) { + let swidget = KIRI.newWidget(); + swidget.slices = sslices; + swidget.support = true; + swidget.mesh = { widget: swidget, position: widget.mesh.position }; + settings.widget[swidget.id] = { extruder: process.sliceSupportNozzle }; + widgets.push(swidget); + } } let extruders = []; @@ -229,14 +223,14 @@ // find max layers (for updates) // generate list of used extruders for purge blocks - widgets.forEach(function(widget) { + for (let widget of widgets) { maxLayers = Math.max(maxLayers, widget.slices.length); let extruder = (settings.widget[widget.id] || {}).extruder || 0; if (!extruders[extruder]) { extruders[extruder] = {}; extcount++; } - }); + } let blokpos, walkpos, blok; if (bounds.min.x < bounds.min.y) { @@ -293,8 +287,8 @@ if (isBelt) { offset.x = widget.rotinfo.xpos; offset.y = widget.belt.miny; - offset.y += widget.rotinfo.ypos * bcos; - offset.z = widget.rotinfo.ypos * bcos; + offset.y += widget.rotinfo.ypos * beltfact; + offset.z = widget.rotinfo.ypos * beltfact; } else { // when rafts used this is non-zero offset.z = zoff; diff --git a/src/mode/fdm/slice.js b/src/mode/fdm/slice.js index 783e216d..09cd5c23 100644 --- a/src/mode/fdm/slice.js +++ b/src/mode/fdm/slice.js @@ -274,12 +274,6 @@ bounds.merge(top.poly.bounds); } widget.belt.miny = -bounds.miny; - // widget.belt.yy2 = sdev.bedDepth / 2 + widget.track.pos.y; - // widget.belt = { - // offset_y: bounds.miny, - // pos_y: sdev.bedDepth / 2 + widget.track.pos.y, - // ypos: widget.belt.ypos - // }; } // report slicing complete