Pages

Sunday, 10 May 2020

Using Z Probe With LinuxCNC



Z axis probing is a nice addition to a CNC allowing for accurate locating of the top surface of a workpiece. I made a touchplate from a 5mm disc of aluminium, a crocodile clip, and a length of 2 pin cable. 

The operating principle is simple:
  • Move the CNC spindle in the XY plane and position over the workpiece. Lower the Z axis so the bit is approximately 10mm above the workpiece.
  • Place the probe plate on the work piece surface under the bit. This forms one contact of a switch.
  • Attach the second wire to the spindle bit using the crocodile clip. This forms the second contact of the switch.
  • G-code G38.2 probe command is issued to lower the bit until it touches the probe plate and completes the circuit. The Z axis zero is calculated as the contact position minus the thickness of the probe plate. 

To configure LinuxCNC for Z probing there are a number of elements to configure. First is the physical wiring of the probe. My CNC uses a Mesa 7i96 controller which has 11 opto-isolated inputs. The probe is set up as a sourcing input on the Mesa card with the input common pin connected to +5V. The connection to the spindle bit is connected to ground as the spindle chassis is typically grounded.



LinuxCNC Z Probe Wiring
Mesa Input Common (COM+) +5V
Spindle bit GND
Probe plate Mesa Input 6


LinuxCNC HAL uses pin motion.probe−input during probing. G-code G38.n probe commands uses the value on this HAL pin to determine when the probe has made contact with the touch plate. Edit the io.hal file and add a net to connect Mesa card input 6 to the HAL motion.probe-input pin.

  net probe-input motion.probe-input <= hm2_7i96.0.gpio.006.in



The PyVCP (Python Virtual Control Panel) allows the LinuxCNC AXIS interface to be customised. In the LinuxCNC config folder create a file called ztouch.xml and add the following definition for a 'Touch Off Z' button. 

  <?xml version='1.0' encoding='UTF-8'?>
  <pyvcp>
    <button>
      <relief>RAISED</relief>
      <bd>3</bd>
      <halpin>"ztouch"</halpin>
      <text>"Touch Off Z"</text>
      <font>("Helvetica",16)</font>
    </button>
  </pyvcp>


In the postgui.hal file add a net connecting the newly created button (pyvcp.ztouch) to a MDI command (halui.mdi-command-00). This command will later be used to call the G-code probe subroutine file.

  net ztouch halui.mdi-command-00 <= pyvcp.ztouch


I place my subroutines in a subfolder of my LinuxCNC config folder, linuxcnc/configs/subroutines/. In this folder create a file called z_touch.ngc and add the following G-code subroutine to perform Z axis probing.

  O <z_touch> sub
  G10 L20 P0 Z0 (set current Z = 0)
  G91 (switch to relative coordinates)
  G38.2 Z-10 F25 (probe down using a fast feedrate)
  G92 Z5.0 (set Z = plate thickness)
  G0 Z.1 F10 (move up by 0.1mm)
  G38.2 Z-1 F1 (2nd pass: probe down using a slow feedrate to get better accuracy)
  G92 Z5.0 (set Z = plate thickness)
  G90 (switch to absolute coordinates)
  G0 Z10 F25 (move to 10mm above work piece)
  O <z_touch> endsub


Now to link all these parts together in the config ini file by adding a DISPLAY reference to the new button definition XML file, set SUBROUTINE_PATH to the location of the G-code subroutine file, define the POSTGUI_HALFILE to load once the LinuxCNC AXIS GUI has started, and finally the definition for the MDI_COMMAND which is used to call the probing subroutine.

  [DISPLAY]
  PYVCP = ztouch.xml

  [RS274NGC]
  SUBROUTINE_PATH = /home/seand/linuxcnc/configs/subroutines/

  [HAL]
  HALFILE = io.hal
  POSTGUI_HALFILE = postgui.hal
  HALUI = halui

  [HALUI]
  # Z axis touch plate subroutine
  MDI_COMMAND = O <z_touch> CALL


No comments:

Post a Comment