update gcode parser to handle compact notations. fix up/over forced moves

This commit is contained in:
Stewart Allen 2023-01-19 21:56:41 -05:00
commit e973792ef6
3 changed files with 28 additions and 17 deletions

View file

@ -386,6 +386,7 @@ CAM.export = function(print, online) {
// collect tool info to add to header // collect tool info to add to header
let toolz = {}, ctool; let toolz = {}, ctool;
const isOffset = offset && (offset.x || offset.y);
// remap points as necessary for origins, offsets, inversions // remap points as necessary for origins, offsets, inversions
print.output.forEach(layer => { print.output.forEach(layer => {
if (!Array.isArray(layer)) { if (!Array.isArray(layer)) {
@ -403,7 +404,7 @@ CAM.export = function(print, online) {
if (!point || point.mod) return; if (!point || point.mod) return;
// ensure not point is modified twice // ensure not point is modified twice
point.mod = 1; point.mod = 1;
if (offset) { if (isOffset) {
point.x += offset.x; point.x += offset.x;
point.y += offset.y; point.y += offset.y;
} }

View file

@ -361,18 +361,20 @@ function prepEach(widget, settings, print, firstPoint, update) {
maxToolDiam/2, maxToolDiam/2,
zclear zclear
), ),
mustGoUp = Math.max(maxz - point.z, maxz - lastPoint.z) >= tolerance, maxZdelta = Math.max(maxz - point.z, maxz - lastPoint.z),
mustGoUp = maxZdelta >= tolerance,
clearz = maxz; clearz = maxz;
if (zmax_force) { if (zmax_force) {
clearz = maxz = zmax + zadd; clearz = maxz = zmax + zadd;
} }
// up if any point between higher than start/outline, go up first // up if any point between higher than start/outline, go up first
if (mustGoUp) { const zIsBelow = point.z < maxz;
layerPush(lastPoint.clone().setZ(clearz + ztOff), 0, 0, tool.getNumber()); if (mustGoUp || zIsBelow) {
const zClearance = clearz + ztOff;
if (zIsBelow) {
layerPush(lastPoint.clone().setZ(zClearance), 0, 0, tool.getNumber());
} }
// move to point above target point layerPush(point.clone().setZ(zClearance), 0, 0, tool.getNumber());
if (mustGoUp || point.z < maxz) {
layerPush(point.clone().setZ(clearz + ztOff), 0, 0, tool.getNumber());
// new pos for plunge calc // new pos for plunge calc
deltaXY = 0; deltaXY = 0;
} }

View file

@ -216,13 +216,16 @@ class Print {
const belt = opts.belt; const belt = opts.belt;
const lines = gcode const lines = gcode
.toUpperCase() .toUpperCase()
.replace("X", " X") .replaceAll("X", " X")
.replace("Y", " Y") .replaceAll("Y", " Y")
.replace("Z", " Z") .replaceAll("Z", " Z")
.replace("A", " A") .replaceAll("A", " A")
.replace("E", " E") .replaceAll("E", " E")
.replace("F", " F") .replaceAll("F", " F")
.replace(" ", " ") .replaceAll("G", " G")
.replaceAll("I", " I")
.replaceAll("J", " J")
.replaceAll(" ", " ")
.split("\n"); .split("\n");
const scope = this, const scope = this,
@ -264,7 +267,8 @@ class Print {
autolayer = true, autolayer = true,
newlayer = false, newlayer = false,
arcdivs = Math.PI / 24, arcdivs = Math.PI / 24,
hasmoved = false; hasmoved = false,
lastG = 'G1';
const output = scope.output = [ seq ]; const output = scope.output = [ seq ];
const beltaxis = { X: "X", Y: "Z", Z: "Y", E: "E", F: "F" }; const beltaxis = { X: "X", Y: "Z", Z: "Y", E: "E", F: "F" };
@ -359,6 +363,8 @@ class Print {
const mov = {}; const mov = {};
const axes = {}; const axes = {};
lastG = g0 ? 'G0' : 'G1';
line.forEach(tok => { line.forEach(tok => {
let axis = tok.charAt(0); let axis = tok.charAt(0);
if (morph && belt) { if (morph && belt) {
@ -479,7 +485,9 @@ class Print {
// line = `G0${line}`; // line = `G0${line}`;
// } // }
line = line.trim().split(";")[0].split(" ").filter(v => v); line = line.trim().split(";")[0].split(" ").filter(v => v);
let cmd = line.shift(); if (!line.length) return;
const c0 = line[0].charAt(0);
let cmd = ["X","Y","Z"].indexOf(c0) >= 0 ? lastG : line.shift();
if (!cmd) return; if (!cmd) return;
if (cmd.charAt(0) === 'T') { if (cmd.charAt(0) === 'T') {
let ext = scope.settings.device.extruders; let ext = scope.settings.device.extruders;