grbl/grbl — pull request #491 by tmpvar (2014-09-15 17:11:22+00:00)
Title: G38.2+

This is mostly a copy of #490's description which I've included at the bottom

It seems like @chamnit is having some reservations about landing this, so I guess it's worth explaining my use case.

I would _really_ like to have a switch on my machine somewhere near `0,0,-z` that I can use in combination with `G43` ([G43 Tool Length Offset](http://linuxcnc.org/docs/html/gcode/gcode.html#sec:G43)) to automatically setup tools (their depth for now) after manual tool changes.

My main concern is with `G38.2` and that once the switch is pressed it continues moving into the switch during the `EXEC_FEED_HOLD`/deceleration phase and eventually reports it's resting position. This makes sense, you certainly don't want to blow away the state of the machine doing a hard stop and losing steps. This is probably not as big a concern for machines with fast acceleration settings.

However, to be robust against various machine configurations, backing off of the switch seems like a reasonable next operation to ensure the tool is exactly at the height of the button. This is roughly analogous to how homing is performed currently (i.e. back off, re-engage, etc.)

Given access to either the probe pin state or `G38.{4,5}` a cycle much like the homing cycle could be created in user land tools (i.e. python/node/java) to help eliminate any variation between tool changes. I've chosen the standard way here as to avoid adding more reporting noise to the output, and with the hope that it is useful for people using other types of probes as well

_copied from #490_

This is accomplished by adding a sys.probe_away flag that is used to flip the direction of the switch depending on which direction we are probing in.

truth table

towards (G38.2, G38.3) away (G38.4, G38.5)
before sys.probe_away = 0 sys.probe_away = 1
sys.probe_state = 0 sys.probe_state = 1

after sys.probe_away = 0 sys.probe_away = 1
sys.probe_state = 1 sys.probe_state = 0
This assumes that the switch is engaged when "probing away" begins, which appears to be sound given the wording in linuxcnc's description

G38.2 - probe toward workpiece, stop on contact, signal error if failure
G38.3 - probe toward workpiece, stop on contact
G38.4 - probe away from workpiece, stop on loss of contact, signal error if failure
G38.5 - probe away from workpiece, stop on loss of contact
grbl with this patch builds at 27758 bytes vs master at 27654 bytes