ik ben voor het eerst begonnen aan het maken van een subroutine. Ik heb sinds kort een toolsetter op mijn machine gemonteerd en zou nu heel graag een macro maken waarbij bij elke toolchange in een freesprogramma de lengte van het nieuwe gereedschap automatisch gemeten en gecorrigeerd wordt. Om dit voor elkaar te krijgen probeer ik de bestaande sub tool_change samen te voegen met met de sub m_tool. Het idee is als volgt:
1. Start machine, home machine
2. Span gereedschap op
3. Meet gereedschap in met sub m-tool
4. zero x, y en z op werkstuk 0
5. Start programma
Bij elke toolchange in het programma wil ik dat de sub m-tool gestart wordt om zo het nieuwe gereedschap in te meten waarna de lengte van de frees gecorrigeerd wordt. Hierdoor zou je dan alleen de eerste frees moeten nullen op je werkstuk. Ik wissel de frezen met de hand (lengte offset niet herhaalbaar).
Ik heb de sub m_tool aangepast aan het einde zodat de ingemeten frees ook de actieve frees wordt in het programma en dat toollength offset aanstaat:
Code: Selecteer alles
sub m_tool
if [[#5380==0] and [#5397==0]] ;do this only when not simulating and not rendering
;Check if toolsetter is calibrated
if [[#4996 == 0] and [#4997 == 0] and [#4998 == 0] and [#4999 == 0]]
errmsg "calibrate first, MDI: gosub calibrate_tool_setter"
else
g0 g53 z#4996 ; move to safe z
dlgmsg "enter tool dimensions" "tool number" 5016 "approx tool length" 5017 "tool diameter" 5018
;Check user pressed OK
if [#5398 == 1]
if [[#5016 < 1] OR [#5016 > 99]]
ErrMsg "Tool must be in range of 0 .. 99"
endif
;move to toolsetter coordinates
g00 g53 x#4997 y#4998
;move to 10mm above chuck height + approx tool length + 10
g00 g53 z[#4999+6+#5017]
;measure tool length and pull 5mm back up
g38.2 g91 z-20 f60
g90
;back to safe height
g0 g53 z#4996
;Store tool length, diameter in tool table
;but only if actually measured,
;so leave tool table as is while rendering
if [#5397 == 0]
#[5400 + #5016] = [#5053-#4999]
#[5500 + #5016] = #5018
#[5600 + #5016] = 0 ;Tool X offset is 0
msg "tool length measured="#[5400 + #5016]" stored at tool "#5016
#5011 = #5016
m6 T[#5011] ;new tool during tool change
endif
endif
endif
endif
endsub
Mijn sub change_tool ziet er nu zo uit:
Code: Selecteer alles
sub change_tool
;Use #5015 to indicate succesfull toolchange
#5015 = 0 ; Tool change not performed
; Als new tool during toolchange niet hetzelfde is als actual tool
If [ [#5011] <> [#5008] ]
;Meet nieuwe frees in
if [[#5380==0] and [#5397==0]] ;do this only when not simulating and not rendering
;Check if toolsetter is calibrated
if [[#4996 == 0] and [#4997 == 0] and [#4998 == 0] and [#4999 == 0]]
errmsg "calibrate first, MDI: gosub calibrate_tool_setter"
;end program
m30
else
g0 g53 z#4996 ; move to safe z
dlgmsg "enter tool dimensions" "tool number" 5016 "approx tool length" 5017 "tool diameter" 5018
;Check user pressed OK
if [#5398 == 1]
;move to toolsetter coordinates
g00 g53 x#4997 y#4998
;move to 10mm above chuck height + approx tool length + 10
g00 g53 z[#4999+10+#5017]
;measure tool length and pull 5mm back up
g38.2 g91 z-20 f30
;absolute distance mode
g90
;back to safe height ;motion in machine coordinate system
g0 g53 z#4996
;Store tool length, diameter in tool table
;but only if actually measured,
;so leave tool table as is while rendering
if [#5397 == 0]
#[5400 + #5016] = [#5053-#4999]
#[5500 + #5016] = #5018
#[5600 + #5016] = 0 ;Tool X offset is 0
msg "tool length measured="#[5400 + #5016]" stored at tool "#5016
#5015 = 1 ;indicate tool change performed
endif
endif
endif
endif
else
msg "Tool already in spindle"
#5015 = 0 ;indicate tool change not performed
endif
If [[#5015] == 1] ;if tool change performed
;msg Tool "actual tool" replaced by tool "new tool during tool change"
msg "Tool "#5008" Replaced by tool "#5011""
m6 T[#5011] ;new tool during tool change
else msg "tool "#5011" allready in spindle"
endif
;switch tool lengthe offset on
G43
EndSub
Ik heb automatic tool change in de setup aangevinkt. Ik begrijp uit de handleiding dat bij een t#m6 (is t#m6 hetzelfde als m6t#?) in het programma de sub change_tool automatisch oproept. Wat ik nu alleen niet snap is dat als ik een t#m6 in mijn programma tegenkom de sub change_tool niet geladen wordt. Zodra ik t#m6 tegenkom springt eding er overheen en vervolgt het programma zonder dat ik een frees heb kunnen wisselen of een dialoog in kan vullen. Wat zie ik hier over het hoofd? Alvast bedankt.