Skip to content

Commit

Permalink
Merge pull request #509 from Sienci-Labs/MI-1458-Start-From-Line-Incl…
Browse files Browse the repository at this point in the history
…ude-A

Include A Axis in Start From Line Calcs
  • Loading branch information
walidkayhan committed Jun 5, 2024
2 parents e576658 + 670e5e0 commit 37ee727
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"express": "~4.16.4",
"express-jwt": "~5.3.1",
"express-session": "~1.16.1",
"gcode-interpreter": "~2.1.0",
"gcode-parser": "~1.3.6",
"gcode-toolpath": "~2.2.0",
"hogan.js": "~3.0.2",
"http-proxy": "~1.18.1",
"i18next": "~15.0.9",
Expand Down
8 changes: 6 additions & 2 deletions src/server/controllers/Grbl/GrblController.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

import ensureArray from 'ensure-array';
import * as parser from 'gcode-parser';
import Toolpath from 'gcode-toolpath';
import _ from 'lodash';
import map from 'lodash/map';
import GcodeToolpath from '../../lib/GcodeToolpath';
import SerialConnection from '../../lib/SerialConnection';
import EventTrigger from '../../lib/EventTrigger';
import Feeder from '../../lib/Feeder';
Expand Down Expand Up @@ -1523,7 +1523,7 @@ class GrblController {
return 0;
};

const toolpath = new Toolpath();
const toolpath = new GcodeToolpath();
toolpath.loadFromStringSync(firstHalf.join('\n'), (data) => {
const { words, line } = data;
if (line.includes('F')) {
Expand Down Expand Up @@ -1556,6 +1556,7 @@ class GrblController {
x: xVal,
y: yVal,
z: zVal,
a: aVal
} = position;

const modalGCode = [];
Expand All @@ -1573,6 +1574,9 @@ class GrblController {
modalGCode.push(this.event.getEventCode(PROGRAM_START));
modalGCode.push(`G0 G90 G21 Z${zMax + safeHeight}`);
modalGCode.push(`G0 G90 G21 X${xVal.toFixed(3)} Y${yVal.toFixed(3)}`);
if (aVal) {
modalGCode.push(`G0 G90 G21 A${(Number(aVal) % 360).toFixed(3)}`);
}
modalGCode.push(`G0 G90 G21 Z${zVal.toFixed(3)}`);
// Set modals based on what's parsed so far in the file
modalGCode.push(`${modal.units} ${modal.distance} ${modal.arc} ${modalWcs} ${modal.plane} ${modal.spindle} ${coolant.flood} ${coolant.mist}`);
Expand Down
9 changes: 7 additions & 2 deletions src/server/controllers/Grblhal/GrblHalController.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

import ensureArray from 'ensure-array';
import * as parser from 'gcode-parser';
import Toolpath from 'gcode-toolpath';
import _ from 'lodash';
import map from 'lodash/map';
import GcodeToolpath from '../../lib/GcodeToolpath';
import SerialConnection from '../../lib/SerialConnection';
import EventTrigger from '../../lib/EventTrigger';
import Feeder from '../../lib/Feeder';
Expand Down Expand Up @@ -1553,7 +1553,7 @@ class GrblHalController {
return 0;
};

const toolpath = new Toolpath();
const toolpath = new GcodeToolpath();
toolpath.loadFromStringSync(firstHalf.join('\n'), (data) => {
const { words, line } = data;
if (line.includes('F')) {
Expand Down Expand Up @@ -1586,6 +1586,7 @@ class GrblHalController {
x: xVal,
y: yVal,
z: zVal,
a: aVal
} = position;

const modalGCode = [];
Expand All @@ -1604,13 +1605,17 @@ class GrblHalController {
modalGCode.push(this.event.getEventCode(PROGRAM_START));
modalGCode.push(`G0 G90 G21 Z${zMax + safeHeight}`);
modalGCode.push(`G0 G90 G21 X${xVal.toFixed(3)} Y${yVal.toFixed(3)}`);
if (aVal) {
modalGCode.push(`G0 G90 G21 A${(Number(aVal) % 360).toFixed(3)}`);
}
modalGCode.push(`G0 G90 G21 Z${zVal.toFixed(3)}`);
// Set modals based on what's parsed so far in the file
modalGCode.push(`${modal.units} ${modal.distance} ${modal.arc} ${modalWcs} ${modal.plane} ${modal.spindle} ${coolant.flood} ${coolant.mist}`);
modalGCode.push(`F${feedRate} S${spindleRate}`);
modalGCode.push(setModalGcode);
modalGCode.push('G4 P1');
modalGCode.push('%_GCODE_START');
// console.log(modalGCode);

// Fast forward sender to line
this.sender.setStartLine(lineToStartFrom);
Expand Down
18 changes: 12 additions & 6 deletions src/app/lib/GcodeToolpath.js → src/server/lib/GcodeToolpath.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,13 @@ class GcodeToolpath {
x: this.position.x,
y: this.position.y,
z: this.position.z,
a: this.position.a
};
const v2 = {
x: this.translateX(params.X),
y: this.translateY(params.Y),
z: this.translateZ(params.Z),
a: this.translateA(params.A)
};
const v0 = {
// fixed point
Expand All @@ -288,7 +290,7 @@ class GcodeToolpath {
z: this.translateK(params.K),
};
const isClockwise = true;
const targetPosition = { x: v2.x, y: v2.y, z: v2.z };
const targetPosition = { x: v2.x, y: v2.y, z: v2.z, a: v2.a };

if (this.isXYPlane()) {
// XY-plane
Expand Down Expand Up @@ -337,7 +339,8 @@ class GcodeToolpath {
this.setPosition(
targetPosition.x,
targetPosition.y,
targetPosition.z
targetPosition.z,
targetPosition.a
);
},
'G3': (params) => {
Expand All @@ -349,11 +352,13 @@ class GcodeToolpath {
x: this.position.x,
y: this.position.y,
z: this.position.z,
a: this.position.a
};
const v2 = {
x: this.translateX(params.X),
y: this.translateY(params.Y),
z: this.translateZ(params.Z),
a: this.translateA(params.A)
};
const v0 = {
// fixed point
Expand All @@ -362,7 +367,7 @@ class GcodeToolpath {
z: this.translateK(params.K),
};
const isClockwise = false;
const targetPosition = { x: v2.x, y: v2.y, z: v2.z };
const targetPosition = { x: v2.x, y: v2.y, z: v2.z, a: v2.a };

if (this.isXYPlane()) {
// XY-plane
Expand Down Expand Up @@ -411,7 +416,8 @@ class GcodeToolpath {
this.setPosition(
targetPosition.x,
targetPosition.y,
targetPosition.z
targetPosition.z,
targetPosition.a
);
},
// G4: Dwell
Expand Down Expand Up @@ -734,8 +740,8 @@ class GcodeToolpath {

// Position
if (position) {
const { x, y, z } = { ...position };
this.setPosition(x, y, z);
const { x, y, z, a } = { ...position };
this.setPosition(x, y, z, a);
}

// Modal
Expand Down

0 comments on commit 37ee727

Please sign in to comment.