Skip to content

Commit

Permalink
Make M4000 tool similarity checks more robust (#184)
Browse files Browse the repository at this point in the history
* Clean up M4000 tool similarity check

Also fixes an error when tools are passed with an empty description
string.

Signed-off-by: Ben Agricola <[email protected]>

* Do not allow empty tool name / description in post-processors

Signed-off-by: Ben Agricola <[email protected]>

---------

Signed-off-by: Ben Agricola <[email protected]>
  • Loading branch information
benagricola authored Dec 20, 2024
1 parent 5d232d4 commit 39b69ec
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
28 changes: 19 additions & 9 deletions macro/machine/M4000.g
Original file line number Diff line number Diff line change
Expand Up @@ -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 ^ "!" }
Expand All @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions post-processors/freecad/millennium_os_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,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
Expand Down
3 changes: 3 additions & 0 deletions post-processors/fusion-360/millennium-os.cps
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,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),
Expand Down

0 comments on commit 39b69ec

Please sign in to comment.