(author: Chris P)
(version: 0.0)
(date: 12/26/24)

(Probe Spindle Nose in Z Minus direction over tool setter and set Spindle Zero Distance)
(Start probe position is over toolsetter platter within max z distance)
(ensure all settings have been set properly according to help diagrams)

o<probe_spindle_nose> sub

  (uses NGCGUI style arg spec)
  (number after "=" in comment is default value)

  #<probe_fast_fr> = #3004        (=10.0)
  #<probe_slow_fr> = #3005        (=0)
  #<probe_traverse_fr> = #3006    (=50)
  #<max_z_distance> = #3007       (=12.5)
  #<retract_distance> = #3009     (=0.1000)

  (Cancel G92 offsets)
  G92.1

  o100 if [2 EQ 2]
    G49
  o100 endif

  #<offset_z> = #5422

  (Initial Fast Z- Probe)
  G91
  F[#<probe_fast_fr>]
  G38.2 Z-[#<max_z_distance>]
  #<z_minus_probed> = #5063

  (Probe Error check, #5070 will be 0 if failed)
  o110 if [#5070 EQ 0]
      (back to start point and feed)
      G90
      G1 F[#<probe_traverse_fr>] Z#<z>
      F[#<probe_fast_fr>]
      (return from sub)
      o<probe_spindle_nose> return
  o110 endif

  (Move up retract_distance height for slow probe)
  G90
  G1 F[#<probe_traverse_fr>] Z[#<z_minus_probed> + #<retract_distance>]

  (Slow Probe Rule, if Slow Probe FR is set to 0, Slow Probe is Bypassed)
  o120 if [#<probe_slow_fr> GT 0]
      (Initiate Slow Z- Probe)
      G91
      F[#<probe_slow_fr>]
      G38.2 Z-[#<retract_distance> * 2]
      #<z_minus_probed> = #5063
      G90
      G1 F[#<probe_traverse_fr>] Z[#<z_minus_probed> + #<retract_distance>]
  o120 endif

  (defines the edge as z_probed_position for DRO reporting)
  #<z_minus_probed_position> = #<z_minus_probed>

  (output to gui DRO "Z PROBED POSITION")
  #1009 = #<z_minus_probed_position>
  #3010 = [ABS[#<z_minus_probed_position> - #<offset_z>]]
  #<max_z_travel_default> = [#3010 * 1.001]
  #3007 = #<max_z_travel_default>

  (DEBUG, EVAL[vcp.getWidget{"z_minus_probed_position"}.setValue{#1009}])
  (DEBUG, EVAL[vcp.getWidget{"spindle_zero_height_3010"}.setValue{#3010}])
  (DEBUG, EVAL[vcp.getWidget{"z_max_travel_3007"}.setValue{#3007}])

  G53 G0 Z0.0

o<probe_spindle_nose> endsub

M2 (end program)
