Good day guys
I need help with the macro for manual tool change with a fixed position tool setter. I have used a macro found on the forum. it works as it should except for the Z height which is incorrect after the tool change. My understanding of it is that I zero my work coordinates and run the file when it comes to the m6 command the M6 start macro takes over moves to the tool change position waits for the manual too change, then probes the new tool. it then waits for the cycle start button to be pressed and starts the M6 end macro which should bring the tool back to where it the previous tool stopped with the tool height Zero in the position. I have attached a short video of the issue. here you can see that before the tool change the Machine coordinates for Z is -30 and after the tool change it is -125. please help with correcting the code.
https://youtu.be/mrfNlQ5pM5M?si=7JmL6Iqr2e-vs4yLthis is the macro that i'm using.
M6 start macro
' Set variables to store some current, selected and user defined values
tool = GetSelectedTool() 'Value for Tool DRO at completion of tool change
CurrentFeedMode = GetOemDRO(819) 'Get current G0/G1 state
CurrentUnitsMM = GetOemLED(802) 'Get Current MM Units state
CurrentAbsCMode = GetOemLED(48) 'Get current G90/G91 state
CurrentFeedRate = GetOemDRO(818) 'Get the current Feed Rate
ToolChangeX = GetUserDRO(1200) 'Get user defined tool change location
ToolChangeY = GetUserDRO(1201)
ToolChangeZ = GetUserDRO(1202) 'NOTE: Z will be used for Auto Tool Zero start height
GageH = GetOEMDRO( 1001 ) 'Gage Block Height
ProbeD = 150 'Depth to probe for touch plate
' Move to user defined tool change location
If CurrentUnitsMM = FALSE Then 'Ensure measurement mode is in MM for macro
Code "G21"
End If
If IsSafeZ() Then 'If SafeZ is defined,
safeZ = GetSafeZ() 'use it for positioning commands
Else
safeZ = 0 'Otherwise, moves are made at MC Z0
End If
Code" G53 G0 Z" & safeZ 'Position spindle for tool change
Code"G53 G0 X" & ToolChangeX
Code"G53 G0 Y" & ToolChangeY
While IsMoving()
Sleep(10)
Wend
PText = "Tool #" & tool & " requested. (See Setup Sheet for details.)" _
& Chr(10) & "Insert requested tool and press OK to continue."
MachMsg(PText,"Tool Change Request",0)
SetCurrentTool( tool ) 'Set the Tool DRO to the new tool number
' Auto tool zero
AutoZeroPrompt = "Place probe for Auto Tool Zero and press OK" _
& Chr(10) & "Or press CANCEL to zero tool manually"
AutoZero = MachMsg(AutoZeroPrompt,"Auto Tool Zero",1)
If AutoZero = 1 Then 'AutoZero = 1, User pressed OK
Code "G53 G0 Z" & ToolChangeZ 'ToolChangeZ is MC for starting location of probing
While IsMoving()
Sleep (10)
Wend
ZCurrent = GetOemDro(802) 'Current Z DRO
ZNew = ZCurrent - ProbeD 'Probe depth end height
Code "G90F500" 'slow feed rate to 100 MM/MIN
Code "G31 Z" &ZNew 'Start the probe move
While IsMoving()
Sleep(10)
Wend
If GetOEMLed(825) = True Then 'Probing successful
ProbeTouch = GetVar(2002) 'Exact height touch plate was contacted
Code "G1 Z" & ProbeTouch 'Go there (corrects for potential over-run)
While IsMoving()
Sleep(10)
Wend
Call SetDro(2,GageH) 'Set Z DRO to adjusted value
FinalMove = GageH + 10
Code "G0 Z" &FinalMove 'Raise probe off of touch plate
While IsMoving()
Sleep(10)
Wend
Message("Press Cycle Start to continue...")
Else 'Probe did not contact touch plate
Message("Zero not achieved - Check probe and try again manually")
End If
Else 'User selected Cancel on Auto Tool Zero prompt
Message("Zero tool manually and press Cycle Start to continue...")
End If
'RESTORE MACHINE STATE VALUES
'Feed Rate
Code "F" &CurrentFeedRate 'restore starting feed rate
'G0/G1 State
If CurrentFeedMode = "80" Then 'Machine still in initial state at start of macro
Code "G0" 'so set move mode to G0
Else
Code "G" & CurrentFeedMode 'Otherwise set move mode to previous value
End If
'G20/G21 State
If CurrentUnitsMM Then 'Units was previously set to mm
Code "G21"
Else 'Units was previously set to inches
Code "G20"
End If
'G90/G91 State
If CurrentAbsCMode Then 'System was using absolute coordinates
Code "G90"
Else 'System was using incremental coordinates
Code "G91"
End If
------------------------------------------------------------------------------------
M6 end macro
'The (modified) default script here moves the tool back To m6start If Any movement has occured during the tool change..
x = GetToolChangeStart( 0 )
y = GetToolChangeStart( 1 )
z = GetToolChangeStart( 2 )
a = GetToolChangeStart( 3 )
b = GetToolChangeStart( 4 )
c = GetToolChangeStart( 5 )
If(IsSafeZ() = 1) Then
SafeZ = GetSafeZ()
Code "G53 G0 Z" & SafeZ
Else
Code "G53 G0 Z0"
End If
Code "G0 A" & a' & "B" & b & "C" & c
Code "F2000 X" & x
Code "F2000 Y" & y
Code "F2000 Z" & z