Skip to content

Commit

Permalink
[MI-1394]: fix issue with weird artifacts in visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiabeluli committed Mar 7, 2024
1 parent 4c0ae8b commit 40017a1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 67 deletions.
74 changes: 20 additions & 54 deletions src/app/lib/GCodeVirtualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,6 @@ class GCodeVirtualizer extends EventEmitter {
];
feedrateCounter = 0;

hasSetV1 = false;

handlers = {
// G0: Rapid Linear Move
'G0': (params) => {
Expand Down Expand Up @@ -244,19 +242,11 @@ class GCodeVirtualizer extends EventEmitter {
this.updateBounds(targetPosition);
this.setPosition(targetPosition.x, targetPosition.y, targetPosition.z, targetPosition.a);

if (!this.hasSetV1) {
this.data[this.totalLines].lineData = {
v1: this.offsetG92(v1),
v2: this.offsetG92(v2),
shouldUseAddCurve: isCurvedLine && angleDiff > ANGLE_THRESHOLD,
};
this.hasSetV1 = true;
} else {
this.data[this.totalLines].lineData = {
v2: this.offsetG92(v2),
shouldUseAddCurve: isCurvedLine && angleDiff > ANGLE_THRESHOLD,
};
}
this.data[this.totalLines].lineData = {
v1: this.offsetG92(v1),
v2: this.offsetG92(v2),
shouldUseAddCurve: isCurvedLine && angleDiff > ANGLE_THRESHOLD,
};
},
// G1: Linear Move
// Usage
Expand Down Expand Up @@ -307,19 +297,11 @@ class GCodeVirtualizer extends EventEmitter {
this.updateBounds(targetPosition);
this.setPosition(targetPosition.x, targetPosition.y, targetPosition.z, targetPosition.a);

if (!this.hasSetV1) {
this.data[this.totalLines].lineData = {
v1: this.offsetG92(v1),
v2: this.offsetG92(v2),
shouldUseAddCurve: isCurvedLine && angleDiff > ANGLE_THRESHOLD,
};
this.hasSetV1 = true;
} else {
this.data[this.totalLines].lineData = {
v2: this.offsetG92(v2),
shouldUseAddCurve: isCurvedLine && angleDiff > ANGLE_THRESHOLD,
};
}
this.data[this.totalLines].lineData = {
v1: this.offsetG92(v1),
v2: this.offsetG92(v2),
shouldUseAddCurve: isCurvedLine && angleDiff > ANGLE_THRESHOLD,
};
},
// G2 & G3: Controlled Arc Move
// Usage
Expand Down Expand Up @@ -410,19 +392,11 @@ class GCodeVirtualizer extends EventEmitter {
this.updateBounds(targetPosition);
this.setPosition(targetPosition.x, targetPosition.y, targetPosition.z);

if (!this.hasSetV1) {
this.data[this.totalLines].lineData = {
v1: this.offsetG92(v1),
v2: this.offsetG92(v2),
v0: this.offsetG92(v0)
};
this.hasSetV1 = true;
} else {
this.data[this.totalLines].lineData = {
v2: this.offsetG92(v2),
v0: this.offsetG92(v0)
};
}
this.data[this.totalLines].lineData = {
v1: this.offsetG92(v1),
v2: this.offsetG92(v2),
v0: this.offsetG92(v0)
};
},
'G3': (params) => {
if (this.modal.motion !== 'G3') {
Expand Down Expand Up @@ -494,19 +468,11 @@ class GCodeVirtualizer extends EventEmitter {
this.updateBounds(targetPosition);
this.setPosition(targetPosition.x, targetPosition.y, targetPosition.z);

if (!this.hasSetV1) {
this.data[this.totalLines].lineData = {
v1: this.offsetG92(v1),
v2: this.offsetG92(v2),
v0: this.offsetG92(v0)
};
this.hasSetV1 = true;
} else {
this.data[this.totalLines].lineData = {
v2: this.offsetG92(v2),
v0: this.offsetG92(v0)
};
}
this.data[this.totalLines].lineData = {
v1: this.offsetG92(v1),
v2: this.offsetG92(v2),
v0: this.offsetG92(v0)
};
},
// G4: Dwell
// Parameters
Expand Down
15 changes: 2 additions & 13 deletions src/app/workers/Visualize.worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,21 +406,10 @@ onmessage = function({ data }) {

const entry = data[i];
if (entry.lineData) {
const { v2, v0, shouldUseAddCurve } = entry.lineData;
// use previous v2 as v1 unless there is no previous entry
let v1 = entry.lineData.v1;
if (!v1) {
// sometimes the last line doesn't have movements, so we must search for the last line with a movement
for (let x = i - 1; x >= 0; x--) {
if (data[x].lineData && data[x].lineData.v2) {
v1 = data[x].lineData.v2;
break;
}
}
}
const { v1, v2, v0, shouldUseAddCurve, dwellTime } = entry.lineData;

if (modal.motion === 'G4') {
vm.addToTotalTime(entry.lineData.dwellTime);
vm.addToTotalTime(dwellTime);
} else {
const targetPosition = { x: v2.x, y: v2.y, z: v2.z };
if (modal.motion === 'G1' || modal.motion === 'G0') {
Expand Down

0 comments on commit 40017a1

Please sign in to comment.