Hello Guest it is September 16, 2019, 03:18:49 AM

Author Topic: Autozero and Coordinate issues are loading G-Code  (Read 6464 times)

0 Members and 1 Guest are viewing this topic.

Offline ger21

*
  • *
  •  6,288 6,288
    • View Profile
    • The CNC Woodworker
Re: Autozero and Coordinate issues are loading G-Code
« Reply #20 on: November 08, 2014, 11:28:59 AM »
You should try to avoid mixing units at all costs. While you may get away with it most of the time, sooner or later something will go wrong.
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html

Offline ZASto

*
  •  157 157
    • View Profile
Re: Autozero and Coordinate issues are loading G-Code
« Reply #21 on: November 09, 2014, 11:25:46 AM »
Code from Blue Screen b Big Tex (with minor modifications by me):

Code: [Select]
Sub Main()
'made it a sub, so you can return on "show stopper" errors

'UPDATED TOOL CHANGE ZERO SETUP SCRIPT
'Option Explicit
'Written by Big-Tex December 29 2010
'Modified by Poppa Bear, added Greolt's and Arbo's changes 08Dec2010

Dim xjobcoord, yjobcoord, zjobcoord, xmachcoord, ymachcoord, zmachcoord
Dim ZNew, ZPlate, Zplatetomaterial,PlateOffset, ZMaterialmachcoord, Zplatejobcoord
Dim xprobeloc, yprobeloc,xtoprobe, ytoprobe
Dim FirstProbeDist, FirstRetractDist, SecProbeDist
Dim CurrentFeed
Dim CurrentAbsInc

xjobcoord = GetDRO(0) 'get current job coordinate for X
yjobcoord = GetDRO(1) 'get current job coordinate for Y
zjobcoord = GetDRO(2) 'get current job coordinate for Z
xmachcoord = GetOemDRO(83) 'get current machine coordinate for X
ymachcoord = GetOemDRO(84) 'get current machine coordinate for y
zmachcoord = GetOemDRO(85) 'get current machine coordinate for z
xprobeloc = GetUserDRO(1100) 'get x machine coord of fixed plate
yprobeloc = GetUserDRO(1101) 'get y machine coord of fixed plate
xtoprobe = (xprobeloc - xmachcoord + xjobcoord) 'calc x move to fixed probe
ytoprobe = (yprobeloc - ymachcoord + yjobcoord) 'calc y move to fixed probe
CurrentFeed = GetOemDro(818) 'get current feed rate
PlateOffset = GetUserDRO(1151) 'get plate offset DRO
Zplatetomaterial = GetUserDRO(1102) 'get calculated material offset from somewhere else?
CurrentAbsInc = GetOemLED(48) 'Get the current G90/G91 state


'//////// the block below will set all your reusable vars depending on Inch or mm.
'//////// this sets the vars so you only need ONE large block of probing code.

If GetOEMLED(801) Then 'ON = English Measure INCH
FirstProbeDist = 6.0 'first probe travel
FirstRetractDist = 0.1 'first probe retract travel
SecProbeDist = 0.25 'second probe travel
FirstProbeFeed = 12 'First Probe Feed Speed
SecondProbeFeed = 2 'Second Probe Feed Speed
Zretract = -0.5 'Z retract
Else 'OFF = Metric Measure MM
FirstProbeDist = 150.0 'first probe travel
FirstRetractDist = 3.0 'first probe retract travel
SecProbeDist = 6.0 'second probe travel
FirstProbeFeed = 300 'First Probe Feed Speed
SecondProbeFeed = 50 'Second Probe Feed Speed
Zretract = -12 'Z retract
End If

'//////// Error Condition checking code

If GetOemLED(16)<>0 Then 'Checks for machine coordinates
Code "(Please change to working coordinates)"
Exit Sub 'ERROR! exit the macro
End If

If GetOemLED(825)<>0 Then
Code "(Z-Plate Grounded Check connection and try again)"
Exit Sub 'ERROR! exit the macro
End If

'//////// Start Probing Code, Probe In -Z direction.FIXED PLATE
'//////// The vars will be Inch or Metric from above if/else statment

Code "G0 X" & xtoprobe & " Y" & ytoprobe 'move to fixed plate location
Code "F" & FirstProbeFeed 'slow down feedrate to 12 ipm, or 300 mmpm
Zplate = (GetDro(2) - FirstProbeDist) 'probe move to z - 6", or 150mm
Code "G90 G31Z" & Zplate 'FIRST Probe Operation!

While IsMoving()
Wend

Zplate = GetVar(2002) 'read the touch point
Code "G1 Z" & (Zplate + FirstRetractDist) 'retract above hit point +0.1" or +3mm

While IsMoving()
Wend

Code "F" & SecondProbeFeed 'slow down feedrate to 2 ipm, or 50 mmpm
Zplate = (GetDro(2)- SecProbeDist) 'probe move to current z - 0.25", or -6.0mm
Code "G90 G31Z" & Zplate 'SECOND Probe Operation!

While IsMoving()
Wend

Call SetDRO(2,Zplatetomaterial) 'this sets Z DRO to calculated material offset
Sleep(250) 'pause for Dro to update.
Code "G53 G0 Z" & Zretract

While IsMoving () 'wait for probe move to finish retracting
Wend

Code "G0 X" & xjobcoord & "Y" & yjobcoord 'returns to the previous X Y job location

While IsMoving()
Wend

Code "F" & CurrentFeed 'returns to prior feed rate

'//////// End Probing Code,

If GetOEMLED(801) Then 'ON = English Measure INCH
Code "(Z axis is now zeroed in English Units)" 'puts this message in the status bar
Else 'OFF = Metric Measure MM
Code "(Z axis is now zeroed in Metric Units)" 'puts this message in the status bar
End If

If CurrentAbsInc = 0 Then 'if G91 was in effect before then return to it
Code "G91"
End If

Code DoButton(0) 'Cycle Start

End Sub

I've also modified other button scripts to deal properly with Inch and mm measurements according to units to which the Mach3 is set (OEMLED 801)
« Last Edit: November 09, 2014, 11:28:42 AM by ZASto »
Make no mistake between my personality and my attitude.
My personality is who I am.
My attitude depends on who you are.