' M1004
' SET TOOL SETTER Z OFFSET Macro with workaround concerning G31 limitations on chinese controlers
' Base code written by Big-Tex May 25 2010
' Mod David Marmilloud 03/2025 version 2025-0325.1 to work woith "DarkScreen DPD MM 23 03 27"
' https://www.machsupport.com/forum/index.php?topic=41912.60
InitialFeed = GetOemDRO(818) 'get the Initial feedrate to return to later
InitialAbsInc = GetOemLED(48) 'Get the Initial G90/G91 state
InitialAbsX = GetOEMDRO(83) 'Get the Initial MACHINE X position
InitialAbsY = GetOEMDRO(84) 'Get the Initial MACHINE Y position
InitialAbsZ = GetOEMDRO(85) 'Get the Initial MACHINE Z position
InitialWorkZ = GetOEMDRO(180) 'Get the Initial WORK Z position
Main
Sub Main()
'//////// Unit dependent parameters
If GetOEMLED(801) Then 'if unit is imperial (inches)
FirstProbeFeed = 8 'Approach Probe Feed Speed
SecondProbeFeed = 1 'Slow Probe Feed Speed
ProbeDepth = 10 'probing Depth
Res = 0.001 'set the measurement resolution
Else 'if unit is metric
FirstProbeFeed = 200.0 'Approach Probe Feed Speed
SecondProbeFeed = 30.0 'Slow Probe Feed Speed
ProbeDepth = 190 'Probing Depth
Res = 0.01 'set the measurement resolution
End If
'//////// Error Condition checking code
If GetOEMLED(16) Then 'Checks for machine coordinates
DoOEMButton(256) 'toggle to program coordinates
End If
If GetOEMLED(825)<>0 Then 'check probe first see if it is grounded
Code "(Probe Grounded, check connection and try again)" 'Status Bar display
End 'ERROR! exit the macro
End if
If GetOEMLED(807) or GetOEMLED(808) or GetOEMLED(809) Then 'Check all axes have been referenced
Code "(Ref all axis prior to Zero Z)" 'Status Bar display
End 'ERROR! exit the macro
End If
'//////// Get Tool measurement positions
ToolSensorXPos = GetOEMDRO(1006) 'Get Tool probe X position
ToolSensorYPos = GetOEMDRO(1007) 'Get Tool probe Y position
ToolNumber = GetOEMDRO(824) 'get tool number
'//////// Move to probe position
Code "G90 G0 G53 Z" & getOEMDRO(54) 'Move to Safe Z
Code "G90 G0 G53 X" & ToolSensorXPos & "Y" & ToolSensorYPos 'Move to Tool sensor position
'//////// Probing, first using G31, then refining with iterative method
Code "G4 P1" 'pause 1 seconds to give time to position probe plate
Code "F" & FirstProbeFeed 'First approach feedrate using G31
Code "(Probing)"
Code "G91 G31 Z-" & ProbeDepth 'probe move to probedepth - First travel
While IsMoving() 'wait for probe move to finish
Wend
Code "(1st touch)"
Code "F" & SecondProbeFeed 'set slow feedrate
ProbedZABS = GetZ(Res*10) 'Probing up to Low signal as Low res
ProbedZABS = GetZ(-Res) 'Probing down to High signal at High Res
If ToolNumber <> 0 Then 'if not ref tool
MachMsg("Tool number should be #0" & Chr(13) & Chr(10) & "Please set the ref tool and restart the procedure", "WARNING", 0)
RestoreInit 'restore initial conditions
Exit sub
Else 'if tool is ref tool
Call setOEMDRO(1008, ProbedZABS)'write sensed ABS position to Tool Setter Z offset
Code "G4 P.25" 'pause for Dro to update.
Code "(Ref tool is set ans stored on Settings Screen - Tool Setter coordinates Z)"
End If
RestoreInit 'restore initial conditions
End Sub
Function GetZ(ResStep) As Double
'//////// Start Probing Code, Probe In -Z direction.
'//////// The vars will be Inch or Metric from above if/else statment
PlateOffset = GetOEMDRO(1001) 'get plate offset DRO
InitialContact = GetOEMLED(825) 'get probe contact state
i=0
Code "(Refining contact by " & ResStep & " step)"
While GetOEMLED(825)=InitialContact
'as long as the limit switch is ON
Code "G91 G1 Z" & ResStep 'move one step
While IsMoving() 'wait for probe move to finish
Wend
i = i+1 'count steps
If i=30 Then 'If probe moved more than 20 steps without switching
Code "(Can't reach the sensor. ABORTED)" 'ERROR!
RestoreInit 'restore initial conditions
End 'End the program
End If
Wend 'loop
Code "(Got it)"
Code "G4 P.25" 'pause for Dro to update.
GetZ = GetOEMDRO(85) - PlateOffset 'Return new touch point in Machine coordinates
End Function
Sub RestoreInit()
'////////// restoring initial conditions
'Code "G90 G0 G53 Z" & getOEMDRO(54) 'Move to Safe Z
'Code "G90 G0 G53 X" & InitialAbsX & "Y" & InitialAbsY 'Move to initial position
Code "G90 G0 G53 Z" & InitialAbsZ 'Move to initial Z position - Be carefull before uncomment. if tool is longer than previous, you migth crash
'Code "G90 G0 Z" & InitialWorkZ 'Move to initial work Z position
While IsMoving() 'wait for probe move to finish
Wend
If InitialAbsInc = 0 Then 'if G91 was in effect before then return to it
Code "G91"
Else
Code "G90"
End If
Call SetOEMDRO(818, InitialFeed) 'restore feed rate
End Sub
' M1004
' SET TOOL SETTER Z OFFSET Macro with workaround concerning G31 limitations on chinese controlers
' Base code written by Big-Tex May 25 2010
' Mod David Marmilloud 03/2025 version 2025-0325.1 to work woith "DarkScreen DPD MM 23 03 27"
' https://www.machsupport.com/forum/index.php?topic=41912.60
InitialFeed = GetOemDRO(818) 'get the Initial feedrate to return to later
InitialAbsInc = GetOemLED(48) 'Get the Initial G90/G91 state
InitialAbsX = GetOEMDRO(83) 'Get the Initial MACHINE X position
InitialAbsY = GetOEMDRO(84) 'Get the Initial MACHINE Y position
InitialAbsZ = GetOEMDRO(85) 'Get the Initial MACHINE Z position
InitialWorkZ = GetOEMDRO(180) 'Get the Initial WORK Z position
Main
Sub Main()
'//////// Unit dependent parameters
If GetOEMLED(801) Then 'if unit is imperial (inches)
FirstProbeFeed = 8 'Approach Probe Feed Speed
SecondProbeFeed = 1 'Slow Probe Feed Speed
ProbeDepth = 10 'probing Depth
Res = 0.001 'set the measurement resolution
Else 'if unit is metric
FirstProbeFeed = 200.0 'Approach Probe Feed Speed
SecondProbeFeed = 30.0 'Slow Probe Feed Speed
ProbeDepth = 190 'Probing Depth
Res = 0.01 'set the measurement resolution
End If
'//////// Error Condition checking code
If GetOEMLED(16) Then 'Checks for machine coordinates
DoOEMButton(256) 'toggle to program coordinates
End If
If GetOEMLED(825)<>0 Then 'check probe first see if it is grounded
Code "(Probe Grounded, check connection and try again)" 'Status Bar display
End 'ERROR! exit the macro
End if
If GetOEMLED(807) or GetOEMLED(808) or GetOEMLED(809) Then 'Check all axes have been referenced
Code "(Ref all axis prior to Zero Z)" 'Status Bar display
End 'ERROR! exit the macro
End If
'//////// Get Tool measurement positions
ToolSensorXPos = GetOEMDRO(1006) 'Get Tool probe X position
ToolSensorYPos = GetOEMDRO(1007) 'Get Tool probe Y position
ToolNumber = GetOEMDRO(824) 'get tool number
'//////// Move to probe position
Code "G90 G0 G53 Z" & getOEMDRO(54) 'Move to Safe Z
Code "G90 G0 G53 X" & ToolSensorXPos & "Y" & ToolSensorYPos 'Move to Tool sensor position
'//////// Probing, first using G31, then refining with iterative method
Code "G4 P1" 'pause 1 seconds to give time to position probe plate
Code "F" & FirstProbeFeed 'First approach feedrate using G31
Code "(Probing)"
Code "G91 G31 Z-" & ProbeDepth 'probe move to probedepth - First travel
While IsMoving() 'wait for probe move to finish
Wend
Code "(1st touch)"
Code "F" & SecondProbeFeed 'set slow feedrate
ProbedZABS = GetZ(Res*10) 'Probing up to Low signal as Low res
ProbedZABS = GetZ(-Res) 'Probing down to High signal at High Res
If ToolNumber <> 0 Then 'if not ref tool
MachMsg("Tool number should be #0" & Chr(13) & Chr(10) & "Please set the ref tool and restart the procedure", "WARNING", 0)
RestoreInit 'restore initial conditions
Exit sub
Else 'if tool is ref tool
Call setOEMDRO(1008, ProbedZABS)'write sensed ABS position to Tool Setter Z offset
Code "G4 P.25" 'pause for Dro to update.
Code "(Ref tool is set ans stored on Settings Screen - Tool Setter coordinates Z)"
End If
RestoreInit 'restore initial conditions
End Sub
Function GetZ(ResStep) As Double
'//////// Start Probing Code, Probe In -Z direction.
'//////// The vars will be Inch or Metric from above if/else statment
PlateOffset = GetOEMDRO(1001) 'get plate offset DRO
InitialContact = GetOEMLED(825) 'get probe contact state
i=0
Code "(Refining contact by " & ResStep & " step)"
While GetOEMLED(825)=InitialContact
'as long as the limit switch is ON
Code "G91 G1 Z" & ResStep 'move one step
While IsMoving() 'wait for probe move to finish
Wend
i = i+1 'count steps
If i=30 Then 'If probe moved more than 20 steps without switching
Code "(Can't reach the sensor. ABORTED)" 'ERROR!
RestoreInit 'restore initial conditions
End 'End the program
End If
Wend 'loop
Code "(Got it)"
Code "G4 P.25" 'pause for Dro to update.
GetZ = GetOEMDRO(85) - PlateOffset 'Return new touch point in Machine coordinates
End Function
Sub RestoreInit()
'////////// restoring initial conditions
'Code "G90 G0 G53 Z" & getOEMDRO(54) 'Move to Safe Z
'Code "G90 G0 G53 X" & InitialAbsX & "Y" & InitialAbsY 'Move to initial position
Code "G90 G0 G53 Z" & InitialAbsZ 'Move to initial Z position - Be carefull before uncomment. if tool is longer than previous, you migth crash
'Code "G90 G0 Z" & InitialWorkZ 'Move to initial work Z position
While IsMoving() 'wait for probe move to finish
Wend
If InitialAbsInc = 0 Then 'if G91 was in effect before then return to it
Code "G91"
Else
Code "G90"
End If
Call SetOEMDRO(818, InitialFeed) 'restore feed rate
End Sub