; AUTOMATIC TOOL CHANGER NGC SUBROUTINE FILE - MAZAK-VQC1540 mill ; Author: Timothy Snowden / Solid Rock Development ; (inspired by Vismach toolchange.ngc by Andy Pugh) ; Notes: ; - All atc-related functions connected in this file ; - ALL MOVES PRECEDED BY G53 (move in machine coord's - NOT modal!) ; - M66 (wait for digital input) - result stored in #5399, timeout = -1 ; - Standard param's exposed by change_prolog/eval'd by change_epilog: ; # ; # ; # ; # ; DEFINE DIGITAL INPUTS: ; P3 = atc-arrive-request (move tool into ATC, but don't engage chain) ; P4 = atc-exit-request (PLC request to exit toolchanger magazine) ; P5 = atc-finished-request (PLC request to complete the tool change) ; P6 = skip-unload (PLC confirms that unload will be skipped) ; DEFINE DIGITAL OUTPUTS: ; P0 = tool-change (signals PLC that a tool change is in progress) ; P1 = atc-arrived (signals PLC that tool is in ATC 'wait' position) ; P2 = atc-exited (signals PLC that the tool/spindle exited the ATC) o sub ; DEFINE VARIABLES: # = #<_ini[ATC]X_ATC> ;X in line with the ATC # = #<_ini[ATC]Y_ATC_MAG> ;Y in the magazine, but not in the tool chain # = #<_ini[ATC]Y_ATC> ;Y position to engage the tool chain # = #<_ini[ATC]Y_SAFE>;Y safely outside the magazine # = #<_ini[ATC]Z_UP> ;Z all the way up - highest clearance / safety # = #<_ini[ATC]Z_ATC> ;Z at level of ATC tool chain) M5 ;ensure spindle is stopped M64 P0 ;notify PLC tool-change has begun - set 'tool-change' ON ;#5399 = 2 ;set #5399 to a bogus value to avoid accidents M70 ;save current modal state G28.1 ;save current position to #5161-5166 ; Update the tool number if a tool was in the spindle before startup ; O10 IF [#5000 GT 0 AND # EQ 0] ; M61 Q#5000 ; O10 ENDIF G53 G0 Z # ;move to up position G53 X # ;move in line to enter ATC M66 P3 L3 Q10 ;wait 5s for PLC atc-arrive-request to go HIGH O20 IF [#5399 LT 0] ;send abort msg if wait times out M65 P0 ;notify PLC tool-change is cancelled - set 'tool-change' OFF (abort, failed to open cover, ready empty pocket assigned to current tool, and/or orient spindle) O20 endif ;(abort, PAUSE HERE) ; G53 G0 Z # ;move Z down to atc position (o.w. triggers ESTOP) !!! CHECK COLLISIONS !!! ; G53 G0 Y # ;move into magazine ---while Z is at safe height--- M66 P6 L0 ;check if PLC is skipping unload M65 P0 (abort, DEBUG STOP) ; Only unload the tool if there is a tool in the spindle. O100 IF [# GT 0 AND #5399 EQ 0] ;test if current tool no > 0 & that PLC agrees G53 Z # ;drop to tool-change position G53 Y # ;move Y into tool chain M64 P1 ;notify PLC - set 'atc-arrived' ON M66 P4 L3 Q5 ;wait 5s for PLC atc-exit-request to go HIGH (i.e. lift after unclamp) M65 P1 ;turn 'atc-arrived' OFF O111 if [#5399 LT 0] ;send abort msg if wait times out M65 P0 ;notify PLC tool-change is cancelled - set 'tool-change' OFF (abort, failed to unclamp current tool) O111 endif G53 G0 Z # ;lift z to allow tool-chain to move M64 P2 ;notify PLC - set 'atc-exited' ON (MSG, 0100 IF1) ; Else, if no tool is in the spindle, simply load the new tool ;O100 ELSEIF [# EQ 0 AND #5399 EQ 1] ;test if current tool no = 0 & PLC agrees to skip unload ; ; G53 Y # ;move Y over tool chain ; M64 P1 ;notify PLC - set 'atc-arrived' ON ; (MSG, O100 IF2) O100 ELSE M65 P0 ;notify PLC tool-change is cancelled - set 'tool-change' OFF (MSG, O100 IF3) (abort, disagreement between PLC and atc.ngc on skipping unload) O100 ENDIF M65 P1 ;turn 'atc-arrived' off so it doesn't accidentally activate next step M66 P3 L3 Q5 ;wait 5s for PLC atc-arrive-request to go HIGH (pocket rdy, move down) O112 if [#5399 LT 0] ;send abort msg if wait times out M65 P0 ;notify PLC tool-change is cancelled - set 'tool-change' OFF M65 P2 ;clear 'atc-exited' pin (OFF) (abort, failed to move new tool into position) O112 endif G53 G0 Z ;drop Z to pick up new tool M64 P1 ;notify PLC - set 'atc-arrived' ON M66 P4 L3 Q5 ;wait 5s for PLC atc-exit-request to go HIGH (clamped) M65 P1 ;turn 'atc-arrived' off O104 if [#5399 LT 0] ;send abort msg if wait times out M65 P0 ;notify PLC tool-change is cancelled - set 'tool-change' OFF (abort, failed to clamp new tool) O104 endif G53 G0 Y # ;move tool/spindle safely out of magazine M64 P2 ;notify PLC - atc-exited (tool safely out of mag) #5000 = # ;update persistent tool number M66 P5 L3 Q5 ;wait 5s for PLC atc-finished-request to go HI (done!) M65 P2 ;turn 'atc-exited' off O105 if [#5399LT 0] ;send abort msg if wait times out M65 P0 ;notify PLC tool-change is cancelled - set 'tool-change' OFF (abort, failed to close magazine cover and/or finish tool-change) O105 endif G53 G0 X #5161 Y #5162 ;move back to pre-toolchange X/Y position G53 G1 Z #5163 ;switch back to feed mode & move down to prev Z G43 H0 ;set tool offsets to current tool in spindle ... or to 0 if no tool M72 ;restore current state M65 P0 ;notify PLC tool-change is over - set 'tool-change' OFF o endsub [1]