Guest User

Untitled

a guest
Feb 20th, 2024
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.10 KB | None | 0 0
  1. exec(open('functions.py', encoding='utf-8').read())
  2. import sys
  3. import time
  4.  
  5. probeIndex = probeIndexTouch
  6.  
  7. #check machine in idle state
  8. if d.getState() != State.Idle:
  9.     print("Steuerung muß eingeschaltet sein.")
  10.     exit(0)
  11.  
  12. # check Axis referenced
  13. x=d.isAxisReferenced(Axis.X)
  14. if Axis.X == 0:
  15.    print("Achsen müssen referenziert sein!")
  16.    sys.exit()
  17.    
  18. y=d.isAxisReferenced(Axis.Y)
  19. if Axis.Y == 0:
  20.    print("Achsen müssen referenziert sein!")
  21.    sys.exit()
  22.    
  23. z=d.isAxisReferenced(Axis.Z)
  24. if Axis.Z == 0:
  25.    print("Achsen müssen referenziert sein!")
  26.    sys.exit()
  27.  
  28. resetG68()
  29.  
  30. #############################################
  31. # Z Measure
  32. #############################################
  33.  
  34. #search distance
  35. searchDistance = searchDistance
  36. toolSetterHeight=0                      # Hier die Höhe des WLS eintragen oder 0 wenn 3d Taster benutzt wird
  37. # the absolute position of the Z axis of the probe contact for the reference tool
  38. refToolProbePos = -60
  39. # approach velocity (units/min)
  40. vel =1000
  41. # probing velocity (units/min)
  42. fastProbeVel = fastProbeSpeed
  43. slowProbeVel = slowProbeSpeed
  44. feedMeasurementVel = feedMeasurementSpeed
  45. # lift up dist before fine probing
  46. goUpDist = 3
  47. # delay (seconds) before fine probing
  48. fineProbingDelay = 0.2
  49. # other options
  50. moveX = True
  51. moveY = True
  52. checkFineProbingDiff = True
  53. fineProbeMaxAllowedDiff = 0.1
  54.  
  55. #############################################
  56. # Start Z Measure
  57. #############################################
  58. d.setSpindleState(SpindleState.OFF)
  59. toolNr = d.getSpindleToolNumber()
  60. if(toolNr == 0):
  61.   sys.exit("Tool(0) has no tool lenght offset. Probing failed!")
  62.  
  63. # get current absolute position
  64. pos = d.getPosition(CoordMode.Machine)
  65.  
  66. # start fast probing
  67. pos[Axis.Z.value] = pos[Axis.Z.value]-searchDistance
  68. probeResult = d.executeProbing(CoordMode.Machine, pos, probeIndex, fastProbeVel)
  69. if(probeResult == False):
  70.   sys.exit("fast probing failed!")
  71. # get fast probe contact position
  72. fastProbeFinishPos = d.getProbingPosition(CoordMode.Machine)
  73.  
  74. # lift-up Z
  75. d.moveAxisIncremental(Axis.Z, goUpDist, vel)
  76. # delay
  77. time.sleep(fineProbingDelay)
  78. # start fine probing
  79. probeResult = d.executeProbing(CoordMode.Machine, pos, probeIndex, slowProbeVel)
  80. if(probeResult == False):
  81.   sys.exit("slow probing failed!")
  82. # get fine probe contact position
  83. probeFinishPos = d.getProbingPosition(CoordMode.Machine)
  84.  
  85. # check diff between fast and fine probing
  86. probeDiff = abs(fastProbeFinishPos[Axis.Z.value] - probeFinishPos[Axis.Z.value])
  87. if(probeDiff > fineProbeMaxAllowedDiff and checkFineProbingDiff == True):
  88.   errMsg = "ERROR: fine probing difference limit exceeded! (diff: {:.3f})".format(probeDiff)
  89.   sys.exit( errMsg)
  90.  
  91. d.setAxisProgPosition(Axis.Z,0+toolSetterHeight)
  92. d.moveAxisIncremental(Axis.Z,0+zSafeHeight, fastProbeVel)
  93.  
  94. #Message Box Start Kreismessung
  95. msg.info("Z Tiefenmessung erfolgreich beendet. Messtaster mittig über der zu messenden Kreistasche positionieren!")
  96.  
  97.  
  98. ##################################
  99. # start Circle Outer Measure
  100. ##################################
  101.  
  102. xyClearance<=diameterCircleInner/2
  103. if(xyClearance>diameterCircleInner/2 == True):
  104.   errMsg="XY Offset muß kleiner wie der halbe Durchmesser sein!"
  105.  
  106. d.moveAxisIncremental(Axis.Z,-(zSafeHeight-zMeasureDeep),feedMeasurementVel)
  107. d.moveAxisIncremental(Axis.Y,-((diameterCircleInner/2)-xyClearance),feedMeasurementVel)
  108.  
  109. posZ=d.getPosition(CoordMode.Machine)
  110. posZ[Axis.Z.value] = posZ[Axis.Z.value]
  111.  
  112. #execute positioning the z axis down, when touch probe is active breake
  113. zStartPos = d.executeProbing(CoordMode.Machine, posZ,probeIndex ,feedMeasurementVel)
  114. if(zStartPos==True):
  115.     sys.exit("Z movement fail, please position the probe once again!!")
  116. probePoint1=probeYMinus()
  117.  
  118. d.moveAxisIncremental(Axis.Y,(diameterCircleInner/2),feedMeasurementVel)
  119.  
  120.  
  121. ###
  122. #second Point Measurement
  123. ###
  124. d.moveAxisIncremental(Axis.X,-((diameterCircleInner/2)-xyClearance),feedMeasurementVel)
  125. probePoint2=probeXMinus()
  126.  
  127. d.moveAxisIncremental(Axis.X,(diameterCircleInner/2),feedMeasurementVel)
  128.  
  129.  
  130. ###
  131. #third Point Measurement
  132. ###
  133. d.moveAxisIncremental(Axis.Y,((diameterCircleInner/2)-xyClearance),feedMeasurementVel)
  134. probePoint3=probeYPlus()
  135.  
  136. d.moveAxisIncremental(Axis.Y,-(diameterCircleInner/2),feedMeasurementVel)
  137.  
  138.  
  139. ###
  140. #fourth Point Measurement
  141. ###
  142. d.moveAxisIncremental(Axis.X,((diameterCircleInner/2)-xyClearance),feedMeasurementVel)
  143. probePoint4=probeXPlus()
  144.  
  145. d.moveAxisIncremental(Axis.X,-(diameterCircleOuter/2),feedMeasurementVel)
  146. d.moveAxisIncremental(Axis.Z,(zSafeHeight-zMeasureDeep),feedMeasurementVel)
  147.  
  148.  
  149. ###
  150. #calculation of the zero point
  151. ###
  152. middleOfCircle=circleMiddle(probePoint1,probePoint2,probePoint3)
  153. middleOfCircle2=circleMiddle(probePoint1,probePoint2,probePoint4)
  154.  
  155. diameter=calculation_diameter(probePoint1, probePoint2, probePoint3, probePoint4)
  156. print(f"Der gemessene Durchmesser beträgt: {diameter:.3f}mm")
  157.  
  158. setAxisProgX(middleOfCircle[0])
  159. setAxisProgY(middleOfCircle2[1])
  160.  
  161. endPos=pos = d.getPosition(CoordMode.Program)
  162. endPos[0]=0
  163. endPos[1]=0
  164. d.moveToPosition(CoordMode.Program, endPos,feedMeasurementVel)
  165.  
  166. print("Messung erfolgreich beendet.")
Advertisement
Add Comment
Please, Sign In to add comment