Guest User

Untitled

a guest
Feb 22nd, 2025
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.72 KB | None | 0 0
  1. ; M6 REMAP Macro for ATC RapidChange rack tool changer
  2. ;
  3. ; Assumptions
  4. ; 1 Tool number is equal to pocket number
  5. ; 2 Tool number is the discriminating factor for pick up procedure (from rack, from manual position)
  6. ; 3 all tools need to be measured
  7.  
  8. ; Uses tool number mounted as a work around for the broken handler in linuxcnc tooltable
  9. ; Note: If #5190 is manually entered into linuxnc.var it will be stored between starts of linux, this is currently not desired.
  10. ; Uses M66 E0 (analog input 00 to obtain tool-prep-pocket from iocontrol. This is more stable than a call on #<_hal[iocontrol.0.tool-prep-pocket]> as TxM6 and Tx and M6 seperately are interpreted)
  11.  
  12. ; DustCover actuation is done using a single signal pin via M64 and M65
  13.  
  14.  
  15. o<rack_change> sub
  16. ;(auto-restore modal settings on return)
  17. M73
  18. ; Use Exact Stop mode
  19. G61
  20. ; print to console (if available)
  21. (print, Storing tool and pocket information in local variables)
  22. #<newtool> = #<selected_tool>
  23. #<oldtool> = #<tool_in_spindle>
  24. ; call upon iocontrol.0.tool-prep-pocket via M66 and have it stored in #5399
  25. M66 E0
  26. ;#<newpocket> = #5399
  27. #5190=#5399
  28. (print, oldtool=#<oldtool>)
  29. (print, newtool=#<newtool>)
  30.  
  31. ; we must execute this macro only in the milltask interpreter or preview will break, so test for '#<_task>' which is 1 for the milltask interpreter and 0 in the UI's
  32. O100 if [#<_task> EQ 0]
  33. (print, Task is Null)
  34. O100 return [999]
  35. O100 endif
  36.  
  37. ; Ensure everything that we do is done in absolute coordinates
  38. G90
  39. ; Cutter comp off, otherwise G53 might go wrong
  40. G40
  41. ; Cancel tool offset (not needed until the end)
  42. G49
  43.  
  44. ; First things first, rapid to safe Z
  45. G53 G0 Z[#<_ini[AXIS_Z]MAX_LIMIT>-0.1]
  46. (print, Moved safe Z)
  47.  
  48. ; First, get rid of the old tool
  49. ; check if the spindle is not empty by checking if tool_in_spindle GT 0
  50. O200 if [#<oldtool> EQ #<newtool>]
  51. ; This is a special case in which no tool needs to be dropped off. This assumes that the user has the tool table under control. further down, during pick up of newtool a message will be brought forward to GUI
  52. (print, do absolutly nothing)
  53. O200 elseif [#<oldtool> GT 0]
  54. (print, Tool No #<oldtool> is in the spindle - we need to put it away)
  55. ; Check if old pocket is within range
  56. O210 if [#<oldtool> GT 0]
  57. O220 if [#<oldtool> LE #<_ini[ATC]NUMPOCKETS>]
  58. ;Tool within range, triggering put move to rack, assuming that the pocket is empty!
  59. (print, Putting tool away into rack in pocket #<oldtool>)
  60. ; We are already at safe Z; now rapid to pre position for a specific pocket
  61. G53 G0 X[#<_ini[ATC]FIRSTPOCKET_X> + [#<oldtool> -1] * #<_ini[ATC]DELTA_X>] Y[#<_ini[ATC]FIRSTPOCKET_Y> + [#<oldtool> -1] * #<_ini[ATC]DELTA_Y>]
  62. ;Open dust cover
  63. M65 P0
  64. G4 P2.0
  65. ;Drop spindle to IR sensor height
  66. G53 G0 Z[#<_ini[ATC]OFF_HEIGHT_Z>]
  67. ;Spin spindle CCW and place tool in rack
  68. M4 S1200
  69. G4 P 2.0
  70. G53 G01 Z #<_ini[ATC]FIRSTPOCKET_Z> F40
  71. ; Move back to IR sensor height above the old pocket
  72. G53 G0 Z[#<_ini[ATC]OFF_HEIGHT_Z>]
  73. M5
  74. G4 P2.0
  75. ; After this move there should be no tool left; check pin for going LOW L4
  76. M66 P1 L0
  77. O910 IF [#5399 EQ 1]
  78. (DEBUG, Timeout! Tool still in spindle - Aborting!)
  79. O910 return [999]
  80. O910 ENDIF
  81.  
  82. (print, Tool released)
  83. O220 else
  84. ; The tool's pocket number is not within the range of the rack and the tool needs to be removed manually
  85. ; Tool is still at safe Z height from before
  86. (print, Pocket is not within range, moving to manual change positon)
  87. G53 G0 X #<_ini[ATC]CHANGEX> Y #<_ini[ATC]CHANGEY>
  88. G53 G0 Z #<_ini[ATC]CHANGEZ>
  89. ;(MSG, Please remove tool manually from spindle. Afterwards press OK)
  90. ; Abuse M6 for a dialog with the user by briefly killing the requested tool and replacing it with T0
  91. T0
  92. M6
  93. T#<newtool>
  94. (print, Finished manual drop off)
  95. o220 endif
  96. (print, We are now without a tool at some position either safely above pocket or the manual change position)
  97. O210 endif
  98. O200 else
  99. ; There is nothing to do here but end the conditional
  100. (print, There is no tool in the spindle - No action required at this time)
  101. O200 endif
  102. (print, Reached end of drop off without error)
  103. ;go to safe Z
  104. G53 G0 Z[#<_ini[AXIS_Z]MAX_LIMIT>-0.1]
  105.  
  106.  
  107. ; Second Step, get new tool
  108. ; Check if the new tool number is EQ 0
  109. o300 if [#<oldtool> EQ #<newtool>]
  110. ; This is to check if the requested tool is already in the spindle. If so, all other steps are skipped and a message is displayed to the user using DEBUG
  111. (DEBUG, Attention - No tool change required. Not doing anything, check if tool offset remains valid)
  112. M2
  113. O300 elseif [#<newtool> GT 0]
  114. ; Tool is GT 0 and we thus need to get a tool from somewhere
  115. (print, New tool: #<newtool> needs to be picked up)
  116. ; Again, check if #newpocket is within range of the tool rack, otherwise pick at manual change position and measure
  117. O310 if [#<newtool> GT 0]
  118. ; Check only for error handling
  119. O320 if [#<newtool> LE #<_ini[ATC]NUMPOCKETS>]
  120. ; Tool within rack range, triggering get tool from rack, assuming that the pocket is filled
  121. (print, Getting tool #<newtool> from rack at pocket #<newtool>)
  122. ; Assuming that the pockets are populated; rapid move above selected_pocket at z0
  123. (print, Moving to safe preposition at z0)
  124. G53 G0 Z[#<_ini[AXIS_Z]MAX_LIMIT>-0.1]
  125. G53 G0 X[#<_ini[ATC]FIRSTPOCKET_X> + [#<newtool> -1] * #<_ini[ATC]DELTA_X>] Y[#<_ini[ATC]FIRSTPOCKET_Y> + [#<newtool> -1] * #<_ini[ATC]DELTA_Y>]
  126. ; Make sure dustcover is open
  127. M65 P0
  128. G4 P 2.0
  129. ; drop Z to IR sensor height
  130. G53 G0 Z[#<_ini[ATC]OFF_HEIGHT_Z>]
  131. ; spin spindle CW
  132. M3 S1200
  133. G4 P 2.0
  134. (print, above pocket #<newtool>, spindle running CW)
  135. ; move Z to pickup tool
  136. G53 G01 Z #<_ini[ATC]FIRSTPOCKET_Z> F40
  137. ; retract Z and repeat pickup to lock spindle nut
  138. G53 G0 Z[#<_ini[ATC]OFF_HEIGHT_Z>]
  139. G4 P0.2
  140. G53 G01 Z #<_ini[ATC]FIRSTPOCKET_Z> F40
  141. G53 G0 Z[#<_ini[ATC]OFF_HEIGHT_Z>]
  142. M5
  143. G4 P2.0
  144. ; check 2: Is there a tool in the spindle? Check immediately!
  145. M66 P1 L0
  146. (print, check tool in spindle AFTER M65 should be 1; VALUE #5399)
  147. O950 IF [#5399 NE 1]
  148. (print, Error! No tool found in spindle - Aborting!)
  149. O950 return [999]
  150. O950 ENDIF
  151. (print, Tool picked up, ready to move)
  152. ; Load tool number
  153. (print, Moving finished, tool loaded, now tell linuxcnc about the toolchange using M61)
  154. M61 Q#<newtool>
  155. G53 G0 Z[#<_ini[AXIS_Z]MAX_LIMIT>-0.1]
  156. (print, Tool loaded from rack, ready to measure)
  157. ;Close Dust cover
  158. M64 P0
  159.  
  160. O320 else
  161. ; The tool's pocket number is not within the range of the rack and the tool needs to picked up at the manual change position
  162. (print, Selected pocket is not within range, moving to manual pick up)
  163. ; rapid move to manual pick up position
  164. G53 G0 Z[#<_ini[AXIS_Z]MAX_LIMIT>-0.1]
  165. G53 G0 X[#<_ini[ATC]CHANGEX>] Y[#<_ini[ATC]CHANGEY>]
  166. G53 G0 Z[#<_ini[ATC]CHANGEZ>]
  167. ;Close dust cover
  168. M64 P0
  169. ; using the code being remapped here means 'use builtin behaviour' and should trigger the usual message
  170. (print, Now trigger M6 to tell the user which tool to pick)
  171. M6
  172. O320 ENDIF
  173.  
  174. ; Perform tool measurement - first rapid to tool sensor position
  175. G53 G0 Z[#<_ini[AXIS_Z]MAX_LIMIT>-0.1]
  176. G53 G0 X[#<_ini[TOOLSENSOR]X>] Y[#<_ini[TOOLSENSOR]Y>]
  177. ; Turn on airblast to clean tool length sensor
  178. ;M64 P #<_ini[ATC_PINS]CLEAN_TS>
  179. G53 G0 Z[#<_ini[TOOLSENSOR]Z>]
  180. ; Check certain inputs in probe_screen
  181. O420 if [#<_hal[gmoccapy.searchvel]> LE 0]
  182. O420 return [-1] ; indicate searchvel <= 0
  183. O420 endif
  184. O430 if [#<_hal[gmoccapy.probevel]> LE 0]
  185. O430 return [-2] ; indicate probevel <= 0
  186. O430 endif
  187.  
  188.  
  189.  
  190. ; Perform tool measurement in relative motion
  191. F #<_hal[gmoccapy.searchvel]>
  192. G91
  193. G38.2 Z #<_ini[TOOLSENSOR]MAXPROBE>
  194. G0 Z0.25
  195. F #<_hal[gmoccapy.probevel]>
  196. G38.2 Z-0.5
  197. ; Turn off airblast to clean sensor
  198. ;M65 P #<_ini[ATC_PINS]CLEAN_TS>
  199. O440 if [#5070 EQ 0]
  200. G90
  201. O440 return [-3] ; indicate probe contact failure to epilog
  202. O440 endif
  203.  
  204. G90
  205. G53 G0 Z[#<_ini[AXIS_Z]MAX_LIMIT>-0.1]
  206. (print, moving away from ts)
  207. #<touch_result> = #5063
  208. #<probeheight> = #<_hal[gmoccapy.probeheight]>
  209. #<blockheight> = #<_hal[gmoccapy.blockheight]>
  210. (print, #<touch_result> #<probeheight> #<blockheight>)
  211. G10 L1 P#<newtool> Z[#<touch_result> - #<_hal[gmoccapy.probeheight]> + #<_hal[gmoccapy.blockheight]>]
  212. G43
  213. O310 endif
  214. O300 endif
  215.  
  216. (print, End of Program)
  217. o<rack_change> endsub [1]
  218.  
  219. M2
  220. %
Advertisement
Add Comment
Please, Sign In to add comment