diff --git a/macro/machine/M4000.g b/macro/machine/M4000.g index 71a8255..3abbd9e 100644 --- a/macro/machine/M4000.g +++ b/macro/machine/M4000.g @@ -15,6 +15,9 @@ if { !inputs[state.thisInput].active } if { !exists(param.P) || !exists(param.R) || !exists(param.S) } abort { "Must provide tool number (P...), radius (R...) and description (S...) to register tool!" } +if { #param.S < 1 } + abort { "Tool description must be at least 1 character long!" } + ; Validate tool index if { param.P >= limits.tools || param.P < 0 } abort { "Tool index must be between 0 and " ^ limits.tools-1 ^ "!" } @@ -23,18 +26,25 @@ if { param.P >= limits.tools || param.P < 0 } ; This allows us to re-run a file that defines the tool that is currently ; loaded, without unloading the tool. ; This has to be split over multiple lines due to length of the condition. -if { exists(global.mosTT[param.P]) && global.mosTT[param.P] != null && exists(tools[param.P]) && tools[param.P] != null } - var toolSame = { global.mosTT[param.P][0] == param.R && tools[param.P].spindle == ((exists(param.I)) ? param.I : global.mosSID) } +; Make sure to check that the tool table has enough entries. + +; Initial tool similarity check - make sure the tool is defined in both the internal +; RRF tool table and our own mosTT table. +var toolSame = { global.mosTT[param.P] != null && #tools > param.P && tools[param.P] != null } - set var.toolSame = { var.toolSame && tools[param.P].name == param.S } +; Check that tool radius and spindle match +set var.toolSame = { var.toolSame && global.mosTT[param.P][0] == param.R && tools[param.P].spindle == ((exists(param.I)) ? param.I : global.mosSID) } - if { exists(param.X) } - set var.toolSame = { var.toolSame && global.mosTT[param.P][1][0] == param.X } - if { exists(param.Y) } - set var.toolSame = { var.toolSame && global.mosTT[param.P][1][1] == param.Y } +; Check that tool description matches +set var.toolSame = { var.toolSame && tools[param.P].name == param.S } - if { var.toolSame } - M99 +; Check that deflection values match +set var.toolSame = { var.toolSame && exists(param.X) && global.mosTT[param.P][1][0] == param.X } +set var.toolSame = { var.toolSame && exists(param.Y) && global.mosTT[param.P][1][1] == param.Y } + +; If the tool already matches, return. +if { var.toolSame } + M99 ; Define RRF tool against spindle. ; Allow spindle ID to be overridden where necessary using I parameter. diff --git a/post-processors/freecad/millennium_os_post.py b/post-processors/freecad/millennium_os_post.py index a6b93be..ef1a7f3 100644 --- a/post-processors/freecad/millennium_os_post.py +++ b/post-processors/freecad/millennium_os_post.py @@ -639,6 +639,9 @@ def addtool(self, index, name, params): if index in self.tools and name != self.tools[index]['name']: raise ValueError("Duplicate tool index {} with different descriptions!".format(index)) + if len(name) < 1: + raise ValueError("Tool name must not be empty!") + self.tools[index] = {"name": name, "params": params} # Return tool info diff --git a/post-processors/fusion-360/millennium-os.cps b/post-processors/fusion-360/millennium-os.cps index a8951f0..f49c1b2 100644 --- a/post-processors/fusion-360/millennium-os.cps +++ b/post-processors/fusion-360/millennium-os.cps @@ -465,6 +465,9 @@ function onOpen() { writeComment("Pass tool details to firmware"); for(var i = 0; i < nTools; i++) { var tool = tools.getTool(i); + if(tool.description.length < 1) { + error("Tool description must not be empty!"); + } writeBlock('{cmd} P{index} R{radius} S"{desc}"'.supplant({ cmd: mCodes.format(M.ADD_TOOL), index: intFmt.format(tool.number),