I would actually like it if people could pick my macros and vb to shreds as I have only really been learning a few months and cut and paste most things untill it works.... Slowly I am working out what each function is for but having many minds on a task tends to make a stronger product!
My code so far seems to work as expected apart from a few points:
Tnumber = getselectedtool() ' gets current tool
this line only returns the value of zero so I am wondering if i am using it right...
I also am using this line to make the offset changes
code "G10 L1 P" &Tnumber & "Z" &ZProbePos ' failing at the moment but maybe due to the zero for the tool number
Code "(Tool offset set)" ' Success! But is it possible to but the actual offset set in this box?
One of the last lines of code is a very basic call to the give a message, could this be set to display the actually offset applied? If so could you give me some pointers to how to do this?
Once this is working I would like to add a call in the start-up to remember the start point so I can return the tool to that point once this macro is done.
Many thanks and hope that once we get the last bugs sorted this code will be useful to others!
-----------------------------------------------------------------------------------------------------
' on top of the X-Y plane at the Z zero position. Cutting tool acts as a probe.
' Operation steps:
' 1. Get current state (Feedrate, G90/G91, G0/G1, Plate Thickness, and Starting Point)
' 2. Check if probe is grounded. Restore state and exit if it is.
' 3. Check if spindle is running. Give option to abort if it is
' 5. Move probe down at a rate of "ProbeFeed" until "ProbeDist" is reached, set Z-DRO and retract the distance set in "Retract"
' If "ProbeDist" is reached before the probe is contacted, the state is restored and the Z-DRO is left unset
' Last updated: 6/12/12
' Author: Christopher Esser (Smokingman). Based on the work done by Greolt
' modded by jestah 6th dec 2012
' Define fixed parameters (Currently in Metric )
Tnumber = getselectedtool() ' getts current tool
ProbeDist = "-200" 'Set the maximum distance to move the Z-axis before probe touches contact plate.
ProbeFeed = "1000" 'Set the first plunge speed for the probe
ProbeFeed2 = "30" 'Set the second plunge speed for the probe
VerifyTimeout = "10" 'Set timeout to wait for probe verify in seconds
Retract = "0.5" 'Set distance to retract after probe (incremental move away from touch plate)
Retract2 = "0" 'Set distance to retract after probe ( in mech. coor.)
Xprobpos = "100" 'Centre of tool sensor X in mech coor
Yprobpos = "100" 'Centre of tool sensor Y in mech coor
' Declare Global Variables
Dim CurrentFeed
Dim CurrentAbsInc
Dim CurrentGmode
Dim PlateThickness
Dim StartingPoint
' Begin the Program
Call GetState
Call doProbe
Call RestoreState
' Get the Starting states
Sub GetState()
CurrentFeed = GetOemDRO(818) ' Get the current feedrate to return to later
CurrentAbsInc = GetOemLED(48) ' Get the current G90/G91 state (Abs Coordinate Mode)
CurrentGmode = GetOemDRO(819) ' Get the current G0/G1 state
PlateThickness = GetUserDRO(1151) ' Read contact plate thickness DRO
StartingPoint = GetOemDRO(85) - GetOemDRO(832) ' Get starting Z position in work coordinates (Z Machine Coord DRO - Z Fixture Orig Off DRO)
End Sub
' Restore the states
Sub RestoreState()
Code "F" &CurrentFeed ' Returns to prior feed rate
If CurrentAbsInc = 0 Then Code "G91" ' If G91 was in effect before then return to it
If CurrentGMode = 0 Then Code "G0" ' If G0 was in effect before then return to it
End Sub
' Probe routine
Sub doProbe()
' Check to see if the probe is already grounded or faulty
If isActive(DIGITIZE) Then
MsgBox "Ground fault in probe detected. Fix probe and try again. "
Exit Sub
End If
' Check to see if the spindle is running
If GetOemLED(11) Then
Begin Dialog SindleOn 16,32,180,96,"Spindle Running!"
OKButton 132,8,40,14
CancelButton 132,28,40,14
Text 12,8,120,40,"It appears the spindle is running! Select 'OK' to continue anyway or 'Cancel' to exit."
End Dialog
Dim Dlg1 As SindleOn
Button = Dialog (Dlg1)
If Button=0 Then
Code "(Auto Tool Zero Aborted!)"
Exit Sub
End If
End If
'Start the actual probe
Code "G0 G53 Z" & Retract2
Code "G0 G53 X" & Xprobpos
Code "G0 G53 Y" & Yprobpos
Code "F" &ProbeFeed ' Set the probe plunge speed
Beep ' Signal start of Z movement
Code "G91 G31Z" &ProbeDist ' Probing move using incremental move mode.
While IsMoving() ' Wait while it happens
Wend
ZProbePos = GetVar(2002) ' Get the axact point the probe was hit
If (ProbeDist+StartingPoint = ZProbePos) Then ' No contact was made during plunge
Code "(Probe failed!)"
Exit Sub
End If
Code "G0 Z" & Retract ' Retract
Code "F" &ProbeFeed2 ' Set the probe plunge speed
Code "G91 G31Z" &Retract+1 ' Probing move using incremental move mode.
While IsMoving() ' Wait while it happens
Wend
Code "G90 G0 Z" &ZProbePos ' Go back to that point. Always a very small amount of overrun.
While IsMoving ()
Wend
code "G10 L1 P" &Tnumber & "Z" &ZProbePos
Code "G0 G53 Z" & Retract2 ' Retract
While IsMoving ()
Wend
Code "(Tool offset set)" ' Success! but is it possible to but the actuall offset set in this box?
End Sub