Skip to content

Commit

Permalink
Laser offset fix for 13 and imperial
Browse files Browse the repository at this point in the history
  • Loading branch information
kglovern committed Feb 16, 2024
1 parent a7554a7 commit acc268e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/app/lib/rounding.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const roundMetric = (val) => {
};

export const round = (val, units) => {
if (units === METRIC_UNITS) {
if (units === METRIC_UNITS || units === 'G21') {
return roundMetric(val);
} else {
return roundImperial(val);
Expand Down
24 changes: 14 additions & 10 deletions src/app/widgets/Spindle/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import {
GRBL_ACTIVE_STATE_IDLE,
IMPERIAL_UNITS,
LASER_MODE,
METRIC_UNITS,
SPINDLE_LASER_CATEGORY,
SPINDLE_MODE,
WORKFLOW_STATE_RUNNING
Expand Down Expand Up @@ -405,12 +404,16 @@ class SpindleWidget extends PureComponent {
}

// Take into account the current wpos when setting offsets
calculateAdjustedOffsets(xOffset, yOffset) {
calculateAdjustedOffsets(xOffset, yOffset, units) {
const { wpos, $13 } = this.props;
const { x, y } = wpos;
let units = METRIC_UNITS;
if ($13 === '1') {
units = IMPERIAL_UNITS;
let { x, y } = wpos;

console.log(units);

if ($13 === '1' || units === 'G20') {
units = 'G20';
x /= 25.4;
y /= 25.4;
}
return [round(Number(x) + Number(xOffset), units), round(Number(y) + Number(yOffset), units)];
}
Expand All @@ -422,14 +425,15 @@ class SpindleWidget extends PureComponent {
laser
});
let { xOffset, yOffset } = laser;
if (preferredUnits === IMPERIAL_UNITS) {
if (preferredUnits === 'G20') {
xOffset = convertToImperial(xOffset);
yOffset = convertToImperial(yOffset);
} else {
xOffset = roundMetric(xOffset);
yOffset = roundMetric(yOffset);
}
const [xoffsetAdjusted, yOffsetAdjusted] = this.calculateAdjustedOffsets(xOffset, yOffset);
const [xoffsetAdjusted, yOffsetAdjusted] = this.calculateAdjustedOffsets(xOffset, yOffset, preferredUnits);
console.log(`x: ${xoffsetAdjusted}, y: ${yOffsetAdjusted}`);

let offsetQuery = [];
if (xOffset === 0 && yOffset !== 0) {
Expand Down Expand Up @@ -457,14 +461,14 @@ class SpindleWidget extends PureComponent {
let { xOffset, yOffset } = laser;
xOffset = Number(xOffset) * -1;
yOffset = Number(yOffset) * -1;
if (preferredUnits === IMPERIAL_UNITS) {
if (preferredUnits === 'G20') {
xOffset = convertToImperial(xOffset);
yOffset = convertToImperial(yOffset);
} else {
xOffset = roundMetric(xOffset);
yOffset = roundMetric(yOffset);
}
const [xoffsetAdjusted, yOffsetAdjusted] = this.calculateAdjustedOffsets(xOffset, yOffset);
const [xoffsetAdjusted, yOffsetAdjusted] = this.calculateAdjustedOffsets(xOffset, yOffset, preferredUnits);
if (xOffset === 0 && yOffset !== 0) {
offsetQuery = [
`G10 L20 P${this.getWCS()} Y${yOffsetAdjusted}`
Expand Down

0 comments on commit acc268e

Please sign in to comment.