Molto dipende dal tipo di CNC che si usa e dalle funzioni del codice G da essa supportate.
Non ho visto nel post che CNC usa quindi posso parlare solo per RosettaCNC di cui conosco funzionamento e codice ma se può essere di aiuto allego un po' di codice e spiego come si fa con questa CNC.
Per risolvere questa funzionalità abbiamo sviluppato due macro.
La prima è una macro richiamabile da icona su toolbar che fa l'azzeramento Z della WCS attiva con misurazione top pezzo.
La seconda è la macro cambio utensile manuale che si occupa di gestire il cambio utensile compensando il Z la differenza tra un utensile e l'altro.
Questo tipo di funzionalità richiede che l'ingresso digitale di PROBE venga commutato tra un probe (o piazzola) mobile, durante la fase di ricerca di zero sul pezzo, e un tool setter fisso (probe per misurazione lunghezza utensile).
Fase 1 - Acquisizione zero pezzo con un utensile qualsiasi
Si commuta la fonte del segnale PROBE affinchè funzioni il sistema di probe posizionato sul pezzo (potrebbe essere una piazzola di rame come un vero e proprio tastatore).
Si inserisce e fissa la prima punta, o qualsiasi punta non è importante, sul mandrino.
Si attiva la WCS che verrà usata nel programma con un comando MDI: G54...G55...etc.
Si posiziona in JOG gli assi X/Y sul punto di zero e si avvicina lo Z a qualche millimetro dalla piazzola.
Si azzerano le posizioni WCS X ed Y di quel punto tramite i relativi bottoni di zero assi X ed Y.
Si avvia la macro di cattura dello Z.
Macro:
Codice: Seleziona tutto
;
; (c) 2016-2019 by RosettaCNC Motion
;
; Name : update_piece_position.ngc
; Sub UID : 7
; Version : 1
; Description : Place touch probe on the piece. This macro move Z down to touch probe.
; : It calculate current WCS Z position according with sensor height.
; Note : none
;
; Inputs:
; None
; Note : None
;
; User Parameters:
;
; Var Description
; === ===========
; #6100 UPDATE_PIECE_Z_POSITION : Z feed to 1st probe input capture (SLOW)
; #6101 UPDATE_PIECE_Z_POSITION : Z feed to 2nd probe input capture (VERY SLOW)
; #6102 UPDATE_PIECE_Z_POSITION : Z up movement after 1st touch capture (REL)
; #6103 UPDATE_PIECE_Z_POSITION : Sensor Z height
; #6104 UPDATE_PIECE_Z_POSITION : Maximun delta during piece position detection
; #6105 UPDATE_PIECE_Z_POSITION : Select where to place WCS.Z zero (0=at tool end, 1=at spindle nose)
;
O7
; initialize local variabiles
#<_measure1_>=0 ; measured Z position
; check if there are compulsory protected parameters undefined
IF [#6100 EQ #0] THEN G65 P3000 E1 A6100
IF [#6101 EQ #0] THEN G65 P3000 E1 A6101
IF [#6102 EQ #0] THEN G65 P3000 E1 A6102
IF [#6103 EQ #0] THEN G65 P3000 E1 A6103
IF [#6104 EQ #0] THEN G65 P3000 E1 A6104
IF [#6105 EQ #0] THEN G65 P3000 E1 A6105
; store actual PLC states
#<_saved.5001>=#5001 ; current program position X (WCS)
#<_saved.5002>=#5002 ; current program position Y (WCS)
#<_saved.5003>=#5003 ; current program position Z (WCS)
#<_saved.5101>=#5101 ; active G-codes group 01: G0, G1, ...
#<_saved.5130>=#5130 ; active feed rate (F)
#<_saved.5151>=#5151 ; active M-codes: M3, M4, M5
#<_saved.5153>=#5153 ; active M-codes: M7, M9
#<_saved.5154>=#5154 ; active M-codes: M8, M9
; check if last G-codes group 01 used instruction was a G0/G1 otherwise, to prevent
; an error when setting G#<_saved.5101>, set it to G80 (cancel motion mode).
IF [[#<_saved.5101> NE 0] AND [#<_saved.5101> NE 1]] THEN #<_saved.5101>=80
; show main procedure message for 1s
M109 P"Update piece Z position" Q4
G4 P1
; disable spindle, flood & mist
M5 M9
; Calculate the current Z BCS position
; Consider G52 offset and WCS offset depending on current WCS index (#5220).
#<Z_BCS_position> = [#5003 + #5203 + #[5200 + 20 * [#5220] + 3]]
; Add G92 offset if it is enabled.
IF [#5210 GE 1] THEN [#<Z_BCS_position> = [#<Z_BCS_position> + #5213]
; call touch probe procedure
G65 P3001 A[#<Z_BCS_position> - #6104] B#6100 C#6102 D0 E#6101
; Calculate the Z piece position using the probe info #5173, and the
; Sensor Z height.
#<_measure1_> = [#5713 - #6103]
IF [#6105 EQ 1] THEN #<_measure1_> = [#<_measure1_> - #5403]
; Update Z of current WCS
G10 L2 P#5220 Z#<_measure1_>
; Move upwards to the original position.
G53 G0 Z#<Z_BCS_position>
; restore save feed
F#<_saved.5130>
; restore g-code group 01 state
G#<_saved.5101>
; reset HUD message
M109 P"" Q4
M2
; EXIT CHECK MANAGEMENT
;
; Inputs:
;
; Var G65 Description
; === === ===========
; #8 E Exit code
; #1 A Undefined compulsory protected parameter
;
; Exit codes:
;
; 0 NONE
; 1 Error : One or more compulsory protected parameters are undefined!
; 2 Error : Sensor was found already tripped before to start approach movements to probe!
; 3 Error : Sensor was tripped during approach movements to probe!
; 4 Error : Sensor was found already tripped before to start 1st touch movements!
; 5 Error : Sensor was not found during 1st touch movements!
; 6 Error : Sensor was found already tripped before to start 2nd touch movements!
; 7 Error : Sensor was not found during 2nd touch movements!
; ** Error : Unknown error<number>!
;
O3000
; check for error code
IF [#<_args.e> EQ 0] THEN M99
; reset HUD message
M109 P"" Q4
IF [#<_args.e> EQ 1] THEN M109 P"<B>Error</B><BR><BR>Compulsory protected parameter ##<_args.a> is undefined!<BR>" Q1
IF [#<_args.e> EQ 2] THEN M109 P"<B>Error during measure of tool length</B><BR><BR>Sensor was found already tripped before to start approach movements to probe!</B><BR>" Q1
IF [#<_args.e> EQ 3] THEN M109 P"<B>Error during measure of tool length</B><BR><BR>Sensor was tripped during approach movements to probe!</B><BR>" Q1
IF [#<_args.e> EQ 4] THEN M109 P"<B>Error during measure of tool length</B><BR><BR>Sensor was found already tripped before to start 1st touch movements!</B><BR>" Q1
IF [#<_args.e> EQ 5] THEN M109 P"<B>Error during measure of tool length</B><BR><BR>Sensor was not found during 1st touch movements!</B><BR>" Q1
IF [#<_args.e> EQ 6] THEN M109 P"<B>Error during measure of tool length</B><BR><BR>Sensor was found already tripped before to start 2nd touch movements!</B><BR>" Q1
IF [#<_args.e> EQ 7] THEN M109 P"<B>Error during measure of tool length</B><BR><BR>Sensor was not found during 2nd touch movements!</B><BR>" Q1
M109 P"<B>Generic Error<BR><BR>Unknown error #<_args.e>!</B>" Q1
M99
; TOUCH PROBE
;
; Inputs:
;
; Var G65 Description
; === === ===========
; #A : Sensor top/center position Z (MCS)
; #B : Z feed to 1st probe input capture (SLOW)
; #C : Z up movement after 1st touch capture (REL)
; #D : Minimum tool lenght accepted
; #E : Z feed to 2nd probe input capture (VERY SLOW)
O3001
; measure of tool : 1st touch
M109 P"Approach movements to probe : 1st touch..." Q4
G53 G38.3 Z#<_args.a> F#<_args.b>
; check if sensor was found already tripped before to start 1st touch movements
IF [#5700 EQ -2] THEN G65 P3000 E4
; check if sensor was not found during 1st touch movements
IF [#5700 NE 1] THEN G65 P3000 E5
; measure of tool : 2nd touch
M109 P"Approach movements to probe : 2nd touch..." Q4
G53 G0 Z[#5713+#<_args.c>]
G53 G38.3 Z[#<_args.a>+#<_args.d>] F#<_args.e>
; check if sensor was found already tripped before to start 2nd touch movements
IF [#5700 EQ -2] THEN G65 P3000 E6
; check if sensor was not found during 2nd touch movements
IF [#5700 NE 1] THEN G65 P3000 E7
M99
Questa macro scende, tocca il probe, si rialza di una distanza programmata fino allo sgancio, ridiscende a velocità lenta, calcola la posizione macchina del tocco e la scrive nella WCS.Z della WCS attiva.
Fase 2 - Lavorazione
Si commuta la fonte del segnale PROBE affinchè funzioni il sistema di probe in posizione fissa per la misurazione lunghezza utensili (Tool Setter).
Si da Start al programma di lavorazione.
In testa al programma ci deve essere la definizione del primo utensile in uso ad esempio T1 M6.
La macro cambio utensile si alza, va nella posizione definita del tool setter e rileva la prima misura.
Si rialza, va nella posizione di cambio utensile manuale e compare una finestra che descrive numero e caratteristiche dell'utensile da inserire.
Se l'utensile caricato è già quello giusto basta dare conferma di riprendere la lavorazione.
Se l'utensile caricato è diverso, lo si cambia, e si da conferma di riprendere la lavorazione.
La CNC si riposiziona sul punto di misura lunghezza e del tool setter.
Rimisura la lunghezza, con doppia misurazione, e calcola la differenza lunghezza che attiva come compensazione lunghezza utensile dinamica (G43.1) quindi senza dover far uso della lunghezza pre-impostata nella libreria utensili.
La CNC inizia la lavorazione.
Quando incontra un nuovo utensile, ad esempio T5 M6 ripete le operazioni di misura, cambio, misura e torna a lavorare con il secondo utensile.
Continua cosi finchè non finisce il programma.
Macro:
Codice: Seleziona tutto
;
; (c) 2016-2019 by RosettaCNC Motion
;
; Name : tool_change.ngc
; Sub UID : 6
; Version : 1
; Description : Tool change with 2 touches tool length probing system.
; Note : This change tool requires that, after a T<n> M6, the post processor
; : adds a G0 back movement to working X/Y, then move to safe Z and
; : then move to working Z with a G1. Better if set also F value in G1, eg:
; :
; ; T1 M6 ; change tool 1 request
; ; G0 X12 Y34 ; back to working X/Y positions
; ; Z30 ; down to safe Z height
; ; G1 Z-10 F3000 ; down to working Z height with working feed
; ; ....
;
; Inputs:
;
; Var G65 Description
; === === ===========
; #1 A tool id of the tool to be loaded (corresponds to #5132)
; #2 B slot of the tool to be loaded (corresponds to #5133)
; #3 C tool id of the tool in use (corresponds to #5134)
; #4 I slot of the tool in use (corresponds to #5135)
;
;
; User Parameters:
;
; Var Description
; === ===========
; #6000 TOOL_CHANGE : Tool change type:
; 0 = Tool change manual with 2 touches tool length probing system
; 1 = Tool change manual with preloaded tool length in tool library
; #6001 TOOL_CHANGE : Tool change features:
; 0 = Disable back to work position
; 1 = Enable back to work position
; #6002 TOOL_CHANGE : Tool change position X (MCS)
; #6003 TOOL_CHANGE : Tool change position Y (MCS)
; #6004 TOOL_CHANGE : Tool change position Z (MCS)
; #6005 TOOL_CHANGE : Sensor safe position Z (MCS)
; #6006 TOOL_CHANGE : Sensor top/center position X (MCS)
; #6007 TOOL_CHANGE : Sensor top/center position Y (MCS)
; #6008 TOOL_CHANGE : Sensor top/center position Z (MCS)
; #6009 TOOL_CHANGE : Feed during tool change procedure
; #6010 TOOL_CHANGE : Z approaching sensor position (MCS, reached with FAST feed #6011)
; #6011 TOOL_CHANGE : Z feed to sensor approaching (FAST)
; #6012 TOOL_CHANGE : Z feed to 1st probe input capture (SLOW)
; #6013 TOOL_CHANGE : Z feed to 2nd probe input capture (VERY SLOW)
; #6014 TOOL_CHANGE : Z up movement after 1st touch capture (REL)
; #6015 TOOL_CHANGE : Minimum tool lenght accepted
; #6016 TOOL_CHANGE : Enable tool length compensation (only for Tool change type 1)
; #6017..#6050 ; Reserved for future use !!!
;
O6
; notice start change procedure to PLC
M107
; check if there are compulsory protected parameters undefined
IF [#6001 EQ #0] THEN G65 P3000 E1 A6001
IF [#6002 EQ #0] THEN G65 P3000 E1 A6002
IF [#6003 EQ #0] THEN G65 P3000 E1 A6003
IF [#6004 EQ #0] THEN G65 P3000 E1 A6004
IF [#6005 EQ #0] THEN G65 P3000 E1 A6005
IF [#6006 EQ #0] THEN G65 P3000 E1 A6006
IF [#6007 EQ #0] THEN G65 P3000 E1 A6007
IF [#6008 EQ #0] THEN G65 P3000 E1 A6008
IF [#6009 EQ #0] THEN G65 P3000 E1 A6009
IF [#6010 EQ #0] THEN G65 P3000 E1 A6010
IF [#6011 EQ #0] THEN G65 P3000 E1 A6011
IF [#6012 EQ #0] THEN G65 P3000 E1 A6012
IF [#6013 EQ #0] THEN G65 P3000 E1 A6013
IF [#6014 EQ #0] THEN G65 P3000 E1 A6014
IF [#6015 EQ #0] THEN G65 P3000 E1 A6015
IF [#6016 EQ #0] THEN G65 P3000 E1 A6015
; store actual PLC states
#<_saved.5001>=#5001 ; current program position X (WCS)
#<_saved.5002>=#5002 ; current program position Y (WCS)
#<_saved.5003>=#5003 ; current program position Z (WCS)
#<_saved.5101>=#5101 ; active G-codes group 01: G0, G1, ...
#<_saved.5130>=#5130 ; active feed rate (F)
#<_saved.5151>=#5151 ; active M-codes: M3, M4, M5
#<_saved.5153>=#5153 ; active M-codes: M7, M9
#<_saved.5154>=#5154 ; active M-codes: M8, M9
; check if last G-codes group 01 used instruction was a G0/G1 otherwise, to prevent
; an error when setting G#<_saved.5101>, set it to G80 (cancel motion mode).
IF [[#<_saved.5101> NE 0] AND [#<_saved.5101> NE 1]] THEN #<_saved.5101>=80
; show main procedure message for 1s
M109 P"Tool change procedure" Q4
G4 P1
; disable spindle, flood & mist
M5 M9
; check if Tool change type = 0 the execute sub 3002
IF [#6000 EQ 0] THEN G65 P3002
; check if Tool change type = 0 the execute sub 3003
IF [#6000 EQ 1] THEN G65 P3003
; move back to saved work position X/Y (keeping Z to sensor safe position Z)
IF [#6001 EQ 1] THEN G1 X#<_saved.5001> Y#<_saved.5002>
; move back to saved work position Z
IF [#6001 EQ 1] THEN G1 Z#<_saved.5003>
; restore spindle & coolants states
IF [#<_saved.5151> EQ 3] THEN M3
IF [#<_saved.5151> EQ 4] THEN M4
IF [#<_saved.5153> EQ 7] THEN M7
IF [#<_saved.5154> EQ 8] THEN M8
; restore save feed
F#<_saved.5130>
; restore g-code group 01 state
G#<_saved.5101>
; reset HUD message
M109 P"" Q4
; notice end change procedure to PLC
M108
M99
; EXIT CHECK MANAGEMENT
;
; Inputs:
;
; Var G65 Description
; === === ===========
; #8 E Exit code
; #1 A Undefined compulsory protected parameter
;
; Exit codes:
;
; 0 NONE
; 1 Error : One or more compulsory protected parameters are undefined!
; 2 Error : Sensor was found already tripped before to start approach movements to probe!
; 3 Error : Sensor was tripped during approach movements to probe!
; 4 Error : Sensor was found already tripped before to start 1st touch movements!
; 5 Error : Sensor was not found during 1st touch movements!
; 6 Error : Sensor was found already tripped before to start 2nd touch movements!
; 7 Error : Sensor was not found during 2nd touch movements!
; ** Error : Unknown error<number>!
;
O3000
; check for error code
IF [#<_args.e> EQ 0] THEN M99
; reset HUD message
M109 P"" Q4
; notice end change procedure to PLC
M108
IF [#<_args.e> EQ 1] THEN M109 P"<B>Error</B><BR><BR>Compulsory protected parameter ##<_args.a> is undefined!<BR>" Q1
IF [#<_args.e> EQ 2] THEN M109 P"<B>Error during measure of tool length</B><BR><BR>Sensor was found already tripped before to start approach movements to probe!</B><BR>" Q1
IF [#<_args.e> EQ 3] THEN M109 P"<B>Error during measure of tool length</B><BR><BR>Sensor was tripped during approach movements to probe!</B><BR>" Q1
IF [#<_args.e> EQ 4] THEN M109 P"<B>Error during measure of tool length</B><BR><BR>Sensor was found already tripped before to start 1st touch movements!</B><BR>" Q1
IF [#<_args.e> EQ 5] THEN M109 P"<B>Error during measure of tool length</B><BR><BR>Sensor was not found during 1st touch movements!</B><BR>" Q1
IF [#<_args.e> EQ 6] THEN M109 P"<B>Error during measure of tool length</B><BR><BR>Sensor was found already tripped before to start 2nd touch movements!</B><BR>" Q1
IF [#<_args.e> EQ 7] THEN M109 P"<B>Error during measure of tool length</B><BR><BR>Sensor was not found during 2nd touch movements!</B><BR>" Q1
M109 P"<B>Generic Error<BR><BR>Unknown error #<_args.e>!</B>" Q1
M99
; TOUCH PROBE
;
; Inputs:
;
; Var G65 Description
; === === ===========
; #A : Sensor top/center position Z (MCS)
; #B : Z feed to 1st probe input capture (SLOW)
; #C : Z up movement after 1st touch capture (REL)
; #D : Minimum tool lenght accepted
; #E : Z feed to 2nd probe input capture (VERY SLOW)
O3001
; measure of tool : 1st touch
M109 P"Approach movements to probe : 1st touch..." Q4
G53 G38.3 Z#<_args.a> F#<_args.b>
; check if sensor was found already tripped before to start 1st touch movements
IF [#5700 EQ -2] THEN G65 P3000 E4
; check if sensor was not found during 1st touch movements
IF [#5700 NE 1] THEN G65 P3000 E5
; measure of tool : 2nd touch
M109 P"Approach movements to probe : 2nd touch..." Q4
G53 G0 Z[#5713+#<_args.c>]
G53 G38.3 Z[#<_args.a>+#<_args.d>] F#<_args.e>
; check if sensor was found already tripped before to start 2nd touch movements
IF [#5700 EQ -2] THEN G65 P3000 E6
; check if sensor was not found during 2nd touch movements
IF [#5700 NE 1] THEN G65 P3000 E7
M99
; Tool change type 0 sequence
;
O3002
; initialize local variabiles
#<_measure1_>=0 ; measured tool offset Z
; measure of tool to unload : approaching to probe
M109 P"Measure of tool to unload : approacing to probe..." Q4
G53 G1 Z#6005 F#6009
G53 G1 X#6006 Y#6007
G53 G38.3 Z#6010 X#6006 Y#6007 F#6011
; check if sensor was found already tripped before to start approach movements to probe
IF [#5700 EQ -2] THEN G65 P3000 E2
; check if sensor was tripped during approach movements to probe
IF [#5700 EQ 1] THEN G65 P3000 E3
; call touch probe procedure
G65 P3001 A#6008 B#6012 C#6014 D#6015 E#6013
; calculate the tool length offset as the difference between when the sensor was tripped and the sensor Z position.
#<_measure1_> = [#5713 - #6008]
; move to sensor safe position Z
G53 G1 Z#6005 F#6009
; move to tool change position
G53 G1 Z#6004 F#6009
G53 G1 X#6002 Y#6003
; A different tool should be inserted. Display the message to the user.
M109 P"<BR>Insert tool <B>T#5132</B><BR><@TI=#5132><BR>" Q2
G4 P1
; notice to PLC the loaded tool ID
M61 Q#5132
; measure of loaded tool : approaching to probe
M109 P"Measure of loaded tool : approacing to probe..." Q4
G53 G1 Z#6005 F#6009
G53 G1 X#6006 Y#6007
G53 G38.3 Z#6010 X#6006 Y#6007 F#6011
; check if sensor was found already tripped before to start approach movements to probe
IF [#5700 EQ -2] THEN G65 P3000 E2
; check if sensor was tripped during approach movements to probe
IF [#5700 EQ 1] THEN G65 P3000 E3
; call touch probe procedure
G65 P3001 A#6008 B#6012 C#6014 D#6015 E#6013
; calculate the tool length offset as the difference between when the sensor was tripped and the sensor Z position.
#<_measure2_> = [#5713 - #6008]
; move to sensor safe position Z
G53 G1 Z#6005 F#6009
; calc compensation to do
#<_toll_length_difference_>=[#<_measure2_>-#<_measure1_>+#5422]
; enable tool length compensation
G43.1 Z#<_toll_length_difference_>
M99
;
; Tool change type 1 sequence
O3003
; Check if a different tool should be inserted.
IF [#5132 NE #5134] THEN10
; move to tool change position
G53 G1 Z#6004 F#6009
G53 G1 X#6002 Y#6003
; A different tool should be inserted. Display the message to the user.
M109 P"<BR>Insert tool <B>T#5132</B><BR><@TI=#5132><BR>" Q2
G4 P1
; notice to PLC the loaded tool ID
M61 Q#5132
; enable tool length compensation if enabled
IF [#6016 EQ 1] THEN G43 H#5132
END10
M99
Questo è il massimo che posso fare per aiutarla.
Dovrà vedere se con la sua CNC ha un linguaggio abbastanza simile e può portare il concetto espresso in queste due macro.