571
General Mach Discussion / Re: M6 Macro tweaking
« on: January 27, 2018, 03:16:49 AM »
Just as an update, here is my M6 code presently....
Code: [Select]
Sub Main()
If GetSelectedTool() = GetCurrentTool() Then Exit Sub '***Do nothing if current tool is called again
If GetOEMLED(1866) Then Exit Sub '***Ignore M6 calls LED
Tool = GetSelectedTool()'***Set the requested tool to be the current tool
SetCurrentTool(Tool)
Code "G53 G0 Z0" '***Move Z axis to machine zero - fully retracted for tool change
While IsMoving()
Sleep(100)
Wend
'***Get the respective backlash clearance allowance for knee moves
If GetOEMLED(801) Then '***On = English Measure INCH
ClearAllow = 0.125
Else '***Off = Metric Measure MM
ClearAllow = 3.0
End If
'***Lookup the offset in the tool table, T100 is our 3d Haimer Probe
ToolOffset = GetToolParam(GetCurrentTool(), 2)
ProbeOffset = GetToolParam(100, 2)
OffSetDifference = ProbeOffset-ToolOffset'***Calculate the difference between the probe and the new tool - can be negative or positive
'***Calculate the new knee machine coordinate value based on tool length difference
'KneeRefPosition = GetUserDRO(1012) '***Get the knee ref position - set when pressing "Z Zero" at probing stage, this is a hidden DRO
KneeRefPosition = GetVar(179) '***Get the knee ref position - #var is set when pressing "Z Zero" at probing stage
TargetKneePosition = KneeRefPosition - OffsetDifference
'***Check if knee axis has enough travel to make the move - C position is always negative
If TargetKneePosition + ClearAllow >0 Then
Response=MsgBox("Not Enough Travel On Knee Axis - Move Aborted!", 48, "Axis Travel Error")
Exit Sub
End If
'***Rapid to a position lower than needed
Code "G53 G0 C" & (TargetKneePosition + ClearAllow)
While IsMoving()
Sleep(100)
Wend
'***Now move the knee UP slowly to its final position
Code "G53 G1 C" & TargetKneePosition & " F100"
While IsMoving()
Sleep(100)
Wend
End Sub