M6 - MDI Command remapped to - toolchang2.ngc o sub (M108 P#<_current_tool> Q#<_selected_tool> ) ;assign the tool numbers held in parameters to the pocket numbers #1 = #5190 #2 = #5191 #3 = #5192 #4 = #5193 #5 = #5194 #6 = #5195 #7 = #5196 #8 = #5197 #9 = #5198 #10 = #5199 #11 = #5200 #12 = #5201 ;assign the variables passed by M6 to some parameters #100 = #<_selected_tool> #110 = #<_current_tool> (#120 = #) O10 if [#100 EQ #110] ; checks if tool in the spindle is same as requested o endsub [1] M2 O10 endif # = 0 ; assigns 0 to the next pocket for a later check if the tool is found in the basket # = 0 ; assigns 0 to the next pocket for a later check if the tool is found in the basket and loaded #15 = 12 ;assign test parameter the number of pockets in the carousel O100 do O110 if [#[5189 + #15] EQ #100] ; checks all pockets to see if it contains tool number requested as the new tool # = #15 ; if tool is found in pocket, assigns the next pocket O110 endif O115 if [#[5189 + #15] EQ #110] ; checks if the pocket is loaded in spindle # = #15 O115 endif #15= [#15 - 1] O100 while [#15 GT 0] ;now we know which pocket the next tool is sitting in ;and we know inwhich pocket the current tool is ;we need to know if we need to put a tool away ;or if there is no tool in the spindle O180 IF [#110 GT 0] ; checks if there is a valid tool in the spindle O190 if [# EQ 0] ;If there is a tool in the spindle, checks if it is an pocket ; Go for manual Tool removal G53 G0 Z0 ;raise spindle G53 G0 X0 Y0 ;move to door M125 ; remove tool O190 endif O195 if [# GT 0] ;If there is a tool in the spindle, checks if it is an pocket ; Go for atc Tool removal G0 G53 Z0 ; raise spindle M110 ; draw bar loose M112 ; lower basket M116 ; raise pockets O195 endif O180 ENDIF O200 IF [#100 GT 0] ; selected tool is not tool0 O210 if [# EQ 0] ;if new tool is not in a pocket ; Go for manual Tool load M113 ; Raise basket G53 G0 Z0 ; Raise spindle G53 G0 X0 Y0 ; move to door M110 ; draw bar loose M126 ; manual tool load O210 endif O215 if [# GT 0] ;If new tool is in a pocket ; Go for atc Tool Load G0 G53 Z0 ; raise sindle M110 ; draw bar loose M112 ; Lower basket M131 P# ; load pocket M114 ; air blast S150 M3 ; rotate spindle M113 ; raise basket M115 ; stop air blast M111 ; clamp tool M5 ; stop spindle O215 endif O200 Else ;new tool is 0 raise basket and clamp drawbar M113 ;raise basket M111 ;clamp drawbar O200 ENDIF M61 Q#100 o endsub [1] M2