Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exec(open('functions.py', encoding='utf-8').read())
- import sys
- import time
- probeIndex = probeIndexTouch
- #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 Axis.X == 0:
- print("Achsen müssen referenziert sein!")
- sys.exit()
- y=d.isAxisReferenced(Axis.Y)
- if Axis.Y == 0:
- print("Achsen müssen referenziert sein!")
- sys.exit()
- z=d.isAxisReferenced(Axis.Z)
- if Axis.Z == 0:
- print("Achsen müssen referenziert sein!")
- sys.exit()
- resetG68()
- #############################################
- # Z Measure
- #############################################
- #search distance
- searchDistance = searchDistance
- toolSetterHeight=0 # Hier die Höhe des WLS eintragen oder 0 wenn 3d Taster benutzt wird
- # the absolute position of the Z axis of the probe contact for the reference tool
- refToolProbePos = -60
- # approach velocity (units/min)
- vel =1000
- # probing velocity (units/min)
- fastProbeVel = fastProbeSpeed
- slowProbeVel = slowProbeSpeed
- feedMeasurementVel = feedMeasurementSpeed
- # lift up dist before fine probing
- goUpDist = 3
- # delay (seconds) before fine probing
- fineProbingDelay = 0.2
- # other options
- moveX = True
- moveY = True
- checkFineProbingDiff = True
- fineProbeMaxAllowedDiff = 0.1
- #############################################
- # Start Z Measure
- #############################################
- d.setSpindleState(SpindleState.OFF)
- toolNr = d.getSpindleToolNumber()
- if(toolNr == 0):
- sys.exit("Tool(0) has no tool lenght offset. Probing failed!")
- # get current absolute position
- pos = d.getPosition(CoordMode.Machine)
- # start fast probing
- pos[Axis.Z.value] = pos[Axis.Z.value]-searchDistance
- probeResult = d.executeProbing(CoordMode.Machine, pos, probeIndex, fastProbeVel)
- if(probeResult == False):
- sys.exit("fast probing failed!")
- # get fast probe contact position
- fastProbeFinishPos = d.getProbingPosition(CoordMode.Machine)
- # lift-up Z
- d.moveAxisIncremental(Axis.Z, goUpDist, vel)
- # delay
- time.sleep(fineProbingDelay)
- # start fine probing
- probeResult = d.executeProbing(CoordMode.Machine, pos, probeIndex, slowProbeVel)
- if(probeResult == False):
- sys.exit("slow probing failed!")
- # get fine probe contact position
- probeFinishPos = d.getProbingPosition(CoordMode.Machine)
- # check diff between fast and fine probing
- probeDiff = abs(fastProbeFinishPos[Axis.Z.value] - probeFinishPos[Axis.Z.value])
- if(probeDiff > fineProbeMaxAllowedDiff and checkFineProbingDiff == True):
- errMsg = "ERROR: fine probing difference limit exceeded! (diff: {:.3f})".format(probeDiff)
- sys.exit( errMsg)
- d.setAxisProgPosition(Axis.Z,0+toolSetterHeight)
- d.moveAxisIncremental(Axis.Z,0+zSafeHeight, fastProbeVel)
- #Message Box Start Kreismessung
- msg.info("Z Tiefenmessung erfolgreich beendet. Messtaster mittig über der zu messenden Kreistasche positionieren!")
- ##################################
- # start Circle Outer Measure
- ##################################
- xyClearance<=diameterCircleInner/2
- if(xyClearance>diameterCircleInner/2 == True):
- errMsg="XY Offset muß kleiner wie der halbe Durchmesser sein!"
- d.moveAxisIncremental(Axis.Z,-(zSafeHeight-zMeasureDeep),feedMeasurementVel)
- d.moveAxisIncremental(Axis.Y,-((diameterCircleInner/2)-xyClearance),feedMeasurementVel)
- posZ=d.getPosition(CoordMode.Machine)
- posZ[Axis.Z.value] = posZ[Axis.Z.value]
- #execute positioning the z axis down, when touch probe is active breake
- zStartPos = d.executeProbing(CoordMode.Machine, posZ,probeIndex ,feedMeasurementVel)
- if(zStartPos==True):
- sys.exit("Z movement fail, please position the probe once again!!")
- probePoint1=probeYMinus()
- d.moveAxisIncremental(Axis.Y,(diameterCircleInner/2),feedMeasurementVel)
- ###
- #second Point Measurement
- ###
- d.moveAxisIncremental(Axis.X,-((diameterCircleInner/2)-xyClearance),feedMeasurementVel)
- probePoint2=probeXMinus()
- d.moveAxisIncremental(Axis.X,(diameterCircleInner/2),feedMeasurementVel)
- ###
- #third Point Measurement
- ###
- d.moveAxisIncremental(Axis.Y,((diameterCircleInner/2)-xyClearance),feedMeasurementVel)
- probePoint3=probeYPlus()
- d.moveAxisIncremental(Axis.Y,-(diameterCircleInner/2),feedMeasurementVel)
- ###
- #fourth Point Measurement
- ###
- d.moveAxisIncremental(Axis.X,((diameterCircleInner/2)-xyClearance),feedMeasurementVel)
- probePoint4=probeXPlus()
- d.moveAxisIncremental(Axis.X,-(diameterCircleOuter/2),feedMeasurementVel)
- d.moveAxisIncremental(Axis.Z,(zSafeHeight-zMeasureDeep),feedMeasurementVel)
- ###
- #calculation of the zero point
- ###
- middleOfCircle=circleMiddle(probePoint1,probePoint2,probePoint3)
- middleOfCircle2=circleMiddle(probePoint1,probePoint2,probePoint4)
- diameter=calculation_diameter(probePoint1, probePoint2, probePoint3, probePoint4)
- print(f"Der gemessene Durchmesser beträgt: {diameter:.3f}mm")
- setAxisProgX(middleOfCircle[0])
- setAxisProgY(middleOfCircle2[1])
- endPos=pos = d.getPosition(CoordMode.Program)
- endPos[0]=0
- endPos[1]=0
- d.moveToPosition(CoordMode.Program, endPos,feedMeasurementVel)
- print("Messung erfolgreich beendet.")
Advertisement
Add Comment
Please, Sign In to add comment