''========================================================================================
'  Created From: LengthCompEnable.m3m
'  Includes: 
'       ../Common.def
'       ./ToolLengthComp.def
''========================================================================================

''========================================================================================
''	 Included Definitions:
''========================================================================================
MachAAxisOEMDRO = 		803	' A Axis OEM DRO
ToolParam_ZOffset =     2
''========================================================================================

''
'   Bogus G43 Macro
'
'   Usage:
'       M143 P<OffsetNumber>
''

'#filename "M843.m1s"
'#include "Common.def"
'#include "ToolLengthComp.def"

''========================================================================================
''	Start of Macro Code
''========================================================================================

' Get the offset number to use
ToolOffsetNum = Param1()
' Lookup the offset
ToolOffset = GetToolParam(ToolOffsetNum, ToolParam_ZOffset)
' Now see where the knee is now
CurrentPos = GetOEMDRO(MachAAxisOEMDRO)
Message "CurrentPos=" & CurrentPos & " ToolOffset=" & ToolOffset
If (ToolOffset + CurrentPos) > 0 Then
    ' Make sure we always move UP to final position
    Code "G0 A" & (0 - ToolOffset - 0.100)
    ' Macro:     #WaitUntilStopped

    ' Wait until machine is stopped
    While IsMoving ()
        Sleep 10
    Wend
    ' End Macro: #WaitUntilStopped
End If    
' Apply it
Code "G0 A" & 0 - ToolOffset
' Macro: #WaitUntilStopped
' Wait until machine is stopped
While IsMoving ()
    Sleep 10
Wend
' End Macro: #WaitUntilStopped
