M.tool
The M.tool functions read and change tool data: the current and next tool, tool changer slots, tool names, Z offsets, diameters and diameter wear.
true for setters); on failure it's nil and the second value err describes the error.Current and next tool
Returns the tool number currently in the spindle.
Returns: integer tool number, or 0/nil if no tool.
Sets the current tool in the software state. Use it after a manual or automatic tool change.
Input: tool_number (integer). Returns: true, or nil, err.
Returns the next staged tool, selected with a T word.
Returns: integer, or 0/nil.
Sets which tool is loaded at the next M6.
Input: tool_number (integer). Returns: true, or nil, err.
Tool changer slots
Gets the tool changer slot (pocket) assigned to a tool.
Input: tool_number (integer). Returns: slot (integer), or nil, err.
Assigns or changes the tool changer slot for a tool.
Input: tool_number (integer), slot (integer). Returns: true, or nil, err.
Tool name
Gets a tool's name.
Input: tool_number (integer). Returns: string, or nil, err.
Sets or changes a tool's name.
Input: tool_number (integer), name (string). Returns: true, or nil, err.
Offsets, diameter and wear
Returns the tool length (Z) offset.
Input: tool_number (integer). Returns: number in mm, or nil, err.
Sets the tool length (Z) offset.
Input: tool_number (integer), z_offset (number, mm). Returns: true, or nil, err.
Gets the nominal cutter diameter.
Input: tool_number (integer). Returns: number in mm, or nil, err.
Gets the diameter wear value.
Input: tool_number (integer). Returns: number in mm, or nil, err.
Sets the diameter wear. The value can be negative.
Input: tool_number (integer), wear (number, mm). Returns: true, or nil, err.
Example
Names the current tool with its diameter and number, for example Ø6.00 T03.
-- Label current tool with its diameter
local tn = M.tool.get_current()
if tn and tn > 0 then
local d = M.tool.get_diameter(tn)
if d then M.tool.set_name(tn, string.format("Ø%.2f T%02d", d, tn)) end
end