Alternative à la mesure d'outil G31

manivelle-ebenisterie

Nouveau
Cher tous,

Ce post fait suite à celui ci https://www.usinages.com/threads/au...pour-zero-et-offset-en-z.175823/#post-2224598 ou j'avais cru bon, à tord, de regrouper plusieurs fonctions dans une seule macro.

Ici le cœur du sujet est de contourner les limitations du G31 avec des contrôleurs chinois, dans mon cas, le WixHC MKX-ET . (https://www.wixhc.com/en/pc/243.html)
En effet, la variable 2002 est écrite de manière complètement incompréhensible et inexploitable.
J'ai aussi eu des problèmes de vitesse d'avance non respectée avec le G31 (impossible de descendre en dessous de 100mm/min estimés), mais pour une raison inexpliquée... je n'arrive plus à reproduire ce problème !!!

Ma solution consiste à effectuer une mesure itérative en pas à pas. Autrement dit :
  1. Descendre en vitesse moyenne jusqu'au contact à l'aide d'un G31
  2. Remonter pas à pas d'une certaine valeur (10x la résolution finale), en vitesse lente, jusqu'à perdre le contact.
  3. Descendre, pas à pas d'un valeur égale à la résolution souhaitée (ici 0,01 mm) jusqu'à détecter à nouveau le contact.
Ça s'avère redoutablement répétable.

J'ai programmé les macros avec des sub et des fonctions afin de gérer proprement les interruptions. J'ai intégré la comptabilité aux systèmes métrique et imperial
L'ensemble à été programmé pour être utilisé avec le ScreenSet DarkScreen dans sa dernière version, améliorée par Dotymen que j'ai du un peu adapter à mes besoins.

Sur les conseils de @Jipé11 j'ai organisé le process en 3 macros que vous trouverez ci après:
  1. Palage du Zero Travail (Work Zero) - macro M1002
  2. Changement d'outil aux coordonnées spécifiées dans l'interface, puis définition de l'offest Z aux coordonnées de palpage définies elles aussi dans l'interface - macro M1003
  3. Palpage de l'outil de référence (nez de broche) et stockage dans une DRO personnalisée - macro M1004
 

Fichiers joints

Voici donc le code de la macro de palpage du zéro travail

' SET JOB Z ZERO 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()

InitialFeed = GetOemDRO(818) 'get the Initial feedrate to return to later
InitialAbsInc = GetOemLED(48) 'Get the Initial G90/G91 state
InitialAbsZ = GetOEMDRO(85) 'Get the Initial Z position

'//////// 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 = 2 '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 = 50 '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

'//////// 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


Call SetOEMDRO (802, GetOEMDRO(85) - ProbedZABS)'Job Z zero = Current MachineABS position - MachineABS probed point)
Code "G4 P.25" 'pause for Dro to update.
Code"(Z axis is zeroed for this job)"

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(1161) '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 get a signal - probing abroted)" 'ERROR!
RestoreInit 'Restore initial conditions
End 'Exit the macro
End If
Wend 'loop

Code "(Got it)"
Code "G4 P.25" 'pause for Dro to update.
GetZ = GetOEMDRO(85) - PlateOffset 'store 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
 
Dernière édition:
La seconde macro qui permet le changement d'outil, ainsi que si l'outil 0 est actif de palper l'outil de référence

' TOOL CHANGE 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 change, and Tool measurement positions
ToolLoadXPos = GetOEMDRO(1150) 'Get tool load X position
ToolLoadYPos = GetOEMDRO(1151) 'Get tool load Y position
ToolLoadZPos = GetOEMDRO(1152) 'Get tool load Z position

ToolSensorXPos = GetOEMDRO(1006) 'Get Tool probe X position
ToolSensorYPos = GetOEMDRO(1007) 'Get Tool probe Y position

RefToolZOffset = GetOEMDRO(1008) 'Get Z offset, corresponding to REF tool Z position

'//////// Move to tool position
Code "G90 G0 G53 Z" & getOEMDRO(54) 'Move to Safe Z
Code "G90 G0 G53 X" & ToolLoadXPos & "Y" & ToolLoadYPos 'Move to Tool load position
Code "G90 G0 G53 Z" & ToolLoadZPos 'Move to Z load position
While IsMoving() 'wait for move to finish
Wend

ToolNumber = GetOEMDRO(824) 'get tool number

MachMsg("Change the tool to #" & ToolNumber & Chr(13) & Chr(10) & "Press OK when done", "MANUAL TOOL CHANGE", 0)

'//////// 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
Tool_Offset = ProbedZABS - RefToolZOffset 'Offset = This tool sensed position - Ref tool sensed positon
Call setOEMDRO(42, Tool_Offset) 'write it to current tool offset DRO
Code "G4 P.25" 'pause for Dro to update.
Code "(Tool #" & Tool_Num & " Offset is now set to" & ToolOffset &")"
Else 'if tool is ref tool
Ret = MachMsg("Ref Tool is active" & Chr(13) & Chr(10) & "Press OK to set Spindle Z offset," & Chr(13) & Chr(10) & "otherwise press CANCEL to abort", "WARNING", 1)
If Ret = 1 Then 'If answered OK
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)"
Else 'if answerd CANCEL
Code "(Set up canceled)"
RestoreInit
End If
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 get a signal - probing abroted)" 'ERROR!
RestoreInit 'restore initial conditions
End 'Exit the macro
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
 
Dernière édition:
Et enfin celle qui permet de seulement palper l'outil de référence - idéalement le nez de broche.

' 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 get a signal - probing abroted)" 'ERROR!
RestoreInit 'restore initial conditions
End 'Exit the macro
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
 
Dernière édition:
Question : tu utilises une plaque de contact ou un capteur NO pour la procédure de sondage ?
 
Un capteur NO,

mais je pense aussi utiliser une plaque de contact (celle qui etait livrée initialement avec la machine) pour le palpage sur le brut.

Les deux sont déjà câblés en parallèle sur la même entrée.

J'en profite pour relever 1 premier bug : lorsque je quitte la fonction GetZ sur l'erreur, la sub principale se poursuit et le message "tout va bien" sera ffiché.
 
L'utilisation de deux capteurs t'oblige à saisir sa hauteur à chaque mesure ; c'est une perte de temps.
L'utilisation d'un capteur unique (type NO), dont la hauteur est mémorisée, permet d'utiliser une vitesse d'approche plus grande puisque la course morte après déclenchement est d'environ 0.3 à 0.4 mm (pas de risque de poinçonnage du "touch plate".
Dans le cas d'utilisation de ce type de capteur la procédure est la suivante :
* approche rapide (G1) 100 à 150 mm/mn
* retrait rapide (G0) sur 0.8 à 1 mm
* mesure (G1) à 10mm/mn
Si on recherche l'OP, la procédure est complétée par : G10 L20 P(espace de travail) Z(hauteur du contact)

En une seule manip tu détermines ton Z0. Si tu utilises une sonde type 3D, tu mets tes 3 axes à 0 en une seule fois.
JP
 
Dans mon cas, je n'aurais pas à réécrire la valeur du capteur : J'ai deux champs distincts dans le screenset (DRO 1001 pour le capteur fixe et DRO 1161 pour le palpage de pièce). D'ailleurs je me fais la réflexion qu'on doit pouvoir négliger la hauteur du capteur fixe puisqu'il n'est sensé qu'effectuer une mesure comparative.

J'ai lu dans le manuel, p.152, que MACH3 est capable d'interpréter le G10 mais je n'ai pas encore tout bien compris.
C'est vrai que mon code est ici essentiellement basé sur le VB et les DRO - Les variables de mach3 - et pas sur le G-code.
Je m'y pencherai lorsque j'aurais à nouveau un peu de temps à y consacrer, parce que là j'ai un système fonctionnel, et il est grand temps de faire du copeau.

En passant, j'ai résolu le petit bug de sortie de sub en remplaçant "Exit Sub" par "End". Les messages précédents ont été édités dans ce sens. Le fichier zip n'a pas été mis à jour.

Merci pour tes précieux conseils qui m'ont poussé (et devrait encore le faire à l'avenir) à nettement améliorer mon code.
 
Dernière édition:

Sujets similaires

M
Réponses
13
Affichages
450
Jipé11
J
PL50
Réponses
14
Affichages
2 740
Squal112
Squal112
PL50
Réponses
25
Affichages
1 450
dh42
misty soul
Réponses
8
Affichages
1 405
misty soul
misty soul
K
Réponses
7
Affichages
6 970
MARECHE
M
L
Réponses
6
Affichages
1 896
L
X
Réponses
32
Affichages
13 892
XIIIVSI
X
misty soul
Réponses
7
Affichages
2 992
rabotnuc
R

Sujets similaires

ah26
Réponses
1
Affichages
298
pinou29
pinou29
J
Réponses
28
Affichages
613
J
P
Réponses
21
Affichages
883
P
E
Réponses
13
Affichages
2 256
E
Retour
Haut