Skip to content

Commit 8c43ca8

Browse files
committed
Added incremental
1 parent 0953d60 commit 8c43ca8

1 file changed

Lines changed: 34 additions & 28 deletions

File tree

src/views/providers/gcodeRuntimeParser.ts

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,27 @@ export class GCodeRuntimeParser {
111111

112112
// Coords
113113
if (letter === 'X') {
114-
newpt.x = +argument;
114+
if (!state.abs) {
115+
newpt.x = +argument + oldpt.x;
116+
} else {
117+
newpt.x = +argument;
118+
}
115119
}
116120

117121
if (letter === 'Y') {
118-
newpt.y = +argument;
122+
if (!state.abs) {
123+
newpt.y = +argument + oldpt.y;
124+
} else {
125+
newpt.y = +argument;
126+
}
119127
}
120128

121129
if (letter === 'Z') {
122-
newpt.z = +argument;
130+
if (!state.abs) {
131+
newpt.z = +argument + oldpt.z;
132+
} else {
133+
newpt.z = +argument;
134+
}
123135
}
124136

125137
// Circular Interpolation
@@ -143,35 +155,29 @@ export class GCodeRuntimeParser {
143155

144156
// Calculate Distance Moved
145157

146-
if (state.abs) {
147-
// Absolute Mode
148-
state.distance = Math.sqrt(
149-
Math.pow(newpt.x - oldpt.x, 2) + Math.pow(newpt.y - oldpt.y, 2) + Math.pow(newpt.z - oldpt.z, 2),
150-
);
151-
152-
if (state.circ) {
153-
// Circular Interpolation
154-
const centerpt = [oldpt.x - ijkr.i, oldpt.y - ijkr.j, oldpt.z - ijkr.k];
155-
let radius: number;
156-
if (ijkr.r === -1) {
157-
// IJK Mode
158-
radius = Math.sqrt(
159-
Math.pow(centerpt[0], 2) + Math.pow(centerpt[1], 2) + Math.pow(centerpt[2], 2),
160-
);
161-
} else {
162-
// Radius Mode
163-
radius = ijkr.r;
164-
}
165-
166-
// Arc Length: ( 2( arcsin(d / 2r) ) / 2)
167-
const arclen = 2 * Math.asin(state.distance / (2 * radius)) * radius;
158+
state.distance = Math.sqrt(
159+
Math.pow(newpt.x - oldpt.x, 2) + Math.pow(newpt.y - oldpt.y, 2) + Math.pow(newpt.z - oldpt.z, 2),
160+
);
168161

169-
state.distance = arclen;
162+
if (state.circ) {
163+
// Circular Interpolation
164+
const centerpt = [oldpt.x - ijkr.i, oldpt.y - ijkr.j, oldpt.z - ijkr.k];
165+
let radius: number;
166+
if (ijkr.r === -1) {
167+
// IJK Mode
168+
radius = Math.sqrt(Math.pow(centerpt[0], 2) + Math.pow(centerpt[1], 2) + Math.pow(centerpt[2], 2));
169+
} else {
170+
// Radius Mode
171+
radius = ijkr.r;
170172
}
171173

174+
// Arc Length: ( 2( arcsin(d / 2r) ) / 2)
175+
const arclen = 2 * Math.asin(state.distance / (2 * radius)) * radius;
176+
177+
state.distance = arclen;
178+
179+
// New Point -> Old Point
172180
Object.assign(oldpt, newpt);
173-
} else {
174-
// Incremental Mode
175181
}
176182

177183
if (!state.rapid) {

0 commit comments

Comments
 (0)