diff --git a/src/package.json b/src/package.json index dbb4a29ea..acf0b7fda 100644 --- a/src/package.json +++ b/src/package.json @@ -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", diff --git a/src/server/controllers/Grbl/GrblController.js b/src/server/controllers/Grbl/GrblController.js index 3a1cc0699..649ac3e05 100644 --- a/src/server/controllers/Grbl/GrblController.js +++ b/src/server/controllers/Grbl/GrblController.js @@ -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'; @@ -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')) { @@ -1556,6 +1556,7 @@ class GrblController { x: xVal, y: yVal, z: zVal, + a: aVal } = position; const modalGCode = []; @@ -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}`); diff --git a/src/server/controllers/Grblhal/GrblHalController.js b/src/server/controllers/Grblhal/GrblHalController.js index e8cd3b583..b3f0089d4 100644 --- a/src/server/controllers/Grblhal/GrblHalController.js +++ b/src/server/controllers/Grblhal/GrblHalController.js @@ -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'; @@ -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')) { @@ -1586,6 +1586,7 @@ class GrblHalController { x: xVal, y: yVal, z: zVal, + a: aVal } = position; const modalGCode = []; @@ -1604,6 +1605,9 @@ 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}`); @@ -1611,6 +1615,7 @@ class GrblHalController { modalGCode.push(setModalGcode); modalGCode.push('G4 P1'); modalGCode.push('%_GCODE_START'); + // console.log(modalGCode); // Fast forward sender to line this.sender.setStartLine(lineToStartFrom); diff --git a/src/app/lib/GcodeToolpath.js b/src/server/lib/GcodeToolpath.js similarity index 98% rename from src/app/lib/GcodeToolpath.js rename to src/server/lib/GcodeToolpath.js index 08644c71d..92320f117 100644 --- a/src/app/lib/GcodeToolpath.js +++ b/src/server/lib/GcodeToolpath.js @@ -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 @@ -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 @@ -337,7 +339,8 @@ class GcodeToolpath { this.setPosition( targetPosition.x, targetPosition.y, - targetPosition.z + targetPosition.z, + targetPosition.a ); }, 'G3': (params) => { @@ -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 @@ -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 @@ -411,7 +416,8 @@ class GcodeToolpath { this.setPosition( targetPosition.x, targetPosition.y, - targetPosition.z + targetPosition.z, + targetPosition.a ); }, // G4: Dwell @@ -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