add metric/inch conversion in and out for gcode
This commit is contained in:
parent
d5490290f1
commit
bb2824a743
2 changed files with 26 additions and 13 deletions
|
|
@ -114,6 +114,7 @@
|
|||
seq = [],
|
||||
abs = true,
|
||||
move = false,
|
||||
factor = 1,
|
||||
tool = 0,
|
||||
E0G0 = false,
|
||||
G0 = function() {
|
||||
|
|
@ -154,6 +155,12 @@
|
|||
}
|
||||
}
|
||||
switch (cmd) {
|
||||
case 'G20':
|
||||
factor = 25.4;
|
||||
break;
|
||||
case 'G21':
|
||||
factor = 1;
|
||||
break;
|
||||
case 'G90':
|
||||
// absolute positioning
|
||||
abs = true;
|
||||
|
|
@ -168,12 +175,12 @@
|
|||
line.forEach(function(tok) {
|
||||
pos[tok.charAt(0)] = parseFloat(tok.substring(1));
|
||||
});
|
||||
if (pos.X) bounds.min.x = Math.min(bounds.min.x, pos.X);
|
||||
if (pos.X) bounds.max.x = Math.max(bounds.max.x, pos.X);
|
||||
if (pos.Y) bounds.min.y = Math.min(bounds.min.y, pos.Y);
|
||||
if (pos.Y) bounds.max.y = Math.max(bounds.max.y, pos.Y);
|
||||
if (pos.Z) bounds.min.z = Math.min(bounds.min.z, pos.Z);
|
||||
if (pos.Z) bounds.max.z = Math.max(bounds.max.z, pos.Z);
|
||||
if (pos.X) bounds.min.x = Math.min(bounds.min.x, pos.X * factor);
|
||||
if (pos.X) bounds.max.x = Math.max(bounds.max.x, pos.X * factor);
|
||||
if (pos.Y) bounds.min.y = Math.min(bounds.min.y, pos.Y * factor);
|
||||
if (pos.Y) bounds.max.y = Math.max(bounds.max.y, pos.Y * factor);
|
||||
if (pos.Z) bounds.min.z = Math.min(bounds.min.z, pos.Z * factor);
|
||||
if (pos.Z) bounds.max.z = Math.max(bounds.max.z, pos.Z * factor);
|
||||
if (pos.E) E0G0 = true;
|
||||
if (E0G0 && pos.E === 0.0) {
|
||||
if (LZ != pos.Z) G0();
|
||||
|
|
@ -182,9 +189,9 @@
|
|||
addOutput(
|
||||
seq,
|
||||
{
|
||||
x:pos.X + off.X + xoff.X,
|
||||
y:pos.Y + off.Y + xoff.Y,
|
||||
z:pos.Z + off.Z + xoff.Z
|
||||
x:(factor * pos.X + off.X + xoff.X),
|
||||
y:(factor * pos.Y + off.Y + xoff.Y),
|
||||
z:(factor * pos.Z + off.Z + xoff.Z)
|
||||
},
|
||||
!move,
|
||||
pos.F,
|
||||
|
|
|
|||
|
|
@ -1834,6 +1834,7 @@
|
|||
time = 0,
|
||||
lines = 0,
|
||||
bytes = 0,
|
||||
factor = 1,
|
||||
output = [],
|
||||
spindle = 0,
|
||||
modes = CPRO,
|
||||
|
|
@ -1911,6 +1912,11 @@
|
|||
line = line.substring(0, cidx).trim();
|
||||
if (line.length === 0) continue;
|
||||
}
|
||||
if (line.indexOf('G20') === 0) {
|
||||
factor = 1/25.4;
|
||||
} else if (line.indexOf('G21') === 0) {
|
||||
factor = 1;
|
||||
}
|
||||
append(line);
|
||||
}
|
||||
}
|
||||
|
|
@ -1921,7 +1927,7 @@
|
|||
if (d < 0) {
|
||||
return s + '.0';
|
||||
} else {
|
||||
return s;
|
||||
return val.toFixed(decimals);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2000,19 +2006,19 @@
|
|||
pos.x = newpos.x;
|
||||
runbox.min.x = Math.min(runbox.min.x, pos.x);
|
||||
runbox.max.x = Math.max(runbox.max.x, pos.x);
|
||||
nl.append(space).append("X").append(add0(pos.x));
|
||||
nl.append(space).append("X").append(add0(pos.x * factor));
|
||||
}
|
||||
if (newpos.y !== pos.y) {
|
||||
pos.y = newpos.y;
|
||||
runbox.min.y = Math.min(runbox.min.y, pos.y);
|
||||
runbox.max.y = Math.max(runbox.max.y, pos.y);
|
||||
nl.append(space).append("Y").append(add0(pos.y));
|
||||
nl.append(space).append("Y").append(add0(pos.y * factor));
|
||||
}
|
||||
if (newpos.z !== pos.z) {
|
||||
pos.z = newpos.z;
|
||||
runbox.min.z = Math.min(runbox.min.z, pos.z);
|
||||
runbox.max.z = Math.max(runbox.max.z, pos.z);
|
||||
nl.append(space).append("Z").append(add0(pos.z));
|
||||
nl.append(space).append("Z").append(add0(pos.z * factor));
|
||||
}
|
||||
if (feed && feed !== pos.f) {
|
||||
pos.f = feed;
|
||||
|
|
|
|||
Loading…
Reference in a new issue