OK, I'm sure this isn't the most efficient way of doing this, but I believe it works as intended. Running it in simulation, it appears to work correctly. I'm assuming here the quill is the Z axis, and the knee is the A axis. When you change tools, it over-rides the change in the Z DRO due to the change in tool length, and instead moves the A axis by the difference in length between the old and new tools. So, the effect is Z does not move, or is returned to its previous position if you moved it during the tool change, and the tool length is compensated for entirely by moving the knee. The knee is moved minus for a longer tool, and plus for a shorter tool.
Put the following in M6Start.m1s:
REM Get the current tool length, and store it in User DRO 1200 for M6End macro
OldToolLength = ToolLengthOffset()
SetUserDRO(1200, OldToolLength)
REM Get the current Z axis position, and store it in USer DRO 1201 for M6End macro
OldZPos = GetOEMDRO(802)
SetUserDRO(1201, OldZPos)
REM Activate the new tool
tool = GetSelectedTool()
SetCurrentTool( tool )
Put the folliowing in M6End.m1s:
REM Get the length of the current tool
NewToolLength = ToolLengthOffset()
REM Figure out how much tool length changed, and in which direction
OffsetChange = NewToolLength - OldToolLength
REM Get the Z DRO value before the new tool length was applied, stored in UserDRO 1201 by M6Start macro
OldZPos = GetUserDRO(1201)
SetOEMDRO(802, OldZPos)
REM Get the cuurent A axis (knee) position, and apply the new tool length
OldAPos = GetOEMDRO(803)
NewAPos = OldAPos - OffsetChange
REM Move the knee to the new position
Code "G00 A" & NewAPos
REM Return the the position we were in before the toolchange
x = GetToolChangeStart( 0 )
y = GetToolChangeStart( 1 )
z = GetToolChangeStart( 2 )
a = GetToolChangeStart( 3 )
b = GetToolChangeStart( 4 )
c = GetToolChangeStart( 5 )
if(IsSafeZ() = 1) Then
SafeZ = GetSafeZ
if SafeZ > z then
GotoSafeZ()
end if
Code "G00 X" & x & " Y" & y
Code "G00 Z" & z
else
Code "G00 X" & x & " Y" & y
end if
Regards,
Ray L.