Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/MI-1301-Time-Estimate-Not-Updati…
Browse files Browse the repository at this point in the history
…ng-With-EEPROM' into dev
  • Loading branch information
kglovern committed Dec 19, 2023
2 parents 4202aa5 + cc44212 commit f8ae07a
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 14 deletions.
57 changes: 51 additions & 6 deletions src/app/lib/GCodeVirtualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ class GCodeVirtualizer extends EventEmitter {
];
modalCounter = 0;

feedrateChanges = [
{
change: null,
count: 0
}
];
feedrateCounter = 0;

hasSetV1 = false;

handlers = {
Expand Down Expand Up @@ -505,12 +513,22 @@ class GCodeVirtualizer extends EventEmitter {
// Example
// G4 P200
'G4': (params) => {
if (this.modal.motion !== 'G4') {
this.setModal({ motion: 'G4' });
this.saveModal({ motion: 'G4' });
}
let dwellTime = 0;
if (params.P) {
this.totalTime += params.P / 1000;
dwellTime = params.P / 1000;
}
if (params.S) {
this.totalTime += params.S;
dwellTime = params.S;
}
this.totalTime += dwellTime;

this.data[this.totalLines].lineData = {
dwellTime: dwellTime
};
},
// G10: Coordinate System Data Tool and Work Offset Tables
'G10': (params) => {
Expand Down Expand Up @@ -931,6 +949,7 @@ class GCodeVirtualizer extends EventEmitter {
if (letter === 'F') {
this.feed = code;
this.vmState.feedrates.add(`F${code}`);
this.saveFeedrate(code);
}
if (letter === 'S') {
this.vmState.spindle.add(`S${code}`);
Expand Down Expand Up @@ -1004,6 +1023,7 @@ class GCodeVirtualizer extends EventEmitter {
lineData: null
});
this.modalCounter++;
this.feedrateCounter++;

this.totalLines += 1;
this.fn.callback();
Expand Down Expand Up @@ -1055,6 +1075,11 @@ class GCodeVirtualizer extends EventEmitter {
return this.modal;
}

setFeedrate(feed) {
this.feed = feed;
return this.feed;
}

isMetricUnits() { // mm
return this.modal.units === 'G21';
}
Expand Down Expand Up @@ -1204,12 +1229,13 @@ class GCodeVirtualizer extends EventEmitter {
};
}

calculateMachiningTime(endPos) {
calculateMachiningTime(endPos, v1) {
let moveDuration = 0;
let currentPos = v1 || this.position;

const dx = endPos.x - this.position.x;
const dy = endPos.y - this.position.y;
const dz = endPos.z - this.position.z;
const dx = endPos.x - currentPos.x;
const dy = endPos.y - currentPos.y;
const dz = endPos.z - currentPos.z;

let travelXY = Math.hypot(dx, dy);
if (Number.isNaN(travelXY)) {
Expand Down Expand Up @@ -1301,6 +1327,12 @@ class GCodeVirtualizer extends EventEmitter {
return this.modalChanges;
}

getFeedrateChanges() {
this.feedrateChanges[this.feedrateChanges.length - 1].count = this.feedrateCounter;
this.feedrateCounter = 0;
return this.feedrateChanges;
}

getCurrentModal() {
return this.modal;
}
Expand All @@ -1310,6 +1342,19 @@ class GCodeVirtualizer extends EventEmitter {
this.modalCounter = 0;
this.modalChanges.push({ change: change, count: 0 });
}

saveFeedrate(change) {
this.feedrateChanges[this.feedrateChanges.length - 1].count = this.feedrateCounter;
this.feedrateCounter = 0;
this.feedrateChanges.push({ change: change, count: 0 });
}

addToTotalTime(time) {
if (!Number(time)) {
return;
}
this.totalTime += time;
}
}


Expand Down
50 changes: 42 additions & 8 deletions src/app/workers/Visualize.worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,13 +374,18 @@ onmessage = function({ data }) {
const vm = new GCodeVirtualizer({ addLine, addArcCurve, addCurve, collate: true, accelerations, maxFeedrates });

if (!isEmpty(parsedData) && !isNewFile) {
const { data, info, modalChanges } = parsedData;
const { data, info, modalChanges, feedrateChanges } = parsedData;
fileInfo = info;

let modalIndex = 0; // track changes
let iterationsNeeded = modalChanges[modalIndex].count; // initialize
let modal = vm.getCurrentModal(); // get the default modal
let modalCounter = 0; // tracking how long until the modal change comes

let feedrateIndex = 0; // track changes
let iterationsNeededF = feedrateChanges[feedrateIndex].count; // initialize
let feedrateCounter = 0; // tracking how long until the feed change comes

for (let i = 0; i < data.length; i++) {
// update modal
if (modalCounter === iterationsNeeded) {
Expand All @@ -389,6 +394,13 @@ onmessage = function({ data }) {
iterationsNeeded = modalChanges[modalIndex].count; // update the new count
modalCounter = 0; // reset counter
}
// update feedrate
if (feedrateCounter === iterationsNeededF) {
feedrateIndex++;
vm.setFeedrate(feedrateChanges[feedrateIndex].change); // change the feed
iterationsNeededF = feedrateChanges[feedrateIndex].count; // update the new count
feedrateCounter = 0; // reset counter
}

const entry = data[i];
if (entry.lineData) {
Expand All @@ -404,14 +416,22 @@ onmessage = function({ data }) {
}
}
}
if (modal.motion === 'G1' || modal.motion === 'G0') {
if (shouldUseAddCurve) {
addCurve(modal, v1, v2);

if (modal.motion === 'G4') {
vm.addToTotalTime(entry.lineData.dwellTime);
} else {
const targetPosition = { x: v2.x, y: v2.y, z: v2.z };
if (modal.motion === 'G1' || modal.motion === 'G0') {
if (shouldUseAddCurve) {
addCurve(modal, v1, v2);
} else {
addLine(modal, v1, v2);
}
vm.calculateMachiningTime(targetPosition, v1);
} else {
addLine(modal, v1, v2);
addArcCurve(modal, v1, v2, v0);
vm.calculateMachiningTime(targetPosition, v1);
}
} else {
addArcCurve(modal, v1, v2, v0);
}
}

Expand All @@ -434,7 +454,19 @@ onmessage = function({ data }) {
onData(entry.parsedLine);

modalCounter++;
feedrateCounter++;
}

let newFileInfo = vm.generateFileStats();
fileInfo.estimatedTime = newFileInfo.estimatedTime;
// update estimated time
parsedDataToSend = {
data: parsedData.data,
estimates: parsedData.estimates,
info: fileInfo,
modalChanges,
feedrateChanges,
};
} else {
vm.on('data', (data) => {
let spindleValues = {};
Expand All @@ -461,12 +493,14 @@ onmessage = function({ data }) {

const data = vm.getData();
const modalChanges = vm.getModalChanges();
const feedrateChanges = vm.getFeedrateChanges();
fileInfo = vm.generateFileStats();
parsedDataToSend = {
data: data.data,
estimates: data.estimates,
info: fileInfo,
modalChanges
modalChanges,
feedrateChanges,
};
}

Expand Down

0 comments on commit f8ae07a

Please sign in to comment.