M6 Tool Change Remapping with Tool Length Measurement

01 Feb 2021 04:08 #197276 by nf1z
This is a follow-on to my recent topic:
Taig CNC Mill Upgrades: Probe, Spindle, Pendant, etc..

It looks like I probably should have put that one in the "Show your Stuff" category. My apologies.

In that topic, I mentioned remapping M6 to do tool length measuring (TLM) as part of each tool change, which the standard LinuxCNC manual tool changer component does not allow. That component assumes that the offsets for all tools have been measured and entered into the tool table before the program is run, and that each tool can be reloaded with the exact same tool length whenever an M6 is executed. This is the way most industrial CNC machines work. It requires either a turret-like tool changer (as on lathes), or special tool holders that ensure the tool offsets are preserved when removed and re-inserted into the mill spindle. The standard Taig mill ER16 spindle does not do this. It is (or it was) possible to buy add-on quick-change tool holder systems for the Taig, but these are expensive. For a while I used re-sharpened carbide end mills and drills that had been used in PCB manufacture; these are all made with a 1/8" shank and have a push-on plastic sleeve that (I assume) is used to maintain the tool's protrusion. With care, the plastic sleeve can be pushed hard against the ER16 collet face within a few thou. Sets of assorted size drills and endmills could be obtained very cheaply on eBay, but they seem to be no longer available. This 'system' worked pretty well, until I needed to use a drill or end mill that did not have a 1/8 shank.

When I was using this approach, I had not bothered to make a tool probe. I just touched off each tool to be used to the top of the vise before running the job, using feeler gauges or a gauge block. The work coordinate system (WCS) for each different job is then set by using any tool to touch off the the work's reference surface. Tool offsets can be preserved over many jobs - provided you don't move the vise's coordinates. Adding a tool probe/sensor in a fixed location was done primarily to save time and add accuracy to touching off tools, but it also enables the tool offsets to be made independent of the work and work holding arrangement. This I think helps to avoid stupid mistakes in setup.

There is one other important consideration, the repeatability of the machine coordinate system (MCS) through power cycles. The WCS is defined relative to the MCS, and, if the tool probe is at a fixed position on the machine, the tool offsets are relative to the MCS also. If you cannot set the MCS origin to the same point, the WCS and tool offsets become invalid. Modern industrial machines use battery powered absolute encoders, so the machine simply knows where it is, even if the axis is moved with power off. Older machines use home switches on each axis to indicate the rough area of the zero position, then the encoder index is used to restore the MCS origin very accurately. Many low-end and low accuracy machines (e.g., 3D printers, woodworking routers or cutting machines) do have home switches, but without encoders the repeatability is not good enough for tool setting purposes on a metal cutting mill. I have not bothered with home switches on my Taig.

A side note. It is of course possible to use a CNC machine like a manual machine: load the tool; touch it to the work and set the dials to zero, compensating for tool diameter, etc.. Cut, then repeat for next tool/work feature. However, much of the advantage of a CNC system will be lost.

The tool probe made it much easier to use random tools using the built-in G38.2 code, but the LinuxCNC manual tool changer does not support this, and LinuxCNC cannot perform MDI operations (such as a G38.2) when paused in auto mode. A G-code program can be split so that only one tool is used per program, but the better solution is to remap the M6 code so that it measures the tool length. The process and techniques for remapping M codes in LinuxCNC is pretty well documented, so won't be further described. There are a couple of ways to do it. I chose to use G code rather than Python, being totally unversed in Python at the time. If I were to do it again, I would use Python.

I broke up the remapping code into three G-code O-word subroutines. The lowest level one is called probe, which performs the basic probing moves. The G38.2 probe command is the heart of it, with some preliminary motion to improve safety, and a little accuracy analysis. Some global parameters are set; these are used by the higher-level functions, and can be examined from the MDI command line for debugging purposes. Some configuration items are obtained from the .INI file. I have mapped the probing operation to the M401 M-code (no argument words) to allow it to be called from G code programs, if necessary. The comments in the file should make clear what is going on.

File Attachment:

File Name: probe_2021...31-2.ngc
File Size:5 KB

The next higher subroutine is called probe-calib-taig. This is mapped to the M400 M code, and is intended to setup and perform tool measuring operations. The M400 can have several possible argument words. Without adding too much verbiage, the P word controls the major operation type: P2 performs a probe calibration (which is explained later), P0 does a probe. P1 can be used to override .INI file configuration settings.

File Attachment:

File Name: probe-cali...31-2.ngc
File Size:7 KB

The code requires that the probe be calibrated before it can be used. This condition is stored in a global variable, so automatically gets set to "uncalibrated" when LinuxCNC is started. The purpose of calibration is to set the Z coordinate of the probe trigger point within the current MCS, as a reference for tool length measurements. Basically, it does a probe and adjusts the probe trigger point Z to get the answer you told it. That answer can be anything you like, and could be different each session, but for sanity-preservation, it makes sense to do something constant and meaningful. I decided that the tool lengths in the tool table should be the distance from the spindle nose to the tool tip (per industrial practice). This means that the probe Z activation point should be the Z axis position when the spindle nose, with zero-length tool, triggers the probe. On my machine, the spindle nose cannot reach the probe button, so I perch a 1" gauge block on the button, remove the collet nut and collet from the spindle, and issue the command:
M400 P2 R1.0
If there is a known-good tool offset in the tool table (from previously or manually entered), that too, can be used as a length reference:
M400 P2 Qn
where n is the tool number, defaulting to the current tool. This is the normal calibration mode after the first time, and I keep a special calibration tool with a locating shoulder for this purpose - but any tool would do. In this case, the probe trigger point Z coordinate will be adjusted so that probing that tool would not change the tool table offset. Note that calibrating the probe does not restore the MCS, but it adjusts for it in respect of tool lengths. It also does not affect any WCSs, which would similarly be affected by an MCS change.

Calibration is set up to require that the operator activate the probe button to confirm the action, which also tests the probe The probe-in signal is connected to a digital input in a HAL file so that the M66 command can be used to test it. This wouldn't be necessary in Python. The digital input could also be a separate physical button.

The actual remapping of the M6 tool change code is done in the tool-change-taig subroutine:

File Attachment:

File Name: tool-chang...31-2.ngc
File Size:8 KB

This was derived loosely from a 2014 forum post by orangecat. There are several changes in my approach that are listed at the beginning of the file.

The subroutine first executes the existing M6 function; in the case of the LinuxCNC manual tool changer, this basically prompts the operator to change the tool. At this point the operator can trigger the probe manually to skip probing. This is intended to save some time if the new tool is known to have been loaded with the same offset as in the tool table (e.g., a tool with a location sleeve). If the probe is not triggered within 5 seconds, a tool probe is executed (M400 P0) and the tool table updated. The machine then moves back to the XY position before the M6, but at the tool change height.

Finally, to make these new/changed M codes active, the .INI file must have additions (for example):

	# M6 remap for probe
	# change/add/use SUBROUTINE_PATH to point to the location where these tool-change subroutines are located:
	# abs path is for "tested" functions, macros is gmoccapy stuff
SUBROUTINE_PATH = subroutines: ~/linuxcnc/subroutine:macros
REMAP=M6 modalgroup=6 ngc=tool-change-taig
	#<feature mask> enable #<_ini[section]name> read only variables: 4
	#<feature mask> enable #<_hal[Hal item]> read only variables: 8
ON_ABORT_COMMAND=O <on_abort> call
	# Tool probe setup and calibration
	# M401 raw probe - use with care
REMAP=M401 modalgroup=10 ngc=probe
	# Normal probe with P = 0; other words set config or calibrate
	# P = mode, IJK are XYZ probe coords, Q is current tool, DE are feeds, R is calibration tool length
REMAP=M400 modalgroup=10 argspec=Pijkqrde ngc=probe-calib-taig

I believe the code here to be reasonably stable. Please comment with any errors or suggestions for improvement.

The following user(s) said Thank You: tommylight, CADdy, ikkuh, mark0815, Aciera

Please Log in or Create an account to join the conversation.

Time to create page: 0.090 seconds
Powered by Kunena Forum