Machsupport Forum

Mach Discussion => General Mach Discussion => Topic started by: jestah on December 06, 2012, 12:01:15 AM

Title: Gcode or Vb to update tool table after probing tool length offset
Post by: jestah on December 06, 2012, 12:01:15 AM
Hi guys,

Ok next newbie question.... I am trying to update my tool table offsets but can’t for the life of me find any reference to how to update the tool table using VB.

I have found a few macros and have made one for my more basic manual tool change cnc that just zeros out the Z DRO but as I have got my sticky fingers on a small ATC cnc I would prefer to have the tools in the rack measured and offsets stored in the tool table so that while cutting it only has to grab a tool and avoid measuring each after the change.

I just need to know the code that will actually update the tool table, I have been searching but have not found any thing and my attempts to get it to work in MDI have been fruitless..
Once again many thanks in advance!
Title: Re: Gcode or Vb to update tool table after probing tool length offset
Post by: BR549 on December 06, 2012, 12:10:20 AM
IN the Mach manual look up G10

IN The Mach programmers manual look up SetToolParam()

(;-)TP
Title: Re: Gcode or Vb to update tool table after probing tool length offset
Post by: jestah on December 06, 2012, 12:27:13 AM
Thanks for the point in the right direction, once i have the code done i will post it for all! well at least for the experts to pick to shreds :P
Title: Re: Gcode or Vb to update tool table after probing tool length offset
Post by: Tweakie.CNC on December 06, 2012, 07:00:15 AM
Quote
once i have the code done i will post it for all! well at least for the experts to pick to shreds

No worries Jestah - the experts would not do that.  ;D

Tweakie.
Title: Re: Gcode or Vb to update tool table after probing tool length offset
Post by: BR549 on December 06, 2012, 12:36:23 PM
First you would have to FIND some experts to show it too (;-)

(;-) TP
Title: Re: Gcode or Vb to update tool table after probing tool length offset
Post by: jestah on December 06, 2012, 09:47:25 PM
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

Title: Re: Gcode or Vb to update tool table after probing tool length offset
Post by: BR549 on December 06, 2012, 09:52:09 PM
IF you want the current tool you use

GetCurrentTool()


GetSelectedtool() is the tool number that is loaded into the buffer with the T# call  the M6 call  tansfers the Selected tool to the current tool status.


Just a thought, (;-) TP
Title: Re: Gcode or Vb to update tool table after probing tool length offset
Post by: jestah on December 06, 2012, 09:56:54 PM
So for this am I better to look at one of the tool number dros on screen for getting the current loaded tool?

is it also bad practus to call a macro from a macro?

what is the difference between a oem dro and standard dro?
Title: Re: Gcode or Vb to update tool table after probing tool length offset
Post by: jestah on December 07, 2012, 12:48:32 AM
tired GetCurrentTool() and it still retruns 0 ... hmmmm maybe im still not doing this right!
Title: Re: Gcode or Vb to update tool table after probing tool length offset
Post by: BR549 on December 07, 2012, 01:26:32 AM
Where are you running this macro from ?

(;-) TP
Title: Re: Gcode or Vb to update tool table after probing tool length offset
Post by: jestah on December 07, 2012, 02:03:49 AM
made a new m401 and have it sitting in the macro folder of my test setup for the cnc as I am currently away from where the actual machine is for a few days. Running it at the moment from the vb editor to test it .
Title: Re: Gcode or Vb to update tool table after probing tool length offset
Post by: jestah on December 07, 2012, 06:50:47 AM
forgot to add its in the macro folder in the profile i use as a testing profile. (all ports and pins mapped but running in demo mode without and drivers loaded or ESS plug in)
Title: Re: Gcode or Vb to update tool table after probing tool length offset
Post by: BR549 on December 07, 2012, 11:40:00 AM
IF you are not cycling the M6t# then you will not see the number change for current tool and selected tool.

(;-) TP
Title: Re: Gcode or Vb to update tool table after probing tool length offset
Post by: jestah on December 10, 2012, 10:08:17 AM
Ok had to put this down to get other issues sorted but now that my manual tool release brain is working nicely time to get back into measuring these tools!

So  I have pulled together a few different auto tool zero macros and really happy with this mashup as it has a few key protection features and leave the cnc in the state it was found in. The only issue is I am constantly hitting my z+ soft limit and getting movement that is not what I expect from the G53 command.

I will highlight the lines below to show you where I am having issues but it was my understanding that G53 is in machine coordinates and therefore any offset should have NO effect. With the 0 in the tool offset table I have no issues and the script runs well. Once the offset is set tho on the G53 to Z0 the cnc seems to want to go much higher ( I am assuming the offset value but have a +1mm soft limit on the z at the moment to stop my ball screw nut slamming into bearing block….)

I have tried many different work arounds but none worked well and I would prefer to fine the problem than have to back road methods to be honest.


'Author: Christopher Esser (Smokingman). Based on the work done by Greolt
' modded by jestah 10 dec 2012

' Define fixed parameters (Currently in Metric )

Tnumber      =  GetDRO(24)  ' gets current tool
ProbeDist     = "-50" 'Set the maximum distance to move the Z-axis before probe touches contact plate.
ProbeFeed     = "500"   'Set the first plunge speed for the probe
ProbeFeed2     = "30"   'Set the second plunge speed for the probe
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 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
  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
   
'Start the actual probe

code "G49" 'remove any tool offset (tried both of these options to stop hitting soft limits on z)
'SetToolParam(Tnumber,2,0)
'Code "G43 H" &Tnumber

 Code "G0 G53 Z" & Retract2 ' ( this is where the movement hits the soft limits even with the above removing tool length offsets...?!??!?)
   While IsMoving()
     Wend
     
 Code "G0 G53 X" & Xprobpos
   While IsMoving()
     Wend
  Code "G0 G53 Y" & Yprobpos
    While IsMoving()
      Wend
 
  Code "F" &ProbeFeed        ' Set the probe plunge speed
  Code "G91 G31 Z" &ProbeDist ' Probing move using incremental move mode.
  While IsMoving()           ' Wait while it happens
  Wend

  ZProbePos = GetVar(2002)   ' Get the exact point the probe was hit
 
  If (ProbeDist+StartingPoint = ZProbePos) Then ' No contact was made during plunge
    Code "(Probe failed!)"
    Exit Sub
  End If

Code "G90 G0 Z" &ZProbePos ' Go back to that point. Always a very small amount of overrun.
  While IsMoving ()
  Wend
 
  Code "G91 G0 Z" & Retract      ' Retract
    While IsMoving()           ' Wait while it happens
    Wend
 
  Code "F" &ProbeFeed2       ' Set the probe plunge speed
  Code "G91 G31 Z-" &Retract+0.5 ' Probing move using incremental move mode.
  While IsMoving()           ' Wait while it happens
  Wend
 
  ZProbePos = GetVar(2002)   ' Get the axact point the probe was hit

  Code "G90 G0 Z" &ZProbePos ' Go back to that point. Always a very small amount of overrun.
  While IsMoving ()
  Wend
   
  SetToolParam(Tnumber,2,ZProbePos)
 
  Code "G0 G53 Z" & Retract2     ' Retract to mech zero Have seen this drive z- into the tool sensor but not recently so may have solved this somewhere
  While IsMoving ()
  Wend

Code "G43 H" &Tnumber' apply offset to tool

  Code "(Tool offset set)" 'is it possible to but the actual offset set in this box? not really a issue but would be nice  ;D
End Sub
Title: macro working!
Post by: jestah on December 11, 2012, 02:22:21 AM
Ok I found a clean enough work around for this macro.... I tested it a few times today, ran well from VB editor but from MDI it would do even strange things, I have marked in blue where this would happen.

The odd thing was it would head DOWN and seemed to lump all of the blue lines together (down, x and y movement) at a very slow feed and travel until I got a servo tripping out or my hand hitting the estop. 

Thinking that it should not run them all together I added sleeps(25) between and also a big sleep(500) and a small move off z abs zero and now it seems to run fine... I don't know what it was being so strange but so far after many tests it seems to work well!

Hope it us helpful to others!

' Author: Christopher Esser (Smokingman). Based on the work done by Greolt
' modded by jestah 4th dec 2012

' Define fixed parameters (Currently in Metric )

Tnumber      =  GetDRO(24)  ' gets current tool
ProbeDist     = "-200" 'Set the maximum distance to move the Z-axis before probe touches contact plate.
ProbeFeed     = "500"   'Set the first plunge speed for the probe
ProbeFeed2     = "30"   'Set the second plunge speed for the probe
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   = "2635.74" 'Centre of tool sensor X in mech coor    
Yprobpos   = "31.64" 'Centre of tool sensor Y in mech coor' Declare Global Variables
Probeoffset = "0"' offset from probe top to table surface

' Declare Global Variables
Dim CurrentFeed
Dim CurrentAbsInc
Dim CurrentGmode
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
  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()
 

'Start the actual probe

code "G49" 'remove any tool offset (tried both of these options to stop hitting soft limits on z)
sleep(500)

ActivateSignal(OUTPUT5) ' Dust hood up

'Code "G91 G0 Z-0.01"
Code "G90 G0 G53 Z" & Retract2 ' ( this is where the movement hits the solf limits even with the above removing tool lenght offsets...?!??!?)
   While IsMoving()
   Sleep(50)
     Wend
     
Tme = 0
While(GetOEMLED(822) = fulse)
Sleep(100)
Tme = Tme +.1
If(Tme > 2)Then
MsgBox("Hood up signal Timed out - please check!")
Exit Sub
End If
Wend
         
 Code "G0 G53 X" & Xprobpos
   While IsMoving()
   Sleep(50)
     Wend
  Code "G0 G53 Y" & Yprobpos
    While IsMoving()
    Sleep(50)
      Wend
 
  Code "F" &ProbeFeed        ' Set the probe plunge speed
  Code "G91 G31 Z" &ProbeDist ' Probing move using incremental move mode.
  While IsMoving()           ' Wait while it happens
 Sleep(50)
  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 "G90 G0 Z" &ZProbePos ' Go back to that point. Always a very small amount of overrun.
  While IsMoving ()
  Sleep(50)
  Wend
 
  Code "G91 G0 Z" & Retract      ' Retract
    While IsMoving()           ' Wait while it happens
   Sleep(50)
 Wend
 
  Code "F" &ProbeFeed2       ' Set the probe plunge speed
  Code "G91 G31 Z-" &Retract+0.5 ' Probing move using incremental move mode.
  While IsMoving()           ' Wait while it happens
  Sleep(50)
Wend
 
  ZProbePos = GetVar(2002)   ' Get the axact point the probe was hit

  Code "G90 G0 Z" &ZProbePos ' Go back to that point. Always a very small amount of overrun.
  While IsMoving ()
 Sleep(50)
 Wend
   
  SetToolParam(Tnumber,2,ZProbePos)
 
  Code "G0 G53 Z" & Retract2     ' Retract to mech zero
  While IsMoving ()
  Sleep(50)
Wend

Code "G43 H" &Tnumber' apply offset to tool

  Code "(Tool offset set)" 'is it possible to but the actual offset set in this box?
 
 DeActivateSignal(OUTPUT5)
 
  End Sub