fbpx

CS-Lab Support Forum for CNC Community

Help to run this brand-new forum and stay with us.
Ask your questions, we are here to help! 

 

Please or Register to create posts and topics.

z minus probing script question

Hello,

i wrote a script for setting the Z zero point. In principle it works but I would have expected that when measuring fast the 3D probe would move down (with G31) and as soon as the 3D probe is triggered the measurement is finished it would move up and then do it again as a slow measurement. Unfortunately that is not the case, it always moves the specified search distance down and only then is it recognized that the probe has been triggered. What could be the reason for this? What is my mistake? I would be happy if you could help me.

import os
import sys
import time
import math

GCode ="G91"
print (GCode)
move = d.executeGCode(GCode)

# Parameters
# Touch Probe digital input
touchProbe = int(d.getMachineParam(321))

# vel_Zreturn
vel_Zreturn = 1000

# Parameters from GUI
touch_fast = int(d.getMachineParam(1))
touch_slow = int(d.getMachineParam(2))
searchdistance = int(d.getMachineParam(3))
goUpDistance=0.5
zSafeHeight = int(d.getMachineParam(306))

# maximum allowed difference in mm
max_difference = 0.1

#check machine in idle state
if d.getState() != State.Idle:
print("Steuerung muß eingeschaltet sein.")
exit(0)

# check Axis referenced
x = d.isAxisReferenced(Axis.X)
if x == 0:
print("Achse muß referenziert sein!")
sys.exit()

y = d.isAxisReferenced(Axis.Y)
if y == 0:
print("Achse muß referenziert sein!")
sys.exit()

z = d.isAxisReferenced(Axis.Z)
if z == 0:
print("Achse muß referenziert sein!")
sys.exit()

# spindle off and check tool number
d.setSpindleState(SpindleState.OFF)
toolNr = d.getSpindleToolNumber()
if(toolNr == 0):
sys.exit("Tool(0) has no tool lenght offset. Probing failed!")

def Probing_Z():
# Z-probing fast
GCode="G31 Z-" +str(searchdistance) +" F" +str(touch_fast)
print("Probing Z: Schnelltasten-Code = ", GCode)
move = d.executeGCode(GCode)

# Probing ok?
mod_IP = d.getModule(ModuleType.IP, 0)
if mod_IP.getDigitalIO(IOPortDir.InputPort, touchProbe) == DIOPinVal.PinSet:
sys.exit("Probing Z: Tasten: Fehler Z-Achse!!")
else:
print("Probing Z: Tasten ok")

# save fast Measurement
fast_measurement = d.getPosition(CoordMode.Machine)[2]

# Move Z on top
GCode="G01 Z" +str(goUpDistance) +" F" +str(vel_Zreturn)
time.sleep(0.5)
print("Probing Z: Fahre Z nach oben ", GCode)
move = d.executeGCode(GCode)

# Z-probing slow
GCode="G31 Z-" +str(searchdistance) +" F" +str(touch_slow)
print("Probing Z: Langsamtasten-Code = ", GCode)
move = d.executeGCode(GCode)

# Probing ok?
mod_IP = d.getModule(ModuleType.IP, 0)
if mod_IP.getDigitalIO(IOPortDir.InputPort, touchProbe) == DIOPinVal.PinSet:
sys.exit("Probing Z: Tasten: Fehler Z-Achse!!")
else:
print("Probing Z: Tasten ok")

# save slow Measurement
slow_measurement = d.getPosition(CoordMode.Machine)[2]

# comparison of measurements
difference = abs(fast_measurement - slow_measurement)
if difference > max_difference:
sys.exit(f"Probing Z: Fehler - Unterschied zwischen schneller und langsamer Messung ({difference:.3f} mm) überschreitet den Grenzwert ({max_difference:.3f} mm)")

d.setAxisProgPosition(Axis.Z, 0)
pos=d.getPosition(CoordMode.Program)
posz = pos[2]
print("Probing Z: PosZ = ", posz)

# Calling the Probing_Z function
Probing_Z()

d.setAxisProgPosition(Axis.Z, 0)

# Move Z on top
GCode="G01 Z" +str(zSafeHeight) +" F" +str(vel_Zreturn)
print("Probing Z: Fahre Z nach oben ", GCode)
move = d.executeGCode(GCode)

print("Z Nullpunkt erfolgreich gesetzt.")

Hello,
I was able to solve it myself. I had read that there was G31.1, G31.2 etc. but didn't understand why at the time. Now it's clear and it makes sense to address each individual button separately. Now it works perfectly.

Please send me the compressed macro, I want to check its operation.

PARTNERS:

 

USA

Germany

Slovenia / Bosnia

Spain

South Africa

UNI-CAM

The Netherlands

Portugal

Greece

  Distrib milionis logo

Hungary

Distrib logot

Bulgaria

Master

Kenya

Proteq Automation

Egypt

Germanelectronix

China

Jun Ma

Serbia

ALCO

Italy

LVL tech r

Denmark

Varntoft Dania

Finland

×

Hello!

Click one of our contacts below to chat on WhatsApp

× How can I help you?