Skip to content
Vincent Coffey edited this page Jun 18, 2019 · 10 revisions

The Tool Change function is only available for CNCjs 1.9.11 or later versions

Getting Started

The manual tool change operation is initiated by a M6 command:

M6 ; Tool Change

It will pause program execution and prompt user to change the tool. You can run a tool change macro to perform a manual tool change, and click ▶ (Resume) to continue.

image

Read the following paragraphs to learn how to create a tool change macro to facilitate the process.

Initial Setup

1. Determine the tool change and the tool probe location

The tool change macro requires you to specify the tool change and the tool probe location in absolute coordinates. You can jog to the desire location and specify the position in your tool change macro with macro variables. It's recommended that you use upper case letters in variable names or prefix variable names with "_" or "$" to avoid conflict with reserved variables. The expression must be prefixed with "%" at the beginning of each line. For example:

%CLEARANCE_HEIGHT = 100
%TOOL_CHANGE_X = -300
%TOOL_CHANGE_Y = -300
%TOOL_CHANGE_Z = CLEARANCE_HEIGHT
%TOOL_PROBE_X = 0
%TOOL_PROBE_Y = 0
%TOOL_PROBE_Z = 20

2. Create a tool change macro

image

The tool change macro will perform the following operations:

  • Set user-defined variables

    %CLEARANCE_HEIGHT = 100
    %TOOL_CHANGE_X = -300
    %TOOL_CHANGE_Y = -300
    %TOOL_CHANGE_Z = CLEARANCE_HEIGHT
    %TOOL_PROBE_X = 0
    %TOOL_PROBE_Y = 0
    %TOOL_PROBE_Z = 20
    %PROBE_DISTANCE = 15
    %PROBE_FEEDRATE = 20
    %TOUCH_PLATE_HEIGHT = 10
    %RETRACTION_DISTANCE = 10
    
  • Keep a backup of current work position

    %X0 = posx, Y0 = posy, Z0 = posz
    
  • Save modal state

    ; Work Coordinate System: G54, G55, G56, G57, G58, G59
    %WCS = modal.wcs
    
    ; Plane: G17, G18, G19
    %PLANE = modal.plane
    
    ; Units: G20, G21
    %UNITS = modal.units
    
    ; Distance Mode: G90, G91
    %DISTANCE = modal.distance
    
    ; Feed Rate Mode: G93, G94
    %FEEDRATE = modal.feedrate
    
    ; Spindle State: M3, M4, M5
    %SPINDLE = modal.spindle
    
    ; Coolant State: M7, M8, M9
    %COOLANT = modal.coolant
    
  • Stop spindle

  • Raise to tool change Z (clearance height)

  • Go to tool change X,Y

  • Pause the program with M0 (pause w/ hold) for a manual tool change

  • Click Continue to resume

    image

  • Go to tool probe X,Y

  • Lower to tool probe Z

  • Pause the program with M1 (pause w/o hold) before probing

  • Click Continue to resume

    image

  • Perform a probe toward workpiece with a maximum probe distance

  • Set Z0 for the active work coordinate system

  • Raise to tool change Z

  • Go to tool change X,Y

  • Pause the program with M0 for cleanup (e.g. remove touch plate, wires, etc)

  • Click Continue to resume

    image

  • Go to previous work position

    G0 X[X0] Y[Y0]
    G0 Z[Z0]
    
  • Restore modal state

    [WCS] [PLANE] [UNITS] [DISTANCE] [FEEDRATE] [SPINDLE] [COOLANT]
    
  • Continue program execution

2.1. Tool Change Macro (WCS)

Below is a tool change macro that adjusts the current WCS, you can customize the macro for your needs:

; Wait until the planner queue is empty
%wait

; Set user-defined variables
%CLEARANCE_HEIGHT = 100
%TOOL_CHANGE_X = -300
%TOOL_CHANGE_Y = -300
%TOOL_CHANGE_Z = CLEARANCE_HEIGHT
%TOOL_PROBE_X = 0
%TOOL_PROBE_Y = 0
%TOOL_PROBE_Z = 20
%PROBE_DISTANCE = 15
%PROBE_FEEDRATE = 20
%TOUCH_PLATE_HEIGHT = 10
%RETRACTION_DISTANCE = 10

; Keep a backup of current work position
%X0=posx, Y0=posy, Z0=posz

; Save modal state
; * Work Coordinate System: G54, G55, G56, G57, G58, G59
; * Plane: G17, G18, G19
; * Units: G20, G21
; * Distance Mode: G90, G91
; * Feed Rate Mode: G93, G94
; * Spindle State: M3, M4, M5
; * Coolant State: M7, M8, M9
%WCS = modal.wcs
%PLANE = modal.plane
%UNITS = modal.units
%DISTANCE = modal.distance
%FEEDRATE = modal.feedrate
%SPINDLE = modal.spindle
%COOLANT = modal.coolant

; Stop spindle
M5
; Absolute positioning
G90

; Raise to tool change Z
G0 Z[TOOL_CHANGE_Z]
; Go to tool change X,Y
G0 X[TOOL_CHANGE_X] Y[TOOL_CHANGE_Y]
; Wait until the planner queue is empty
%wait

; Pause the program for a manual tool change
M0

; Go to tool probe X,Y
G0 X[TOOL_PROBE_X] Y[TOOL_PROBE_Y]
; Lower to tool probe Z
G0 Z[TOOL_PROBE_Z]
; Wait until the planner queue is empty
%wait

; Pause the program before probing
M1

; Probe toward workpiece with a maximum probe distance
G91 ; Relative positioning
G38.2 Z-[PROBE_DISTANCE] F[PROBE_FEEDRATE]
G90 ; Absolute positioning

; Set Z0 for the active work coordinate system
G10 L20 P0 Z[TOUCH_PLATE_HEIGHT]

; Retract from the touch plate
G91 ; Relative positioning
G0 Z[RETRACTION_DISTANCE]
G90 ; Absolute positioning

; Raise to tool change Z
G53 Z[TOOL_CHANGE_Z]
; Go to tool change X,Y
G53 X[TOOL_CHANGE_X] Y[TOOL_CHANGE_Y]
; Wait until the planner queue is empty
%wait

; Pause the program for cleanup (e.g. remove touch plate, wires, etc)
M0

; Go to previous work position
G0 X[X0] Y[Y0]
G0 Z[Z0]

; Restore modal state
[WCS] [PLANE] [UNITS] [DISTANCE] [FEEDRATE] [SPINDLE] [COOLANT]

2.2. Tool Change Macro (TLO)

Use the following codes if you want to update the tool length offset (TLO) instead of adjusting the current WCS:

; Wait until the planner queue is empty
%wait

; Set user-defined variables
%CLEARANCE_HEIGHT = 100
%TOOL_CHANGE_X = -300
%TOOL_CHANGE_Y = -300
%TOOL_CHANGE_Z = CLEARANCE_HEIGHT
%TOOL_PROBE_X = 0
%TOOL_PROBE_Y = 0
%TOOL_PROBE_Z = 20
%PROBE_DISTANCE = 15
%PROBE_FEEDRATE = 20
%TOUCH_PLATE_HEIGHT = 10
%RETRACTION_DISTANCE = 10

; Keep a backup of current work position
%X0=posx, Y0=posy, Z0=posz

; Save modal state
; * Work Coordinate System: G54, G55, G56, G57, G58, G59
; * Plane: G17, G18, G19
; * Units: G20, G21
; * Distance Mode: G90, G91
; * Feed Rate Mode: G93, G94
; * Spindle State: M3, M4, M5
; * Coolant State: M7, M8, M9
%WCS = modal.wcs
%PLANE = modal.plane
%UNITS = modal.units
%DISTANCE = modal.distance
%FEEDRATE = modal.feedrate
%SPINDLE = modal.spindle
%COOLANT = modal.coolant

; Stop spindle
M5
; Absolute positioning
G90

; Raise to tool change Z
G53 Z[TOOL_CHANGE_Z]
; Go to tool change X,Y
G53 X[TOOL_CHANGE_X] Y[TOOL_CHANGE_Y]

; Wait until the planner queue is empty
%wait

; Pause the program for a manual tool change
M0

; Go to Clearance Height
G53 Z[CLEARANCE_HEIGHT]
; Go to tool probe X,Y
G53 X[TOOL_PROBE_X] Y[TOOL_PROBE_Y]
; Go to tool probe Z
G53 Z[TOOL_PROBE_Z]

; Wait until the planner queue is empty
%wait

; Pause the program before probing
M1

; Cancel tool length offset
G49

; Probe toward workpiece with a maximum probe distance
G91 ; Relative positioning
G38.2 Z-[PROBE_DISTANCE] F[PROBE_FEEDRATE]
G90 ; Absolute positioning

; A dwell time of one second to make sure the planner queue is empty
G4 P1

; Update the tool length offset
G43.1 Z[posz - TOUCH_PLATE_HEIGHT]

; Retract from the touch plate
G91 ; Relative positioning
G0 Z[RETRACTION_DISTANCE]
G90 ; Absolute positioning

; Raise to tool change Z
G53 Z[TOOL_CHANGE_Z]
; Go to tool change X,Y
G53 X[TOOL_CHANGE_X] Y[TOOL_CHANGE_Y]

; Wait until the planner queue is empty
%wait

; Pause the program for cleanup (e.g. remove touch plate, wires, etc)
M0

; Go to previous work position
G0 X[X0] Y[Y0]
G0 Z[Z0]

; Restore modal state
[WCS] [PLANE] [UNITS] [DISTANCE] [FEEDRATE] [SPINDLE] [COOLANT]
Clone this wiki locally