Skip to content

Commit

Permalink
use LIMS to calculate machining time
Browse files Browse the repository at this point in the history
  • Loading branch information
staniska committed Nov 10, 2024
1 parent 53f633c commit f417d3e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
25 changes: 11 additions & 14 deletions lib/interpretator.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ function parseDataClear(programName) {
View.sinumerikView.parseData.mcall[programName] = undefined;

View.sinumerikView.parseData.calcComp = false;
View.sinumerikView.parseData.spindleSpeed = {type: 'G97', value: 1};
View.sinumerikView.parseData.spindleSpeed = {type: 'G97', value: 1, limit: 20000};
View.sinumerikView.parseData.feed = {type: 'G94', value: 100};
if (View.sinumerikView.programmData[atom.workspace.getActiveTextEditor().getTitle().replace(/\./g, '_').toUpperCase()].machine.machineType === 'Lathe') {
View.sinumerikView.parseData.feed.type = 'G95'
Expand Down Expand Up @@ -538,10 +538,9 @@ function parseRows(programText, programName, variables, firstCall) {
}
}

if (operator.type === 'S_speed') {
View.sinumerikView.parseData.spindleSpeed.value = calcValue(operator.value, programName, row)
}
if (operator.type === 'S_speed') View.sinumerikView.parseData.spindleSpeed.value = calcValue(operator.value, programName, row)
if (operator.type === 'F_feed') View.sinumerikView.parseData.feed.value = calcValue(operator.value, programName, row)
if (operator.type === 'LIMS') View.sinumerikView.parseData.spindleSpeed.limit = calcValue(operator.value, programName, row)
if (operator.type === 'generalGroup15') {
if (operator.value === 'G96' || operator.value === 'G97') {
View.sinumerikView.parseData.spindleSpeed.type = operator.value
Expand Down Expand Up @@ -603,7 +602,7 @@ function parseRows(programText, programName, variables, firstCall) {
}

const calcValue = (value, programName, row) => {
return value[0] === '=' ? mathParse(value.substring(1), programName, row) : value
return value[0] === '=' ? mathParse(value.substring(1), programName, row) : parseFloat(value)
}

function checkRepeat(rowText, programName, programText, row) {
Expand Down Expand Up @@ -2776,15 +2775,6 @@ function generatePrimitives(rowText, programName, progRowNum, programText) {
}
//endregion

//region LIMS
regEx = /(?<!\w)LIMS(?!\w)/;
if (regEx.exec(programRow)) {
primitives[0].operators[0] = {};
primitives[0].operators[0].type = 'LIMS';
return primitives;
}
//endregion

//region SPCO[NF]
regEx = /(?<!\w)SPCO[NF](?!\w)/;
if (regEx.exec(programRow)) {
Expand Down Expand Up @@ -2840,6 +2830,13 @@ function generatePrimitives(rowText, programName, progRowNum, programText) {
}
//endregion

//region LIMS
regEx = /(?<!\w)LIMS(?!\w)/;
if (regEx.exec(splitRow[i])) {
primitives[0].operators[i] = {type: 'LIMS', value: splitRow[i].substring(4)};
break
}
//endregion

//region T-name
regEx = /(?<!\w)T(?=[=\d])/;
Expand Down
22 changes: 12 additions & 10 deletions lib/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ export const createTimeDiv = () => {

const updateMachineTime = (e) => {
const textField = e.target
// textField.value = '00:00:00'
const elements = View.sinumerikView.parseData.canvas.filter(el => el.X_start !== undefined)
const machiningTime = elements.filter(el => el.type === 'G1').reduce((t, el) => t + getElMachineTime(el), 0)
const rapidTime = elements.filter(el => el.type === 'G0').reduce((t, el) => t + getElMachineTime(el), 0)
// console.log(machiningTime)
textField.value = formatTime(machiningTime)
const rapidField = e.target.closest('div').querySelector('#rapidTimeDiv')
rapidField.textContent = formatTime(rapidTime)
Expand All @@ -45,20 +43,25 @@ const getElMachineTime = (el) => {
if (el.type === 'G0') return getLength(el) / 5000
if (el.feed.type === 'G94') return getLength(el) / el.feed.value
if (el.spindleSpeed.type === 'G97' || Math.abs(el.X - el.X_start) < 1) {
const spindleNums = el.spindleSpeed.value / 2 / el.X * 315

let spindleNums = el.spindleSpeed.type === 'G97' ? el.spindleSpeed.value : el.spindleSpeed.value / Math.abs(el.X + el.X_start) * 315
if (Number.isNaN(spindleNums)) spindleNums = 1000
if (spindleNums > el.spindleSpeed.limit) {
spindleNums = el.spindleSpeed.limit
}
return getLength(el) / (spindleNums * el.feed.value)
} else {
const divider = Math.round(Math.abs(el.X - el.X_start) + 1)
return (Array(divider).fill('')
.map((el_part, idx) => {
return {
...el,
X_start: el.X + (el.X - el.X_start) / divider * idx,
X: el.X + (el.X - el.X_start) / divider * (idx + 1),
Y_start: el.Y + (el.Y - el.Y_start) / divider * idx,
Y: el.Y + (el.Y - el.Y_start) / divider * (idx + 1),
Z_start: el.Z + (el.Z - el.Z_start) / divider * idx,
Z: el.Z + (el.Z - el.Z_start) / divider * (idx + 1),
X_start: el.X_start + (el.X - el.X_start) / divider * idx,
X: el.X_start + (el.X - el.X_start) / divider * (idx + 1),
Y_start: el.Y_start + (el.Y - el.Y_start) / divider * idx,
Y: el.Y_start + (el.Y - el.Y_start) / divider * (idx + 1),
Z_start: el.Z_start + (el.Z - el.Z_start) / divider * idx,
Z: el.Z_start + (el.Z - el.Z_start) / divider * (idx + 1),
}
}))
.reduce((time, el_part) => {
Expand All @@ -69,7 +72,6 @@ const getElMachineTime = (el) => {
}

const getLength = (el) => {
let length = 0
const axes_names = ['X', 'Y', 'Z']
return Math.sqrt(axes_names.reduce((l, ax) => l + (el[ax] - el[`${ax}_start`]) ** 2, 0))
}
Expand Down

0 comments on commit f417d3e

Please sign in to comment.