This code version works perfectly, it's one impressive addition to the mill, just increased it's usability 200% I think, she's now got 350mm of Z clearance under code control
Of course, with every new feature there are new ways to mess things up of course -
do not enter a new tool manually in the "Current tool" DRO,
do not jog the knee manually once you have ref'd the Z axis and set the first tool or probe,
always enter the 1st tool/probe manually in the current tool DRO
probably a million other ways to make balls-up
I think a good addition will be to add some code to check that the new knee position is still a negative number as the axis runs out of travel at zero
One thing that did fail is the Index Homing on the knee - keeps throwing "Index not within allowed distance" error which means the index pulse is out of range, will have read the manual on this one.
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
‘***Get the current G90/G91 state
CurrentAbsInc = GetOemLED(48)
‘***Get Axis Scale factors in use
XScale = GetOEMDRO(59)
YScale = GetOEMDRO(60)
ZScale = GetOEMDRO(61)
CScale = GetOEMDRO(64)
‘***Set All Axis Scales to 1
Call SetOEMDRO(59,1)
Call SetOEMDRO(60,1)
Call SetOEMDRO(61,1)
Call SetOEMDRO(64,1)
Sleep(250)
‘***Get old tool length
OldToolLength = roun(GetToolParam(GetCurrentTool, 2))
‘***Set the requested tool to be the current tool
SetCurrentTool(GetSelectedTool())
‘***Get new tool length
NewToolLength = roun(GetToolParam(GetCurrentTool, 2))
‘***Switch to absolute distance mode
Code "G90"
‘***Move Z axis to machine zero - fully retracted for tool change
Code "G53 G0 Z0”
While IsMoving()
Sleep(100)
Wend
'========================================================================================
' Start of Knee Positioning Code
'========================================================================================
‘***Get the knee position in machine coordinates
CurrentKneePosition = roun(GetOEMDRO(88))
‘***Get the respective backlash clearance allowance for downwards knee moves
If GetOEMLED(801) Then ‘***On = English Measure INCH
ClearAllow = 0.125
Else ‘***Off = Metric Measure MM
ClearAllow = 3.0
End If
‘***Calculate the knee machine move value based on tool length difference
If OldToolLength > NewToolLength then ‘***We need to RAISE the knee
Code “G53 G0 C” & (CurrentKneePosition - (OldToolLength - NewToolLength)) + ClearAllow
While IsMoving ()
Sleep(100)
Wend
Code “G53 G1 C” & (CurrentKneePosition - (OldToolLength - NewToolLength)) & “ F100”
While IsMoving ()
Sleep(100)
Wend
End If
‘***If the knee is currently higher than it needs to be, we first
‘***move it down, to ensure the final move is always UP. This ensures
‘***backlash is taken out and provides more consistent positioning.
If OldToolLength < NewToolLength then ‘***We need to LOWER the knee
Code “G53 G0 C” & (CurrentKneePosition + (NewToolLength - OldToolLength)) + ClearAllow
While IsMoving ()
Sleep(100)
Wend
Code “G53 G1 C” & (CurrentKneePosition + (NewToolLength - OldToolLength)) & “ F100”
While IsMoving ()
Sleep(100)
Wend
End If
If OldToolLength = NewToolLength then
‘Message “Knee Will Not Move” ‘***Use this line for debugging
End If
'========================================================================================
' End of Knee Positioning Code
'========================================================================================
‘***If G91 was in effect before then return to it
If CurrentAbsInc = 0 Then
Code "G91"
End If
‘***Put previous Axis Scale factors back
Call SetOEMDRO(59,XScale)
Call SetOEMDRO(60,YScale)
Call SetOEMDRO(61,ZScale)
Call SetOEMDRO(64,CScale)
Sleep(250)
End Sub
I know you are no longer using this code but I think the reason you had issues with the Index Homing was a typo in your code.
The line Code "G53 G0 Z0” contains an incorrect closing double quote.
I ran across this while studying how you are implementing the knee movement.
Great work!!
I should get around to implementing this on my mill later this year.