(author: Chris P) (version: 0.1) (date: 05/29/25) o sub ; Parameter #3989 is used to track if the rack is homed (M13) (volatile) ; Parameter #3990 is used to track the current tool pocket (persistently) ; Parameter #3991 is used to track the current tool loaded it in the spindle (persistently) ; Parameters #4001 to #4024 are used to track which tool is in which pocket (persistently) ; Parameter #4000 is not populated just used in the maths to calculate the above numbers ; # The Z height your spindle needs to be at to clamp/unclamp a tool from the ATC platter (Set via INI [ATC]Z_TOOL_CHANGE_HEIGHT) ; # The Z clearance height in machine coordinates that your spindle needs to be at to clear the tools during rack rotation (Set via INI [ATC]Z_TOOL_CLEARANCE_HEIGHT) (PRINT, o selected_tool: #, tool_in_spindle: #, selected_pocket: #, current_pocket: #, task: #<_task>) o100 if [#<_task> EQ 0] (DEBUG, Task is null) o return [999] o100 endif (this code eliminates tool missing error on load for multiple use tools) # = #3973 # = #3981 # = #3982 ; assign the variables passed by M6 change_prolog to some parameters #100 = # #110 = # #120 = # #121 = # o110 if [# EQ #] ; checks if tool in the spindle is same as requested (PRINT, Requested tool already in spindle) (PRINT, o endsub) o endsub [1] M2 o110 endif o120 if [#3991 NE #] (PRINT, o tool_in_spindle does not match 3991) o120 endif # = 0 ; assigns 0 to the next pocket for a later check if the tool is found in the rack # = 0 #130 = # ; assign test parameter the number of pockets in the rack o130 do o161 if [#[4000 + #130] EQ #] ; checks all pockets to see if it contains tool number requested as the new tool # = #130 ; if tool is found in pocket, assigns the next pocket o161 endif o162 if [#[4000 + #130] EQ 0] ; checks if the pocket is empty, last pocket checked will be the lowest empty pocket number, for putting tool in spindle away. # = #130 o162 endif #130 = [#130 - 1] o130 while [#130 GT 0] o140 if [# EQ 0] ; if tool is not found, aborts and sends a message (abort, Tool T%d# not found in rack) o140 endif ; now we know which pocket the next tool is sitting in ; we need to know if we need to put a tool away ; or if there is not tool in the spindle o150 if [# GT 0] ; checks if there is a valid tool in the spindle o151 if [# EQ 0] ; If there is a tool in the spindle, checks if there is an open pocket (abort, rack is full, cant store tool T# in rack) o151 endif o call [#]; puts the tool in spindle away into the open pocket (DEBUG, EVAL[vcp.getWidget{"rackatc"}.store_tool{#, #}]) #140 = # #[4000 + #140] = # ; save tool number in pocket #3991 = 0 ; empty tool in the spindle M61 Q0 G49 o150 endif o160 if [# GT 0] ; selected tool is not tool 0 o call [#] ; set the spindle to move to the right pocket for the selected tool (DEBUG, EVAL[vcp.getWidget{"rackatc"}.store_tool{#, 0}]) #150 = # #[4000 + #150] = 0 ; empty the pocket #3991 = # ; Set persistent variable to remember tool in spindle after power cycle o160 else M25 ; deactive drawbar o160 endif M61 Q# o170 if [1 EQ 1] G43 H# o170 endif o call (PRINT, o endsub) o endsub [1] M2