patch up laser mode and layer transitions

This commit is contained in:
Stewart Allen 2022-10-19 00:11:54 -04:00
commit 829139c440
7 changed files with 57 additions and 52 deletions

View file

@ -55,7 +55,6 @@ CAM.export = function(print, online) {
points = 0,
lasering = false,
laserOp,
currentOp,
stock = settings.stock || { },
hasStock = spro.camStockOn && stock.x && stock.y && stock.z,
ztOff = hasStock ? stock.z - widget.track.top : 0,
@ -99,7 +98,12 @@ CAM.export = function(print, online) {
}
function filterEmit(array, consts) {
if (!array) return;
if (!array) {
return;
}
if (typeof(array) === 'string') {
array = array.split('\n');
}
for (i=0; i<array.length; i++) {
line = print.constReplace(array[i], consts);
if (!isRML && stripComments && (cidx = line.indexOf(";")) >= 0) {
@ -168,7 +172,7 @@ CAM.export = function(print, online) {
pos.t = out.tool;
consts.tool = pos.t;
consts.tool_name = toolNameByNumber(out.tool);
if (!lasering) {
if (!laserOp) {
filterEmit(cmdToolChange, { ...consts, spindle: newSpindle } );
}
}
@ -176,7 +180,7 @@ CAM.export = function(print, online) {
// on spindle change (deferred from layer transition so it's post-toolchange)
if ((changeTool && spindleMax) || (newSpindle && newSpindle !== spindle)) {
spindle = newSpindle;
if (!lasering) {
if (!laserOp) {
if (spindle > 0) {
let speed = Math.abs(spindle);
filterEmit(cmdSpindle, { speed, spindle: speed, rpm: speed });
@ -306,20 +310,12 @@ CAM.export = function(print, online) {
// collect tool info to add to header
let toolz = {}, ctool;
// remap points as necessary for origins, offsets, inversions
print.output.forEach(function(layer) {
print.output.forEach(layer => {
if (!Array.isArray(layer)) {
return;
}
layer.forEach(function(out) {
if (out.op) {
if (out.op.type === 'laser on') {
laserOp = out.op;
// lasering = true;
// console.log('laser on');
} else if (out.op.type === 'laser off') {
// lasering = false;
// console.log('laser off');
}
layer.forEach(out => {
if (out.gcode) {
return;
}
if (out.tool && out.tool !== ctool) {
@ -354,34 +350,47 @@ CAM.export = function(print, online) {
// emit all points in layer/point order
for (let layerout of print.output) {
if (!Array.isArray(layerout)) {
append(layerout.toString().trim());
continue;
}
if (mode !== layerout.mode || consts.tool !== layerout[0].tool) {
if (mode && !stripComments) {
append("; ending " + mode + " op after " + Math.round(time/60) + " seconds");
const newmode = layerout.mode;
if (newmode) {
if (newmode.type === 'laser on') {
laserOp = newmode;
} else if (newmode.type === 'laser off') {
laserOp = undefined;
// force tool change in case laser tool matches next tool
pos.t = undefined;
}
mode = layerout.mode;
}
const firstOut = layerout[0];
if (newmode && !newmode.silent && mode !== newmode) {
if (mode && !stripComments) {
append("; ending " + mode.type + " op after " + Math.round(time/60) + " seconds");
}
mode = newmode;
if (mode) {
section(`op-${opnum++}-${mode}`);
section(`op-${opnum++}-${mode.type}`);
}
if (!stripComments && mode) {
append("; starting " + mode + " op");
append("; starting " + mode.type + " op");
}
}
newSpindle = layerout.spindle;
// iterate over layer output records
for (let out of layerout) {
if (out.op) {
currentOp = out.op;
continue;
if (out.gcode && Array.isArray(out.gcode)) {
filterEmit(out.gcode, consts);
} else {
moveTo(out);
}
moveTo(out);
}
if (lasering && laserOp) {
// disable laser
filterEmit(laserOp.off, consts);
lasering = false;
}
}
if (mode && !stripComments) {
append("; ending " + mode + " op after " + Math.round(time/60) + " seconds");
append("; ending " + mode.type + " op after " + Math.round(time/60) + " seconds");
}
// emit gcode post

View file

@ -54,9 +54,9 @@ class OpLaserOn extends CamOp {
}
prepare(ops, progress) {
this.op.silent = true;
ops.addGCode(this.op.enable);
ops.setLasering(true, this.op.power);
ops.newLayer();
}
}
@ -66,9 +66,9 @@ class OpLaserOff extends CamOp {
}
prepare(ops, progress) {
this.op.silent = true;
ops.addGCode(this.op.disable);
ops.setLasering(false);
ops.newLayer();
}
}

View file

@ -120,26 +120,23 @@ function prepEach(widget, settings, print, firstPoint, update) {
};
}) : zmax;
newOutput.push(layerOut);
function newLayer() {
if (layerOut.length < 2) {
return;
function newLayer(op) {
if (layerOut.length || layerOut.mode) {
newOutput.push(layerOut);
}
newOutput.push(layerOut);
layerOut = [];
layerOut.mode = lastMode;
layerOut.mode = op || lastMode;
layerOut.spindle = spindle;
}
function addGCode(text) {
if (!text || text.length === 0) {
if (!text && text.length) {
return;
}
if (Array.isArray(text)) {
text = text.join('\r\n');
if (!Array.isArray(text)) {
text = text.trim().split('\n');
}
newOutput.push(text);
newOutput.push([{ gcode: text }]);
if (layerOut.length) {
layerOut = [];
layerOut.mode = lastMode;
@ -423,10 +420,9 @@ function prepEach(widget, settings, print, firstPoint, update) {
for (let op of widget.camops) {
setTolerance(0);
nextIsMove = true;
lastMode = op.op.type;
lastMode = op.op;
let weight = op.weight();
newLayer();
layerOut.push({ op: op.op });
newLayer(op.op);
op.prepare(ops, (progress, message) => {
update((opSum + (progress * weight)) / opTot, message || op.type(), message);
});

View file

@ -160,7 +160,7 @@ CAM.slice = function(settings, widget, onupdate, ondone) {
let opList = [
// silently preface op list with OpShadow
new CAM.OPS.shadow(state, { type: "shadow" })
new CAM.OPS.shadow(state, { type: "shadow", silent: true })
];
if (false) {

View file

@ -527,10 +527,10 @@ const conf = exports({
camRegisterThru: 5,
camFlipAxis: "X",
camFlipOther: "",
camLaserEnable: "M321",
camLaserDisable: "M322",
camLaserOn: "M3",
camLaserOff: "M5",
camLaserEnable: ["M321"],
camLaserDisable: ["M322"],
camLaserOn: ["M3"],
camLaserOff: ["M5"],
camLaserSpeed: 100,
camLaserPower: 1,
// camDrillReg: "none",

View file

@ -105,7 +105,7 @@ function prepareSlices(callback, scale = 1, offset = 0) {
process.beltAnchor = Math.max(
process.firstLayerBeltLead,
Math.sqrt(process.outputPurgeTower) * extruders.length * (1/Math.sqrt(2)));
} else {
} else if (isBelt) {
process.beltAnchor = process.firstLayerBeltLead;
}

View file

@ -141,8 +141,8 @@ async function path(levels, update, opts = {}) {
let emits = 0;
level.forEach(out => {
// skip cam op records
if (out.op) {
// skip cam gcode records
if (out.gcode) {
return;
}
if (retracted && out.emit) {