I write this new version, but I have still a problem.
There's an error measuring the tool, from 0.15 to 0.5mm out, this is not due to the switch because when the tool hit it the measured value is always the same.
there's something that i don't know?
well, this is the new version.
ChX = GetUserDRO( 1200 )
ChY = GetUserDRO( 1201 )
ChZ = GetUserDRO( 1202 )
Code "G53 G00 Z-1" 'Move the tool all the way up
While IsMoving()
Wend
ZOld = Getdro(2)
Code "G53 G00 X" & ChX & "Y" & ChY 'Move to the probe position
While IsMoving()
Wend
Code "G31 Z-230 F600" 'Z move down untill hit
While IsMoving()
Wend
Code "G91 G00 Z5"
Code "G31 Z-10 F60"
While IsMoving()
Wend
HitOldA = GetVar(2002) 'Get the Position that the Porbe hit at
Code "G91 G00 Z5"
Code "G31 Z-10 F60"
While IsMoving()
Wend
HitOldB = GetVar(2002)
Code "G91 G00 Z5"
Code "G31 Z-10 F60"
While IsMoving()
Wend
HitOldC = GetVar(2002)
HitOld = (HitOldA + HitOldB + HitOldC)/3
Code "G90"
Code "G53 G00 Z-1"'Z move all way up
Code "G53 G00 X65 Y-200" 'Move to change tool position
While IsMoving()
Wend
MsgBox ("Insert the new tool")
Code "G53 G00 X" & ChX & "Y" & ChY 'Move to the probe position
While IsMoving()
Wend
Code "G31 Z-230 F600" 'Z move down untill hit
While IsMoving()
Wend
Code "G91 G00 Z5"
Code "G31 Z-10 F60"
While IsMoving()
Wend
HitNewA = GetVar(2002) 'Get the Position that the Porbe hit at
Code "G91 G00 Z5"
Code "G31 Z-10 F60"
While IsMoving()
Wend
HitNewB = GetVar(2002)
Code "G91 G00 Z5"
Code "G31 Z-10 F60"
While IsMoving()
Wend
HitNewC = GetVar(2002)
HitNew = (HitNewA + HitNewB + HitNewC)/3
Diff = HitOld - HitNew
DiffABS =Abs(Diff)
If DiffABS=0 Then End
ZNew=0
If HitOld < HitNew Then ZNew = ZOld - DiffABS
If HitOld > HitNew Then ZNew = ZOld + DiffABS
Code "G90"
Code "G53 G00 Z-1"
While IsMoving()
Wend
Call setdro(2,ZNew)
'FxModel Creation
End
Bye