; ; RosettaCNC (c) 2016-2020 ; ; Name : tool_change.ngc ; Sub UID : 6 ; Version : 2 ; Description : Tool change macro ; Application : Standard CNC cycles ; Note : This macro is called by CNC with M06 or manually with G65 P"tool_change" for optional actions. ; : Check the #6000 parameter description for tool change supported types. ; ; DISCLAIMER : This macro is provided 'AS IS', without WARRANTY of any kind, express or implied. ; : The macro is provided as an example only. ; : Use this macro at your own risk. ; ; TAKE CARE : Don't use the CNC #5132..5135 because they are valid ONLY when the macro is called with a M06. ; ; Conventions of input parameters ; ; Xx compulsory parameter ; [Xx] optional parameter ; (Xx|Yy|Zz)? one of compulsory paramaters ; [Xx|Yy|Zz]* zero or more optionals parameters ; [Xx|Yy|Zz]+ at least one or more optionals parameters ; M! compulsory parameter don't take care of passed value ; [M!] optional parameter don't take care of passed value ; M[1|2]? compulsory parameter with one of listed values (e.g. M1 or M2) ; [M[1|2]?] optional parameter with one of listed values (e.g. None or M1 or M2) ; ; Format ; ; M06 ; ; G65 P"tool_change" Aa Bb Cc Ii [Jj] [K!] ; ; Arguments with M6 call ; ; Aa #1 tool id of the tool to be loaded ; Bb #2 slot of the tool to be loaded ; Cc #3 tool id of the tool in use ; Ii #4 slot of the tool in use ; ; Extra arguments with G65 call ; ; Jj #5 optional action: ; #0 = the option is disabled (is the normal condition when the macro is called by a M06) ; 0 = do not change behavior of tool-setter after a pick in M06 or direct macro call ; 1 = do not execute tool-setter after a pick ; 2 = force execute tool-setter after pick ; 3 = execute only tool-setter of loaded tool ; 4 = execute only magazine open ; 5 = execute only magazine close ; 6 = return magazine state in # ; 7 = manually cone unload/load ; Kk #6 optional magazine argument: ; #0 = the option is disabled (is the normal condition when the macro is called by a M06) ; any = don't close magazine, is not the last operation (PICK/PLACE/TOOL-SETTER) to do yet ; ; Protected Parameters ; ; Param Description ; ===== =========== ; #6000 TOOL_CHANGE [GEN] : Type: ; 0 = Dummy tool change: ; This mode only notice to the PLC about the loaded tool ID. ; No other actions or movments will be done. ; 1 = Manual Tool Change (MTC) with tool length probing: ; a] Moves to tool-setter position and measures the loaded tool length. ; b] Moves to tool change position and show info about tool to manually change. ; c] Waits for the manual tool change by the operator which confirm that change is done. ; d] Moves to tool-setter position to measures the length of the new tool. ; e] Calcs the difference and uses this value as tool length compensation. ; 2 = Manual Tool Change (MTC) with tool length from Tools Library info: ; a] Moves to tool change position and show info about tool to manually change. ; b] Waits for the manual tool change by the operator which confirm that change is done. ; c] If enabled applies the tool length compensation from Tools Libary info. ; 10 = Automatic Tool Change (ATC) ; This mode manages a rack of slots using place/side & pick/top approach. ; If there is a loaded tool it will be placed. ; If there is a requested tool it will be picked. ; If the tool length measurement/compensation are enabled they are automaticallly performed. ; 11 = Automatic Tool Change (ATC) ; This mode manages a rack of slots using place/top & pick/top approach. ; If there is a loaded tool it will be placed. ; If there is a requested tool it will be picked. ; If the tool length measurement/compensation are enabled they are automaticallly performed. ; #6001 TOOL_CHANGE [GEN] : Features: ; 0 = Back to work position is OFF. ; 1 = Back to work position is ON. ; #6002 TOOL_CHANGE [MTC] : Change position X (MCS) ; #6003 TOOL_CHANGE [MTC] : Change position Y (MCS) ; #6004 TOOL_CHANGE [MTC] : Change position Z (MCS) ; #6005 TOOL_CHANGE [TLS] : Sensor safe position Z (MCS) ; #6006 TOOL_CHANGE [TLS] : Sensor top/center position X (MCS) ; #6007 TOOL_CHANGE [TLS] : Sensor top/center position Y (MCS) ; #6008 TOOL_CHANGE [TLS] : Sensor top/center position Z (MCS) ; #6009 TOOL_CHANGE [GEN] : Feed during tool change procedure ; #6010 TOOL_CHANGE [TLS] : Z approaching sensor position (MCS, reached with feed #6011) ; #6011 TOOL_CHANGE [TLS] : Z feed to sensor approaching (FAST) ; #6012 TOOL_CHANGE [TLS] : Z feed to 1st probe input capture (SLOW) ; #6013 TOOL_CHANGE [TLS] : Z feed to 2nd probe input capture (VERY SLOW) ; #6014 TOOL_CHANGE [TLS] : Z up movement after 1st touch capture (REL) ; #6015 TOOL_CHANGE [TLS] : Minimum tool lenght accepted ; #6016 TOOL_CHANGE [TLS] : Enable tool length compensation (only for tool change type 1) ; #6017 TOOL_CHANGE [TLS] : Probe cleaning output ; #6018 TOOL_CHANGE [TLS] : Probe cleaning time ; #6019 TOOL_CHANGE [___] : !!! RESERVED FOR FUTURE USE !!! ; #6020 TOOL_CHANGE [ATC] : Magazine type: ; 0 = none magazine ; 1 = magazine with 2 control outputs (open and close with individual pulse output) ; #6021 TOOL_CHANGE [ATC] : Magazine input open ; #6022 TOOL_CHANGE [ATC] : Magazine input closed ; #6023 TOOL_CHANGE [ATC] : Magazine input timeout ; #6024 TOOL_CHANGE [ATC] : Magazine output time ; #6025 TOOL_CHANGE [ATC] : Magazine output open ; #6026 TOOL_CHANGE [ATC] : Magazine output close ; #6027..#6035 TOOL_CHANGE [___] : !!! RESERVED FOR FUTURE USE !!! ; #6036 TOOL_CHANGE [ATC] : Fast unload tool holder distance ; #6037 TOOL_CHANGE [ATC] : Slow unload tool holder distance ; #6038 TOOL_CHANGE [ATC] : Slow unload tool holder feed ; #6039 TOOL_CHANGE [ATC] : Fast load tool holder distance ; #6040 TOOL_CHANGE [ATC] : Medium load tool holder distance ; #6041 TOOL_CHANGE [ATC] : Medium load tool holder feed ; #6042 TOOL_CHANGE [ATC] : Final load tool holder feed ; #6043 TOOL_CHANGE [ATC] : Cone load unload time (used only if "Cone load unload input" is zero) ; #6044 TOOL_CHANGE [ATC] : Cone load unload input (used only for a NO button and detect the release. You must have a macro that start procedure) ; #6045 TOOL_CHANGE [ATC] : Cone cleaning blow output ; #6046 TOOL_CHANGE [ATC] : Bearing cleaning blow output ; #6047 TOOL_CHANGE [ATC] : Cone grip output ; #6048 TOOL_CHANGE [ATC] : Cone grip output time ; #6049 TOOL_CHANGE [ATC] : Slots positions parameters address ; If undefined (#0) or set to 0 the default address is 6061 for maximum 13 slots ; #6050 TOOL_CHANGE [ATC] : Safe Z ; #6051 TOOL_CHANGE [ATC] : Unlock input ; #6052 TOOL_CHANGE [ATC] : Unlock output ; #6053 TOOL_CHANGE [ATC] : Unlock timeout ; #6054 TOOL_CHANGE [ATC] : Clamp movement ; #6055 TOOL_CHANGE [ATC] : Pick distance Z ; #6056 TOOL_CHANGE [ATC] : Enable tool-setter ; #6057 TOOL_CHANGE [ATC] : Spindle s1 (tool-holder attached correctly) ; #6058 TOOL_CHANGE [ATC] : Spindle s2 (collet open) ; #6059 TOOL_CHANGE [ATC] : Slot axis orientation (0 = along X | 1 = along Y) ; #6060 TOOL_CHANGE [ATC] : Slots number ; #6061..#6099 TOOL_CHANGE [ATC] : Slots positions parameters (default, with #6049 = #0 or 0, for 1 to 13 slots) (MCS) ; O6 ; === DISCLAIMER === ; ; This macro is provided 'AS IS', without WARRANTY of any kind, express or implied. ; The macro is provided as an example only. ; Use this macro at your own risk. ; ; NOTE: You can comment line 157 or delete this ADVICE but anyway you will accept the macro DISCLAIMER of the original code. ; IF [EXISTS[#] EQ 0] THEN10 #=1 M109 P"DISCLAIMER

This macro is provided 'AS IS',
without WARRANTY of any kind, express or implied.

The macro is provided as an example only.

Use this macro at your own risk." Q2 END10 ; store loaded/requested tool/slot ID #=#1 #=#2 #=#3 #=#4 ; recover macro optional action when macro is called with G65 IF [[#5 EQ #0] OR [#5 EQ 0]] THEN10 #=0 ELSE10 #=#5 END10 ; recover macro optional magazine argument available when macro called with G65 IF [EXISTS[#<_args.K>]] THEN10 #=1 ELSE10 #=0 END10 ; initialize ATC parameters CALL P"TC_INIT" ; store actual PLC states in local variables #<_saved.5001>=#5001 ; current TCP position X #<_saved.5002>=#5002 ; current TCP position Y #<_saved.5003>=#5003 ; current TCP position Z #<_saved.5004>=#5004 ; current position A #<_saved.5005>=#5005 ; current position B #<_saved.5006>=#5006 ; current position C #<_saved.5101>=#5101 ; active G-codes - group 01: G00, G01, ... #<_saved.5130>=#5130 ; active feed rate (F) #<_saved.5151>=#5151 ; active M-codes: M3, M4, M5 #<_saved.5153>=#5153 ; active M-codes: M7, M9 #<_saved.5154>=#5154 ; active M-codes: M8, M9 #<_saved.5103>=#5103 ; active G-codes - group 03: G90, G91 ; store actual PLC states in global variables #=#5136 ; active feed override mode (P argument of M50) ; set absolute coordinate G90 ; check if last G-codes group 01 used instruction was a G00/G01 otherwise, to prevent ; an error when setting G#<_saved.5101>, set it to G80 (cancel motion mode) IF [[#<_saved.5101> NE 0] AND [#<_saved.5101> NE 1]] THEN #<_saved.5101>=80 ; check if required only a tool-setter procedure by ATCM macro IF [# EQ 3] THEN10 CALL P"TC_TOUCH_PROBE_EXTERNAL_REQUEST" ; enable tool length compensation if enabled IF [# EQ 1] THEN G43 H# GOTO10 ELIF [# EQ 4] THEN10 CALL P"TC_MAGAZINE_OPEN" GOTO10 ELIF [# EQ 5] THEN10 #=0 CALL P"TC_MAGAZINE_CLOSE" GOTO10 ELIF [# EQ 6] THEN10 CALL P"TC_MAGAZINE_UPDATE_STATE" GOTO10 ELIF [# EQ 7] THEN10 CALL P"TC_TOGGLE_CONE_LOAD_UNLOAD" GOTO10 END10 ; check if tool change type = 0 then execute sub MANUAL_TOOL_CHANGE_0 IF [# EQ 0] THEN10 CALL P"MANUAL_TOOL_CHANGE_0" GOTO10 END10 ; avoid any activity if tool change type is 10 or 11 and requested tool is same of loaded tool IF [[# EQ 10] OR [# EQ 11]] THEN10 IF [[# EQ 0] AND [# EQ 0]] THEN M109 P"tool change require a PICK or PLACE or PLACE/PICK action" Q-1 IF [[# EQ #]] THEN11 ; enable tool length compensation if enabled IF [# EQ 1] THEN G43 H# GOTO10 END11 END10 ; notice start change procedure to PLC M107 ; show main procedure message for 1s M109 P"Tool change procedure" Q4 G04 P1 ; set position of axes type "rotary axes for head" IF [[#] EQ #] THEN10 G49 G53 G01 A0 F# END10 IF [[#] EQ #] THEN10 G49 G53 G01 B0 F# END10 IF [[#] EQ #] THEN10 G49 G53 G01 C0 F# END10 ; check if Tool change type = 1 the execute sub MANUAL_TOOL_CHANGE_1 IF [# EQ 1] THEN CALL P"MANUAL_TOOL_CHANGE_1" ; check if Tool change type = 2 the execute sub MANUAL_TOOL_CHANGE_2 IF [# EQ 2] THEN CALL P"MANUAL_TOOL_CHANGE_2" ; check if Tool change type = 10 the execute sub AUTOMATIC_TOOL_CHANGE_10 IF [# EQ 10] THEN CALL P"AUTOMATIC_TOOL_CHANGE_10" ; check if Tool change type = 10 the execute sub AUTOMATIC_TOOL_CHANGE_10 IF [# EQ 11] THEN CALL P"AUTOMATIC_TOOL_CHANGE_11" ; move back to saved work position IF [# EQ 1] THEN10 G01 X#<_saved.5001> Y#<_saved.5002> G01 Z#<_saved.5003> IF [[#] EQ #] THEN G01 A#<_saved.5004> IF [[#] EQ #] THEN G01 B#<_saved.5005> IF [[#] EQ #] THEN G01 C#<_saved.5005> END10 ( restore saved states ) N10 ; restore spindle & coolants states IF [#<_saved.5151> EQ 3] THEN M03 IF [#<_saved.5151> EQ 4] THEN M04 IF [#<_saved.5153> EQ 7] THEN M07 IF [#<_saved.5154> EQ 8] THEN M08 ; restore save feed F#<_saved.5130> ; restore g-code group 03 state G#<_saved.5103> ; restore g-code group 01 state G#<_saved.5101> ; reset HUD message M109 P"" Q4 ; notice end change procedure to PLC M108 M99 ; TOOL CHANGE EXIT ; ; Inputs: ; ; Ee #8 Exit code ; Aa #1 Undefined compulsory protected parameter ; ; Exit codes: ; ; 0 NONE ; 1 Error : One or more compulsory protected parameters are undefined! ; 2 Error : Sensor was found already tripped before to start approach movements to probe! ; 3 Error : Sensor was tripped during approach movements to probe! ; 4 Error : Sensor was found already tripped before to start 1st touch movements! ; 5 Error : Sensor was not found during 1st touch movements! ; 6 Error : Sensor was found already tripped before to start 2nd touch movements! ; 7 Error : Sensor was not found during 2nd touch movements! ; ** Error : Unknown error! ; SUB "TC_EXIT" ; check for error code IF [#<_args.e> EQ 0] THEN M99 ; reset HUD message IF [# EQ 1] THEN M109 P"" Q4 ; notice end change procedure to PLC M108 IF [#<_args.e> EQ 1] THEN M109 P"compulsory protected parameter ##<_args.a> is undefined!" Q-1 IF [#<_args.e> EQ 2] THEN M109 P"Error during measure of tool length

Sensor was found already tripped before to start approach movements to probe!
" Q1 IF [#<_args.e> EQ 3] THEN M109 P"Error during measure of tool length

Sensor was tripped during approach movements to probe!
" Q1 IF [#<_args.e> EQ 4] THEN M109 P"Error during measure of tool length

Sensor was found already tripped before to start 1st touch movements!
" Q1 IF [#<_args.e> EQ 5] THEN M109 P"Error during measure of tool length

Sensor was not found during 1st touch movements!
" Q1 IF [#<_args.e> EQ 6] THEN M109 P"Error during measure of tool length

Sensor was found already tripped before to start 2nd touch movements!
" Q1 IF [#<_args.e> EQ 7] THEN M109 P"Error during measure of tool length

Sensor was not found during 2nd touch movements!
" Q1 IF [#<_args.e> EQ 8] THEN M109 P"compulsory protected parameter ##<_args.a> has a wrong value!" Q-1 M109 P"Generic Error

Unknown error #<_args.e>!
" Q1 ENDSUB ; MANUAL TOOL CHANGE TYPE 0 ; ; This mode only notice to the PLC about the loaded tool ID. ; No other actions or movments will be done. ; SUB "MANUAL_TOOL_CHANGE_0" ; notice to PLC the loaded tool ID M61 Q# ENDSUB ; MANUAL TOOL CHANGE TYPE 1 ; ; Manual Tool Change (MTC) with tool length probing: ; a] Moves to tool-setter position and measures the loaded tool length. ; b] Moves to tool change position and show info about tool to manually change. ; c] Waits for the manual tool change by the operator which confirm that change is done. ; d] Moves to tool-setter position to measures the length of the new tool. ; e] Calcs the difference and uses this value as tool length compensation. ; SUB "MANUAL_TOOL_CHANGE_1" ; disable spindle, flood & mist M05 M09 ; initialize local variabiles #<_measure1_>=0 ; measured tool offset Z ; disable tool length compensation to avoid software limits error G49 ; measure of tool to unload : approaching to probe IF [# EQ 1] THEN M109 P"Measure of tool to unload : approacing to probe..." Q4 ; call touch probe procedure CALL P"TC_TOUCH_PROBE" A# B# C# D# E# ; calculate the tool length offset as the difference between when the sensor was tripped and the sensor Z position. #<_measure1_> = [#5713 - #] ; move to sensor safe position Z G53 G01 Z# F# ; move to tool change position G53 G01 Z# F# G53 G01 X# Y# ; a different tool should be inserted. Display the message to the user M109 P"
Insert tool T#
<@TI=#>
" Q2 G04 P1 ; notice to PLC the loaded tool ID M61 Q# ; measure of loaded tool : approaching to probe IF [# EQ 1] THEN M109 P"Measure of loaded tool : approacing to probe..." Q4 ; call touch probe procedure CALL P"TC_TOUCH_PROBE" A# B# C# D# E# ; calculate the tool length offset as the difference between when the sensor was tripped and the sensor Z position. #<_measure2_> = [#5713 - #] ; move to sensor safe position Z G53 G01 Z# F# ; calc compensation to do #<_toll_length_difference_>=[#<_measure2_>-#<_measure1_>+#5422] ; enable dynamic tool length compensation (without use of tools library) G43.1 Z#<_toll_length_difference_> ENDSUB ; MANUAL TOOL CHANGE TYPE 2 ; ; Manual Tool Change (MTC) with tool length from Tools Library info: ; a] Moves to tool change position and show info about tool to manually change. ; b] Waits for the manual tool change by the operator which confirm that change is done. ; c] If enabled applies the tool length compensation from Tools Libary info. ; SUB "MANUAL_TOOL_CHANGE_2" ; check if a different tool should be inserted. IF [# NE #] THEN10 ; disable spindle, flood & mist M05 M09 ; disable tool length compensation to avoid software limits error G49 ; move to tool change position G53 G01 Z# F# G53 G01 X# Y# ; A different tool should be inserted. Display the message to the user. M109 P"
Insert tool T#
<@TI=#>
" Q2 G04 P1 ; notice to PLC the loaded tool ID M61 Q# ; enable tool length compensation if enabled IF [# EQ 1] THEN G43 H# END10 ENDSUB ; AUTOMATIC TOOL CHANGE TYPE 10 ; ; This mode manages a rack of slots using place/side & pick/top approach. ; If there is a loaded tool it will be placed. ; If there is a requested tool it will be picked. ; If the tool length measurement/compensation are enabled they are automaticallly performed. ; SUB "AUTOMATIC_TOOL_CHANGE_10" ; checks if slots for the PICK and PLACE actions are valid ; ; this happen if G-code require a T with a slot higher than available slots to keep it IF [[# LT 0] OR [# GT #]] THEN M109 P"tool change require a PLACE slot number not in range (1..#)" Q-1 IF [[# LT 0] OR [# GT #]] THEN M109 P"tool change require a PICK slot number not in range (1..#)" Q-1 ; disable tool length compensation to avoid errors in software limits checking G49 ; check actions to do #<_has.place>=[# NE 0] ; evaluate if tool change has place action #<_has.pick>=[# NE 0] ; evaluate if tool change has pick action ( loaded tool placing ) ; check if necessary to place the loaded tool IF [#<_has.place>] THEN10 ; show place info IF [# EQ 1] THEN M109 P"Tool Changing: PLACE of T#" Q4 ; move Z to safe position G53 G00 Z# ; disable spindle, flood & mist M05 M09 ; open magazine CALL P"TC_MAGAZINE_OPEN" ; move XY to clamp zone slot of loaded tool to place it CALL P"TC_MOVE_XY_TO_CLAMP_ZONE_SLOT" M0 ; move Z to tool drop position G53 G00 Z#].z> ; move XY into tool place G53 G01 X#].x> Y#].y> F# ; unload tool-holder CALL P"TC_TOOLHOLDER_UNLOAD" ; inform the PLC that the tool has been dropped M61 Q0 ; move Z to safe position G53 G00 Z# ; turn OFF tool unlock output M63 P# ; check if there is not a pick action IF [#<_has.pick> EQ 0] THEN11 ; move XY to clamp zone slot of just now unloaded tool CALL P"TC_MOVE_XY_TO_CLAMP_ZONE_SLOT" M0 END11 END10 ( requested tool picking ) ; check if necessary to pick the requested tool IF [#<_has.pick>] THEN10 ; show pick info IF [# EQ 1] THEN M109 P"Tool Changing: PICK of T#" Q4 ; check if place action is enabled IF [#<_has.place> EQ 0] THEN11 ; move Z to safe position G53 G00 Z# ; disable spindle, flood & mist M05 M09 ; open magazine CALL P"TC_MAGAZINE_OPEN" ; move XY to outer of tool place position G53 G00 X#].x> Y#].y> ; enable bearing and cone cleaning blow CALL P"TC_BEARING_CONE_CLEANING_BLOW" E1 ELSE11 ; move Z to safe position G53 G00 Z# ; move XY to outer of tool place position G53 G00 X#].x> Y#].y> END11 ; turn ON tool unlock output and wait 1s M62 P# G04 P1.0 ; enable bearing and cone cleaning blow CALL P"TC_BEARING_CONE_CLEANING_BLOW" E1 ; move Z to tool pick position #=[#].z> + #] G53 G01 Z# F# ; load tool-holder CALL P"TC_TOOLHOLDER_LOAD" ; disable bearing and cone cleaning blow CALL P"TC_BEARING_CONE_CLEANING_BLOW" E0 ; inform PLC that requested tool has been picked M61 Q# ; move X or Y to outer of tool place position depending by slot axis orientation IF [# EQ 0] THEN11 # = [#].y> - #] G53 G00 Y# ELSE11 # = [#].x> - #] G53 G00 X# END11 ; move Z to safe position G53 G00 Z# END10 ( new loaded tool measuring and compensation ) ; check if there was a pick action so a new tool should be in the spindle IF [#<_has.pick>] THEN10 ; check if necessary to measure loaded tool IF [[[# EQ 1] AND [# EQ 0]] OR [# EQ 2]] THEN11 CALL P"TC_TOUCH_PROBE" END11 ; enable tool length compensation if enabled IF [# EQ 1] THEN G43 H# END10 ; close magazine CALL P"TC_MAGAZINE_CLOSE" ENDSUB ; AUTOMATIC TOOL CHANGE TYPE 11 ; ; This mode manages a rack of slots using place/top & pick/top approach. ; If there is a loaded tool it will be placed. ; If there is a requested tool it will be picked. ; If the tool length measurement/compensation are enabled they are automaticallly performed. ; SUB "AUTOMATIC_TOOL_CHANGE_11" ; checks if slots for the PICK and PLACE actions are valid ; ; this happen if G-code require a T with a slot higher than available slots to keep it IF [[# LT 0] OR [# GT #]] THEN M109 P"tool change require a PLACE slot number not in range (1..#)" Q-1 IF [[# LT 0] OR [# GT #]] THEN M109 P"tool change require a PICK slot number not in range (1..#)" Q-1 ; disable tool length compensation to avoid errors in software limits checking G49 ; check actions to do #<_has.place>=[# NE 0] ; evaluate if tool change has place action #<_has.pick>=[# NE 0] ; evaluate if tool change has pick action ( loaded tool placing ) ; check if necessary to place the loaded tool IF [#<_has.place>] THEN10 ; show place info IF [# EQ 1] THEN M109 P"Tool Changing: PLACE of T#" Q4 ; move Z to safe position G53 G00 Z# ; disable spindle, flood & mist M05 M09 ; open magazine CALL P"TC_MAGAZINE_OPEN" ; move XY to clamp zone slot of loaded tool to place it CALL P"TC_MOVE_XY_TO_CLAMP_ZONE_SLOT" M0 ; move XY into tool place G53 G01 X#].x> Y#].y> F# ; aproach to tool-holder drop zone G53 G01 Z[#].z> + #] F# G53 G01 Z[#].z> + #] F# ; unload tool-holder CALL P"TC_TOOLHOLDER_UNLOAD" ; inform the PLC that the tool has been dropped M61 Q0 ; move Z to safe position G53 G00 Z# ; turn OFF tool unlock output M63 P# ; check if there is not a pick action IF [#<_has.pick> EQ 0] THEN11 ; move XY to clamp zone slot of just now unloaded tool CALL P"TC_MOVE_XY_TO_CLAMP_ZONE_SLOT" M0 END11 END10 ( requested tool picking ) ; check if necessary to pick the requested tool IF [#<_has.pick>] THEN10 ; show pick info IF [# EQ 1] THEN M109 P"Tool Changing: PICK of T#" Q4 ; check if place action is enabled IF [#<_has.place> EQ 0] THEN11 ; move Z to safe position G53 G00 Z# ; disable spindle, flood & mist M05 M09 ; open magazine CALL P"TC_MAGAZINE_OPEN" ; move XY to clamp zone slot of requested tool to pick it CALL P"TC_MOVE_XY_TO_CLAMP_ZONE_SLOT" M1 ; move XY into tool place G53 G01 X#].x> Y#].y> F# ELSE11 ; move XY to outer of tool place position G53 G00 X#].x> Y#].y> END11 ( BEGIN UNLOAD TOOL-HOLDER ) ; aproach to tool-holder drop zone G53 G01 Z[#].z> + #] F# ; turn ON tool unlock output M62 P# ; enable bearing and cone cleaning blow CALL P"TC_BEARING_CONE_CLEANING_BLOW" E1 ; check if required unlock output feedback IF [# GT 0] THEN11 ; wait and check for tool unlock input signal with timeout M66 P# L# Q# IF [#5722 EQ #] THEN M109 P"TOOL T# PICK ERROR

Collet Unlock Input is LOW
" Q1 END11 ; wait and check spindle S1/S2 for S1 HIGH & S2 LOW CALL P"TC_WAIT_AND_CHECK_SPINDLE_S1_S2_FOR_HL" ; aproach to tool-holder drop zone G53 G01 Z[#].z> + #] F# ; disable bearing and cone cleaning blow CALL P"TC_BEARING_CONE_CLEANING_BLOW" E0 ; move Z to tool pick position G53 G01 Z#].z> F# ; turn OFF tool unlock output and wait 1s M63 P# ; check if required unlock output feedback IF [# GT 0] THEN11 ; wait settle time for P5 input stabilizatin G04 P1.0 ; wait and check for tool unlock input signal with timeout M66 P# L# Q# IF [#5722 EQ #] THEN12 M109 P"TOOL T# PICK ERROR

Cone present Input is LOW
" Q1 END12 END11 ; cone grip pulse management CALL P"TC_CONE_GRIP_PULSE" ; inform PLC that requested tool has been picked M61 Q# ; move Z to safe position G53 G01 Z# F# ; move XY to clamp zone slot of requested tool just now loaded CALL P"TC_MOVE_XY_TO_CLAMP_ZONE_SLOT" M1 END10 ( new loaded tool measuring and compensation ) ; check if there was a pick action so a new tool should be in the spindle IF [#<_has.pick>] THEN10 ; check if necessary to measure loaded tool IF [[[# EQ 1] AND [# EQ 0]] OR [# EQ 2]] THEN11 CALL P"TC_TOUCH_PROBE" END11 ; enable tool length compensation if enabled IF [# EQ 1] THEN G43 H# END10 ; close magazine CALL P"TC_MAGAZINE_CLOSE" ENDSUB ; TOOL CHANGE CONE GRIP PULSE ; SUB "TC_CONE_GRIP_PULSE" ; check if required cone grip pulse IF [# GT 0] THEN10 G04 P# M62 P# G04 P# M63 P# END10 ENDSUB ; TOOL CHANGE BEARING/CONE CLEANING BLOW ; ; Arguments ; E0 #8 Enabled state: OFF ; E1 #8 Enabled state: ON ; SUB "TC_BEARING_CONE_CLEANING_BLOW" ; evaluate enabled state IF [#8 EQ 0] THEN10 ; check if required cone clearing blow and put it OFF IF [# GT 0] THEN11 M63 P# END11 ; check if required bearing cleaning blow and put it OFF IF [# GT 0] THEN11 M63 P# END11 ELSE10 ; check if required cone clearing blow and put it ON IF [# GT 0] THEN11 M62 P# END11 ; check if required bearing cleaning blow and put it ON IF [# GT 0] THEN11 M62 P# END11 END10 ENDSUB ; TOOL CHANGE WAIT AND CHECK SPINDLE S1/S2 FOR S1 LOW & S2 HIGH ; SUB "TC_WAIT_AND_CHECK_SPINDLE_S1_S2_FOR_LH" ; check if required spindle S1/S2 management IF [[# GT 0] AND [# GT 0]] THEN10 ; wait and check for spindle S1/S2 management M66 P# L# Q# IF [#5722 EQ #] THEN M109 P"TOOL T# PLACE ERROR

Spindle S1 is HIGH
" Q1 M66 P# L# Q# IF [#5722 EQ #] THEN M109 P"TOOL T# PLACE ERROR

Spindle S2 is LOW
" Q1 END10 ENDSUB ; TOOL CHANGE WAIT AND CHECK SPINDLE S1/S2 FOR S1 HIGH & S2 LOW ; SUB "TC_WAIT_AND_CHECK_SPINDLE_S1_S2_FOR_HL" ; check if required spindle S1/S2 management IF [[# GT 0] AND [# GT 0]] THEN10 ; wait and check for spindle S1/S2 management M66 P# L# Q# IF [#5722 EQ #] THEN M109 P"TOOL T# PICK ERROR

Spindle S1 is LOW
" Q1 M66 P# L# Q# IF [#5722 EQ #] THEN M109 P"TOOL T# PICK ERROR

Spindle S2 is HIGH
" Q1 END10 ENDSUB ; TOOL CHANGE MOVE XY TO CLAMP ZONE SLOT FOR LOADED OR SELECTED TOOL ; ; Arguments ; M0 #13 Required position: for the loaded tool ; M1 #13 Required position: for the requested tool ; SUB "TC_MOVE_XY_TO_CLAMP_ZONE_SLOT" ; evaluate required position IF [#13 EQ 0] THEN10 ; move XY to outer of tool place position depending by slot axis orientation IF [# EQ 0] THEN11 G53 G00 Y[#].y> - #] G53 G00 X#].x> ELSE11 G53 G00 X[#].x> - #] G53 G00 Y#].y> END11 ELSE10 ; move XY to outer of tool place position depending by slot axis orientation IF [# EQ 0] THEN11 G53 G00 Y[#].y> - #] G53 G00 X#].x> ELSE11 G53 G00 X[#].x> - #] G53 G00 Y#].y> END11 END10 ENDSUB ; TOOL CHANGE MOVE TO SAFE Z CLAMP ZONE TOOL-SETTER ; SUB "TC_MOVE_TO_SAFE_Z_CLAMP_ZONE_TOOLSETTER" ; move Z to safe position G53 G00 Z# ; move XY to outer of tool-setter position depending by slot axis orientation IF [# EQ 0] THEN11 G53 G00 Y[# - #] G53 G00 X# ELSE11 G53 G00 X[# - #] G53 G00 Y# END11 ENDSUB ; TOOL CHANGE TOUCH PROBE EXTERNAL REQUEST ; SUB "TC_TOUCH_PROBE_EXTERNAL_REQUEST" ; disable tool length compensation to avoid software limits error G49 ; move to safe Z clamp zone tool-setter CALL P"TC_MOVE_TO_SAFE_Z_CLAMP_ZONE_TOOLSETTER" ; open magazine CALL P"TC_MAGAZINE_OPEN" ; call touch probe procedure CALL P"TC_TOUCH_PROBE" ; move to safe Z clamp zone tool-setter CALL P"TC_MOVE_TO_SAFE_Z_CLAMP_ZONE_TOOLSETTER" ; close magazine CALL P"TC_MAGAZINE_CLOSE" ENDSUB ; TOOL CHANGE TOUCH PROBE ; SUB "TC_TOUCH_PROBE" ; check mode type IF [[# EQ 10] OR [# EQ 11]] THEN10 ; move to safe Z clamp zone tool-setter CALL P"TC_MOVE_TO_SAFE_Z_CLAMP_ZONE_TOOLSETTER" ELSE10 ; move to safe Z zone tool-setter G53 G01 Z# F# END10 ; move XY to probe positions G53 G00 X# Y# ; check if required cleaning probe pulse IF [# GT 0] THEN11 M62 P# G04 P# M63 P# END11 ; move z to probe approaching position G53 G38.3 Z# X# Y# F# ; check if sensor was found already tripped before to start approach movements to probe IF [#5700 EQ -2] THEN CALL P"TC_EXIT" E2 ; check if sensor was tripped during approach movements to probe IF [#5700 EQ 1] THEN CALL P"TC_EXIT" E3 ; call tc touch probe managemnt CALL P"TC_TOUCH_PROBE_MAIN" A# B# C# D# E# ; calc and set new tool length (offset Z) #<_offset.z_>=[#5713 - #] G10 L1 P# V# X0 Y0 Z#<_offset.z_> ; show calculated tool length IF [# EQ 1] THEN M109 P"Tool T# measured length = #<_offset.z_>mm" Q4 ; check mode type IF [[# EQ 10] OR [# EQ 11]] THEN10 ; move to safe Z clamp zone tool-setter CALL P"TC_MOVE_TO_SAFE_Z_CLAMP_ZONE_TOOLSETTER" ELSE10 ; move to safe Z zone tool-setter G53 G01 Z# F# END10 ENDSUB ; TOOL CHANGE TOUCH PROBE MAIN ; ; Inputs: ; ; Ee #8 Exit code ; Aa #1 Sensor top/center position Z (MCS) ; Bb #2 Z feed to 1st probe input capture (SLOW) ; Cc #3 Z up movement after 1st touch capture (REL) ; Dd #7 Minimum tool lenght accepted ; Ee #8 Z feed to 2nd probe input capture (VERY SLOW) ; SUB "TC_TOUCH_PROBE_MAIN" ; disable the feed rate override controls ; ; NOTE ; ==== ; During debug movements, for safety, you can disable this code and use feed rate OVR M50 P0 ; measure of tool : 1st touch IF [# EQ 1] THEN M109 P"Tool Measuring: Approach for 1st touch..." Q4 G53 G38.3 Z[#<_args.a>+#<_args.d>] F#<_args.b> ; check if sensor was found already tripped before to start 1st touch movements IF [#5700 EQ -2] THEN10 ; restore the feed rate override controls M50 P# ; move to safe Z clamp zone tool-setter and notice error CALL P"TC_MOVE_TO_SAFE_Z_CLAMP_ZONE_TOOLSETTER" CALL P"TC_EXIT" E4 END10 ; check if sensor was not found during 1st touch movements IF [#5700 NE 1] THEN10 ; restore the feed rate override controls M50 P# ; move to safe Z clamp zone tool-setter and notice error CALL P"TC_MOVE_TO_SAFE_Z_CLAMP_ZONE_TOOLSETTER" CALL P"TC_EXIT" E5 END10 ; measure of tool : 2nd touch IF [# EQ 1] THEN M109 P"Tool Measuring: Approach for 2nd touch..." Q4 G53 G00 Z[#5713+#<_args.c>] G53 G38.3 Z[#<_args.a>+#<_args.d>] F#<_args.e> ; check if sensor was found already tripped before to start 2nd touch movements IF [#5700 EQ -2] THEN10 ; restore the feed rate override controls M50 P# ; move to safe Z clamp zone tool-setter and notice error CALL P"TC_MOVE_TO_SAFE_Z_CLAMP_ZONE_TOOLSETTER" CALL P"TC_EXIT" E6 END10 ; check if sensor was not found during 2nd touch movements IF [#5700 NE 1] THEN10 ; restore the feed rate override controls M50 P# ; move to safe Z clamp zone tool-setter and notice error CALL P"TC_MOVE_TO_SAFE_Z_CLAMP_ZONE_TOOLSETTER" CALL P"TC_EXIT" E7 END10 ; restore the feed rate override controls M50 P# ENDSUB ; TOOL CHANGE TOOLHOLDER LOAD (ATC) ; SUB "TC_TOOLHOLDER_LOAD" ; turn OFF tool unlock output and wait 1s M63 P# G04 P1.0 ; check if required unlock output feedback IF [# GT 0] THEN10 ; wait and check for tool unlock input signal with timeout M66 P# L# Q# IF [#5722 EQ #] THEN M109 P"TOOL T# PICK ERROR

Collet Unlock Input is LOW
" Q1 END10 ; wait and check spindle S1/S2 for S1 HIGH & S2 LOW CALL P"TC_WAIT_AND_CHECK_SPINDLE_S1_S2_FOR_HL" M99 ; TOOL CHANGE TOOLHOLDER UNLOAD (ATC) ; SUB "TC_TOOLHOLDER_UNLOAD" ; turn ON tool unlock output and wait 1s M62 P# G04 P1.0 ; check if required unlock output feedback IF [# GT 0] THEN10 ; wait and check for tool unlock input signal with timeout M66 P# L# Q# IF [#5722 EQ #] THEN11 ; turn OFF tool unlock output M63 P# ; notice error and stop M109 P"TOOL T# PLACE ERROR

Collet Unlock Input is HIGH
" Q1 END11 END10 ; wait and check spindle S1/S2 for S1 LOW & S2 HIGH CALL P"TC_WAIT_AND_CHECK_SPINDLE_S1_S2_FOR_LH" ENDSUB ; TOOL CHANGE MAGAZINE UPDATE STATE ; ; # ; 0 = undefined ; 1 = open ; 2 = closed ; SUB "TC_MAGAZINE_UPDATE_STATE" ; set magazine state to UNDEFINED #=0 ; evaluate magazine type IF [# EQ 1] THEN10 IF [[# GT 0] AND [# GT 0]] THEN11 M66 P# L# IF [#5722 EQ #] THEN M109 P"Error in magazine input recovering states" Q1 #<_open_>=#5720 M66 P# L# IF [#5722 EQ #] THEN M109 P"Error in magazine input recovering states" Q1 #<_closed_>=#5720 IF [[#<_open_> EQ 1] AND [#<_closed_> EQ 0]] THEN #=1 IF [[#<_open_> EQ 0] AND [#<_closed_> EQ 1]] THEN #=2 END11 END10 ENDSUB ; TOOL CHANGE MAGAZINE OPEN ; SUB "TC_MAGAZINE_OPEN" ; get magazine state CALL P"TC_MAGAZINE_UPDATE_STATE" ; evaluate magazine type IF [# EQ 1] THEN10 ; if magazine is already OPEN nothing to do IF [# EQ 1] THEN11 M99 END11 ; open magazine IF [# EQ 1] THEN M109 P"Opening Magazine" Q4 #=0 M63 P# M62 P# IF [# GT 0] THEN11 M66 P# L# Q# M63 P# IF [#5722 EQ #] THEN M109 P"Magazine not reached open state
in the specified time" Q1 ELSE11 G4 P# M63 P# END11 IF [# GT 0] THEN11 M66 P# L# IF [#5722 EQ #] THEN M109 P"Error in magazine input recovering states" Q1 IF [#5720 EQ 1] THEN M109 P"Magazine in wrong state

Opened/Closed inputs are HIGH" Q1 END11 #=1 IF [# EQ 1] THEN M109 P"" Q4 END10 ENDSUB ; TOOL CHANGE MAGAZINE CLOSE ; SUB "TC_MAGAZINE_CLOSE" ; check if magazine close is bypassed IF [# EQ 1] THEN M99 ; get magazine state CALL P"TC_MAGAZINE_UPDATE_STATE" ; evaluate magazine type IF [# EQ 1] THEN10 ; if magazine is already CLOSED nothing to do IF [# EQ 2] THEN11 M99 END11 ; close magazine IF [# EQ 1] THEN M109 P"Closing Magazine" Q4 #=0 M63 P# M62 P# IF [# GT 0] THEN11 M66 P# L# Q# M63 P# IF [#5722 EQ #] THEN M109 P"Magazine not reached closed state
in the specified time" Q1 ELSE11 G4 P# M63 P# END11 IF [# GT 0] THEN11 M66 P# L# IF [#5722 EQ #] THEN M109 P"Error in magazine input recovering states" Q1 IF [#5720 EQ 1] THEN M109 P"Magazine in wrong state

Opened/Closed inputs are HIGH" Q1 END11 #=2 IF [# EQ 1] THEN M109 P"" Q4 END10 ENDSUB ; TOOL CHANGE TOGGLE CONE LOAD/UNLOAD ; SUB "TC_TOGGLE_CONE_LOAD_UNLOAD" ; turn ON tool unlock output and wait 1s M62 P# G04 P1.0 ; wait cone load/unload input goes low IF [# GT 0] THEN11 M66 P# L# IF [#5722 EQ #] THEN M109 P"Unable to get cone load/unload input state" Q1 ELSE11 G04 P# END11 ; turn OFF tool unlock output M63 P# ; check if required cone grip pulse IF [# GT 0] THEN11 G04 P# M62 P# G04 P# M63 P# END11 ENDSUB ; TOOL CHANGE INITIALIZATION ; SUB "TC_INIT" ; if true enable all hud messages # = 0 ; check if there are compulsory protected parameters undefined ; tool change generic parameters IF [#6000 EQ #0] THEN CALL P"TC_EXIT" E1 A6000 IF [#6001 EQ #0] THEN CALL P"TC_EXIT" E1 A6001 IF [#6009 EQ #0] THEN CALL P"TC_EXIT" E1 A6009 IF [#6016 EQ #0] THEN CALL P"TC_EXIT" E1 A6016 ; manual tool change parameters IF [#6002 EQ #0] THEN CALL P"TC_EXIT" E1 A6002 IF [#6003 EQ #0] THEN CALL P"TC_EXIT" E1 A6003 IF [#6004 EQ #0] THEN CALL P"TC_EXIT" E1 A6004 ; tls (tool length presetter) parameters IF [#6005 EQ #0] THEN CALL P"TC_EXIT" E1 A6005 IF [#6006 EQ #0] THEN CALL P"TC_EXIT" E1 A6006 IF [#6007 EQ #0] THEN CALL P"TC_EXIT" E1 A6007 IF [#6008 EQ #0] THEN CALL P"TC_EXIT" E1 A6008 IF [#6010 EQ #0] THEN CALL P"TC_EXIT" E1 A6010 IF [#6011 EQ #0] THEN CALL P"TC_EXIT" E1 A6011 IF [#6012 EQ #0] THEN CALL P"TC_EXIT" E1 A6012 IF [#6013 EQ #0] THEN CALL P"TC_EXIT" E1 A6013 IF [#6014 EQ #0] THEN CALL P"TC_EXIT" E1 A6014 IF [#6015 EQ #0] THEN CALL P"TC_EXIT" E1 A6015 IF [#6017 EQ #0] THEN CALL P"TC_EXIT" E1 A6017 IF [#6018 EQ #0] THEN CALL P"TC_EXIT" E1 A6018 ; atc parameters IF [#6020 EQ #0] THEN CALL P"TC_EXIT" E1 A6020 IF [#6021 EQ #0] THEN CALL P"TC_EXIT" E1 A6021 IF [#6022 EQ #0] THEN CALL P"TC_EXIT" E1 A6022 IF [#6023 EQ #0] THEN CALL P"TC_EXIT" E1 A6023 IF [#6024 EQ #0] THEN CALL P"TC_EXIT" E1 A6024 IF [#6025 EQ #0] THEN CALL P"TC_EXIT" E1 A6025 IF [#6026 EQ #0] THEN CALL P"TC_EXIT" E1 A6026 IF [#6036 EQ #0] THEN CALL P"TC_EXIT" E1 A6036 IF [#6037 EQ #0] THEN CALL P"TC_EXIT" E1 A6037 IF [#6038 EQ #0] THEN CALL P"TC_EXIT" E1 A6038 IF [#6039 EQ #0] THEN CALL P"TC_EXIT" E1 A6039 IF [#6040 EQ #0] THEN CALL P"TC_EXIT" E1 A6040 IF [#6041 EQ #0] THEN CALL P"TC_EXIT" E1 A6041 IF [#6042 EQ #0] THEN CALL P"TC_EXIT" E1 A6042 IF [#6043 EQ #0] THEN CALL P"TC_EXIT" E1 A6043 IF [#6044 EQ #0] THEN CALL P"TC_EXIT" E1 A6044 IF [#6045 EQ #0] THEN CALL P"TC_EXIT" E1 A6045 IF [#6046 EQ #0] THEN CALL P"TC_EXIT" E1 A6046 IF [#6047 EQ #0] THEN CALL P"TC_EXIT" E1 A6047 IF [#6048 EQ #0] THEN CALL P"TC_EXIT" E1 A6048 IF [#6050 EQ #0] THEN CALL P"TC_EXIT" E1 A6050 IF [#6051 EQ #0] THEN CALL P"TC_EXIT" E1 A6051 IF [#6052 EQ #0] THEN CALL P"TC_EXIT" E1 A6052 IF [#6053 EQ #0] THEN CALL P"TC_EXIT" E1 A6053 IF [#6054 EQ #0] THEN CALL P"TC_EXIT" E1 A6054 IF [#6055 EQ #0] THEN CALL P"TC_EXIT" E1 A6055 IF [#6056 EQ #0] THEN CALL P"TC_EXIT" E1 A6056 IF [#6057 EQ #0] THEN CALL P"TC_EXIT" E1 A6057 IF [#6058 EQ #0] THEN CALL P"TC_EXIT" E1 A6058 IF [#6059 EQ #0] THEN CALL P"TC_EXIT" E1 A6059 IF [#6060 EQ #0] THEN CALL P"TC_EXIT" E1 A6060 ; define tool change generic parameters #=#6000 #=#6001 #=#6009 #=#6016 ; define manual tool change parameters #=#6002 #=#6003 #=#6004 ; define tls (tool length presetter) parameters #=#6005 #=#6006 #=#6007 #=#6008 #=#6010 #=#6011 #=#6012 #=#6013 #=#6014 #=#6015 #=#6017 #=#6018 ; define atc parameters #=#6020 #=#6021 #=#6022 #=#6023 #=#6024 #=#6025 #=#6026 #=#6050 #=#6051 #=#6052 #=#6053 #=#6054 #=#6055 #=#6056 #=#6057 #=#6058 #=#6059 #=#6036 #=#6037 #=#6038 #=#6039 #=#6040 #=#6041 #=#6042 #=#6043 #=#6044 #=#6045 #=#6046 #=#6047 #=#6048 ; check slots number and get slots positions parameters address #=#6060 IF [# LT 0] THEN CALL P"TC_EXIT" E8 A6060 IF [[#6049 EQ #0] OR [#6049 EQ 0]] THEN10 IF [# GT 13] THEN CALL P"TC_EXIT" E8 A6060 #=6061 ELSE10 #=#6049 IF [[# + [# * 3] GE 7000] THEN CALL P"TC_EXIT" E8 A6049 END10 ; recover atc slots positions (MCS) #<_i_>=1 #<_j_>=# WHILE [#<_i_> LE #] DO10 IF [##<_j_> EQ #0] THEN CALL P"TC_EXIT" E1 A#<_j_> #].x>=##<_j_> #<_j_>=[#<_j_> + 1] IF [##<_j_> EQ #0] THEN CALL P"TC_EXIT" E1 A#<_j_> #].y>=##<_j_> #<_j_>=[#<_j_> + 1] IF [##<_j_> EQ #0] THEN CALL P"TC_EXIT" E1 A#<_j_> #].z>=##<_j_> #<_j_>=[#<_j_> + 1] #<_i_>=[#<_i_> + 1] END10 ENDSUB