Advertisement
Guest User

measure_script

a guest
Feb 12th, 2024
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.44 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. #search distance
  31. searchDistance = searchDistance
  32. toolSetterHeight=0 # Hier die Höhe des WLS eintragen oder 0 wenn 3d Taster benutzt wird
  33. # the absolute position of the Z axis of the probe contact for the reference tool
  34. refToolProbePos = -60
  35. # approach velocity (units/min)
  36. vel =1000
  37. # probing velocity (units/min)
  38. fastProbeVel = fastProbeSpeed
  39. slowProbeVel = slowProbeSpeed
  40. feedMeasurementVel = feedMeasurementSpeed
  41. # lift up dist before fine probing
  42. goUpDist = 3
  43. # delay (seconds) before fine probing
  44. fineProbingDelay = 0.2
  45. # other options
  46. moveX = True
  47. moveY = True
  48. checkFineProbingDiff = True
  49. fineProbeMaxAllowedDiff = 0.1
  50.  
  51. #############################################
  52. # Start Z Messung
  53. #############################################
  54. d.setSpindleState(SpindleState.OFF)
  55. toolNr = d.getSpindleToolNumber()
  56. if(toolNr == 0):
  57.   sys.exit("Tool(0) has no tool lenght offset. Probing failed!")
  58.  
  59. # get current absolute position
  60. pos = d.getPosition(CoordMode.Machine)
  61.  
  62. # start fast probing
  63. pos[Axis.Z.value] = pos[Axis.Z.value]-searchDistance
  64. probeResult = d.executeProbing(CoordMode.Machine, pos, probeIndex, fastProbeVel)
  65. if(probeResult == False):
  66.   sys.exit("fast probing failed!")
  67. # get fast probe contact position
  68. fastProbeFinishPos = d.getProbingPosition(CoordMode.Machine)
  69.  
  70. # lift-up Z
  71. d.moveAxisIncremental(Axis.Z, goUpDist, vel)
  72. # delay
  73. time.sleep(fineProbingDelay)
  74. # start fine probing
  75. probeResult = d.executeProbing(CoordMode.Machine, pos, probeIndex, slowProbeVel)
  76. if(probeResult == False):
  77.   sys.exit("slow probing failed!")
  78. # get fine probe contact position
  79. probeFinishPos = d.getProbingPosition(CoordMode.Machine)
  80.  
  81. # check diff between fast and fine probing
  82. probeDiff = abs(fastProbeFinishPos[Axis.Z.value] - probeFinishPos[Axis.Z.value])
  83. if(probeDiff > fineProbeMaxAllowedDiff and checkFineProbingDiff == True):
  84.   errMsg = "ERROR: fine probing difference limit exceeded! (diff: {:.3f})".format(probeDiff)
  85.   sys.exit( errMsg)
  86.  
  87. d.setAxisProgPosition(Axis.Z,0+toolSetterHeight)
  88. d.moveAxisIncremental(Axis.Z,0+zSafeHeight, feedMeasurementVel)
  89.  
  90. #Message Box Start Rechteckmessung
  91. msg.info("Z Tiefenmessung erfolgreich beendet. Bitte Messtaster mittig über dem zu messenden Teil positionieren")
  92.  
  93.  
  94.  
  95. ###
  96. # first Measurement in Yplus
  97. ###                          
  98. d.moveAxisIncremental(Axis.Y,-((yLength/2)+xyClearance),feedMeasurementVel)
  99. d.moveAxisIncremental(Axis.X,((xLength/2)-edgeOffset),feedMeasurementVel)
  100.  
  101. posZ=d.getPosition(CoordMode.Machine)
  102. posZ[Axis.Z.value] = posZ[Axis.Z.value]-(zSafeHeight-zMeasureDeep)
  103.  
  104. #execute positioning the z axis down, when touch probe is active breake
  105. zStartPos = d.executeProbing(CoordMode.Machine, posZ,probeIndex ,feedMeasurementVel)
  106. if(zStartPos==True):
  107.     sys.exit("Z movement fail, please position the probe once again!!")
  108. probePoint1=probeYPlus()
  109.  
  110.  
  111. ###
  112. # second Measurement in Yplus
  113. ###
  114.  
  115. d.moveAxisIncremental(Axis.Y,-(xyClearance),feedMeasurementVel)
  116. d.moveAxisIncremental(Axis.Z,(zSafeHeight-zMeasureDeep),feedMeasurementVel)
  117. d.moveAxisIncremental(Axis.X,-(xLength-(2*edgeOffset)),feedMeasurementVel)
  118. d.moveAxisIncremental(Axis.Z,-(zSafeHeight-zMeasureDeep),feedMeasurementVel)
  119. probePoint2=probeYPlus()
  120.  
  121. d.moveAxisIncremental(Axis.Y,-(xyClearance),feedMeasurementVel)
  122. d.moveAxisIncremental(Axis.Z,(zSafeHeight-zMeasureDeep),feedMeasurementVel)
  123.  
  124. ###
  125. # Measurement in Xplus
  126. ###
  127.  
  128. d.moveAxisIncremental(Axis.X,-(edgeOffset+xyClearance),feedMeasurementVel)
  129. d.moveAxisIncremental(Axis.Y,(xyClearance+yLength/2),feedMeasurementVel)
  130. d.moveAxisIncremental(Axis.Z,-(zSafeHeight-zMeasureDeep),feedMeasurementVel)
  131. probePoint3=probeXPlus()
  132.  
  133. d.moveAxisIncremental(Axis.X,-(xyClearance),feedMeasurementVel)
  134. d.moveAxisIncremental(Axis.Z,(zSafeHeight-zMeasureDeep),feedMeasurementVel)
  135.  
  136. ###
  137. # Measurement in Xminus
  138. ###
  139.  
  140. d.moveAxisIncremental(Axis.X,(xLength+(2*xyClearance)),feedMeasurementVel)
  141. d.moveAxisIncremental(Axis.Z,-(zSafeHeight-zMeasureDeep),feedMeasurementVel)
  142. probePoint4=probeXMinus()
  143.  
  144. d.moveAxisIncremental(Axis.X,(xyClearance),feedMeasurementVel)
  145. d.moveAxisIncremental(Axis.Z,(zSafeHeight-zMeasureDeep),feedMeasurementVel)
  146.  
  147. ###
  148. #Measurement in Yminus
  149. ###
  150.  
  151. d.moveAxisIncremental(Axis.X,-(xLength/2+xyClearance),feedMeasurementVel)
  152. d.moveAxisIncremental(Axis.Y,((yLength/2)+xyClearance),feedMeasurementVel)
  153. d.moveAxisIncremental(Axis.Z,-(zSafeHeight-zMeasureDeep),feedMeasurementVel)
  154. probePoint5=probeYMinus()
  155.  
  156. d.moveAxisIncremental(Axis.Y,(xyClearance),feedMeasurementVel)
  157. d.moveAxisIncremental(Axis.Z,(zSafeHeight-zMeasureDeep),feedMeasurementVel)
  158.  
  159. rotationAngle=rotationAngle(probePoint1,probePoint2)
  160.  
  161. def rectangle_center_zeropointX(p1,p2):
  162.     distance=(p2[0]-p1[0])
  163.     midpoint_x = p1[0]+(distance/2)
  164.    
  165.     return midpoint_x
  166.    
  167.      
  168. def rectangle_center_zeropointY(point1, point2, point3):  
  169.     #equilateral triangle
  170.     sidec = math.sqrt((point2[0] - point1[0])**2 + (point1[1] - point2[1])**2)
  171.     sidea = math.sqrt((point2[0] - point3[0])**2 + (point2[1] - point3[1])**2)
  172.     sideb = math.sqrt((point3[0] - point1[0])**2 + (point3[1] - point1[1])**2)
  173.    
  174.     if sidea == sideb:
  175.         height = math.sqrt(sidec/2)
  176.  
  177.     #calculate hypotenuses
  178.     sidep = math.sqrt(sidea**2 / sidec)
  179.     sideq = math.sqrt(sideb**2 / sidec)
  180.    
  181.     #right triangle
  182.     height = math.sqrt(sidea**2 - sidep**2)
  183.    
  184.     midpoint_y = height/2
  185.    
  186.     return midpoint_y
  187.  
  188. xZeroPoint=rectangle_center_zeropointX(probePoint3, probePoint4)
  189. yZeroPoint=rectangle_center_zeropointY(probePoint2, probePoint1, probePoint5)
  190.  
  191. setAxisProgX(xZeroPoint)
  192. setAxisProgY(yZeroPoint)
  193.  
  194. endPos=pos = d.getPosition(CoordMode.Program)
  195. endPos[0]=0
  196. endPos[1]=0
  197. d.moveToPosition( CoordMode.Program, endPos,feedMeasurementVel)
  198.  
  199. print("Messung erfolgreich beendet.")
  200. distanceX=midpoint_x*2
  201. distanceY=midpoint_y*2
  202. print(f"Das Maße betragen für X: {distanceX:.3f}mm x Y: {distanceY:.3f}mm")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement