Advertisement
Guest User

Untitled

a guest
Mar 19th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 35.72 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #
  3. #-----------------------------------------------------------------------------------
  4. import linuxcnc
  5. from interpreter import *
  6. from emccanon import MESSAGE, SET_MOTION_OUTPUT_BIT, CLEAR_MOTION_OUTPUT_BIT,SET_AUX_OUTPUT_BIT,CLEAR_AUX_OUTPUT_BIT
  7. #from util import lineno
  8. #-----------------------------------------------------------------------------------
  9. throw_exceptions = 1 # raises InterpreterException if execute() or read() fail
  10. #-----------------------------------------------------------------------------------
  11. #import TopLevel # Needed ?
  12. from stdglue import change_prolog, change_epilog, init_stdglue # done in TopLevel.py ...
  13. import xmlBiesse
  14. import time
  15. import sys
  16. #-------------------------------------------------------------------------------------------
  17. # MAIN FUNCTION : change_remap
  18. #
  19. # from REMAP=M6 modalgroup=6 prolog=change_prolog python=change_remap epilog=change_epilog
  20. # - change_prolog and change_epilog are in stdglue.py
  21. #-------------------------------------------------------------------------------------------
  22. #------------------------------------------------------------------
  23. # MAIN ALGO
  24. #------------------------------------------------------------------
  25. # param : selected tool
  26. #
  27. # in machine coordinates
  28. #
  29. # raise all spindles ... drills ... side drills ... DONE raiseALLspindles()
  30. #
  31. # selectedtool = int(self.params["selected_tool"])
  32. # if selectedtool > 500:
  33. # drop Side Drill selectedtool - 500 DONE DropSideDrill(i)
  34. # elif (selectedtool > 400 and selectedtool < 500):
  35. # drop Drill selectedtool - 400 DONE DropDrill(i)
  36. # else:
  37. # if selectedtool = 11:
  38. # drop spindle C DONE DropSpindle("C")
  39. # Energise spindle C DONE EnergiseSpindle("C")
  40. # return INTERP_OK DONE
  41. # elif selectedtool = 10:
  42. # drop spindle B DONE DropSpindle("B")
  43. # Energise spindle B DONE EnergiseSpindle("B")
  44. # return INTERP_OK DONE
  45. # elif selectedtool > 0 and selectedtool < 4: #only 3 tools for A
  46. # Energise spindle A DONE EnergiseSpindle("A")
  47. # # now time to see if already in spindle
  48. # find free pocket DONE FindFreePocket()
  49. # if free pocket number is equal to selectedtool then already in spindle,
  50. # drop spindle A DONE DropSpindle("A")
  51. # return INTERP_OK DONE
  52. #------------------------------------------------------------------
  53. # # not in spindle
  54. #
  55. # #Energise spindle A DONE EnergiseSpindle("A")
  56. #
  57. # If not found
  58. # DROP current tool in free pocket
  59. # make sure casket is opened WorkingOnIt
  60. # find free pocket DONE FindFreePocket
  61. # move to FRONT of said pocked TBD1
  62. # raise said pocket DONE RaisePocket(i)
  63. # Drop Spindle 1 DONE DropSpindle("A")
  64. # move INTO said pocket TBD2 MoveIntoOrOutOfPocket
  65. # release tool DONE ReleaseSpindle("A")
  66. # raise spindle 1 DONE RaiseSpindle("A")
  67. # move back to FRONT of said pocket TBD1
  68. # lower said pocket DONE LowerPocket(i)
  69. #
  70. # PICKUP selected tool in according pocket
  71. # make sure casket is opened WorkingOnIt
  72. # find in which pocket is the tool DONE FindToolPocket(i)
  73. # move to TOP of said pocket TBD3
  74. # raise said pocket DONE RaisePocket(i)
  75. # unlock spindle 1 (should be) DONE ReleaseSpindle("A")
  76. # drop spindle 1 DONE DropSpindle("A")
  77. # lock spindle 1 DONE LockSpindle("A")
  78. # move OUT of said pocket TBD2 MoveIntoOrOutOfPocket
  79. # lower said pocket DONE LowerPocket(i)
  80. # close casket DONE CloseCasket
  81. #
  82. # when done, change the world coordinate system to reflect the new offsets for the selected spindle
  83. # (G10 L20 X0 Y0 Z0) ...
  84. #
  85. #
  86. #
  87. #
  88. #
  89. #
  90. #
  91. #
  92. #------------------------------------------------------------------
  93. #------------------------------------------------------------------
  94. def change_remap(self, **words):
  95. for key in words:
  96. MESSAGE("word '%s' = %f" % (key, words[key]))
  97. if words.has_key('p'):
  98. MESSAGE("the P word was present")
  99. if words.has_key('q'):
  100. MESSAGE("the Q word was present")
  101.  
  102. # check if parameters are needed here ....
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109. #print(pi()) # to test if available with TopLevel.py ...
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116. try:
  117. #---------------------------------------------------------------------
  118. # XML - Objects to fetch needed infos ...
  119. #---------------------------------------------------------------------
  120. xBiesse = xmlBiesse.xmlBiesse() # the xml interface
  121. api = clsAPI(xBiesse) # the utility functions defined below
  122. #---------------------------------------------------------------------
  123. # check for spindleHasStopped if not raise error WaitForSpindleToStop
  124. if api.WaitForSpindleToStop() == False:
  125. msg = "Spindle Motor is not stopped"
  126. self.set_errormsg(msg) # replace builtin error message
  127. return INTERP_ERROR
  128. #------------------------------------------------------------------
  129. # we are good to go
  130. #------------------------------------------------------------------
  131. api.raiseALLspindles()
  132. selectedtool = int(self.params["selected_tool"])
  133. if selectedtool > 500:
  134. api.DropSideDrill(selectedtool - 500)
  135. elif (selectedtool > 400 and selectedtool < 500):
  136. api.DropDrill(selectedtool - 400)
  137. else:
  138. if selectedtool == 11:
  139. if api.SpindleHasTool("C"):
  140. api.DropSpindle("C")
  141. api.EnergiseSpindle("C")
  142. return INTERP_OK
  143. else:
  144. msg = "Spindle C has no tool"
  145. self.set_errormsg(msg)
  146. return INTERP_ERROR
  147. elif selectedtool == 10:
  148. if api.SpindleHasTool("B"):
  149. api.DropSpindle("B")
  150. api.EnergiseSpindle("B")
  151. return INTERP_OK
  152. else:
  153. msg = "Spindle B has no tool"
  154. self.set_errormsg(msg)
  155. return INTERP_ERROR
  156. elif selectedtool > 0 and selectedtool < 4: #only 3 tools for A (1, 2, 3)
  157. api.EnergiseSpindle("A")
  158. # now time to see if already in spindle
  159. freePocket = api.FindFreePocket()
  160. print("freePocket = %s" % freePocket)
  161. currenttool = int(self.params["tool_in_spindle"])
  162. if freePocket == -1:
  163. # what is in spindle 1 ? check if spindle has tool
  164. if api.SpindleHasTool("A"): # we have a problem
  165. msg = "No Free Pockets and Spindle A has a tool"
  166. self.set_errormsg(msg)
  167. return INTERP_ERROR
  168. else: # if not, go get the one needed
  169. #------------------------------------------
  170. # PICKUP selected tool in according pocket
  171. #------------------------------------------
  172. res = PickUpNewTool(selectedtool, api)
  173. if res != 0:
  174. msg = "Error while picking up a new tool, err number: %d" % res
  175. self.set_errormsg(msg) # replace builtin error message
  176. return INTERP_ERROR
  177. else:
  178. #------------------------------------
  179. # DROP current tool in free pocket
  180. #------------------------------------
  181. # check if spindle has tool
  182. if not api.SpindleHasTool("A"):
  183. msg = "Error while droping a tool, Spindle A has no tool to drop"
  184. self.set_errormsg(msg) # replace builtin error message
  185. return INTERP_ERROR
  186. res = DropCurrentTool(currenttool, freePocket, api)
  187. if res != 0:
  188. msg = "Error while droping the current tool, err number: %d" % res
  189. self.set_errormsg(msg) # replace builtin error message
  190. return INTERP_ERROR
  191. #------------------------------------------
  192. # PICKUP selected tool in according pocket
  193. #------------------------------------------
  194. res = PickUpNewTool(selectedtool, api)
  195. if res != 0:
  196. msg = "Error while picking up a new tool, err number: %d" % res
  197. self.set_errormsg(msg) # replace builtin error message
  198. return INTERP_ERROR
  199. elif selectedtool == 0:
  200. freePocket = api.FindFreePocket()
  201. print("freePocket = %s" % freePocket)
  202. currenttool = int(self.params["tool_in_spindle"])
  203. if freePocket == -1:
  204. if api.SpindleHasTool("A"): # we have a problem
  205. msg = "T0 M6: Error, No Free Pockets and Spindle A has a tool"
  206. self.set_errormsg(msg)
  207. return INTERP_ERROR
  208. else: # if not, do nothing, M0 is to remove a tool, which is absent
  209. pass
  210. else:
  211. if api.SpindleHasTool("A"): # We have a tool to drop
  212. res = DropCurrentTool(currenttool, freePocket, api)
  213. if res != 0:
  214. msg = "T0 M6: Error while droping the current tool, err number: %d" % res
  215. self.set_errormsg(msg) # replace builtin error message
  216. return INTERP_ERROR
  217. else:
  218. pass
  219. else:
  220. msg = "Wrong tool number either 0 to remove it from spindle or 1,2,3. Tool given: %d" % selectedtool
  221. self.set_errormsg(msg) # replace builtin error message
  222. return INTERP_ERROR
  223.  
  224. #-----------------------------------------
  225. # We have errors ! catch and return error
  226. #-----------------------------------------
  227. except InterpreterException,e:
  228. msg = "%d: '%s' - %s" % (e.line_number,e.line_text, e.error_message)
  229. self.set_errormsg(msg) # replace builtin error message
  230. return INTERP_ERROR
  231.  
  232. except IOError as e:
  233. print "I/O error({0}): {1}".format(e.errno, e.strerror)
  234. return INTERP_ERROR
  235. except ValueError:
  236. print "Could not convert data to an integer."
  237. return INTERP_ERROR
  238. except ZeroDivisionError as detail:
  239. print 'Handling run-time error:', detail
  240. return INTERP_ERROR
  241. except:
  242. print "Unexpected error:", sys.exc_info()[0]
  243. raise
  244.  
  245. finally:
  246. print 'Finally, have a nice day!'
  247. #-----------------------
  248. # all fine, return ok !
  249. #-----------------------
  250. return INTERP_OK
  251.  
  252. #----------------------------------------------------------
  253. #----------------------------------------------------------
  254. def DropCurrentTool(sWhere, api): #(sWhere = 1,2,3)
  255. #----------------------------------------
  256. # Open the cover
  257. #----------------------------------------
  258. isCasketOpened = api.OpenCasket()
  259. if isCasketOpened != 0:
  260. return isCasketOpened #(-6,-7,-8,-9,-10)
  261. #----------------------------------------
  262. # move to front, Raise pocket, Drop,
  263. # move into, release
  264. #----------------------------------------
  265. api.MoveToFrontOfPocket(sWhere)
  266. api.RaisePocket(sWhere)
  267. api.DropSpindle("A")
  268. api.MoveIntoOrOutOfPocket(sWhere, "INTO")
  269. api.ReleaseSpindle("A")
  270. #----------------------------------------
  271. # verify that the spindle has no tool ...
  272. #----------------------------------------
  273. if api.SpindleHasTool("A"):
  274. return -1
  275. #----------------------------------------
  276. # Raise, move out, lower pocket
  277. #----------------------------------------
  278. api.RaiseSpindle("A")
  279. api.LowerPocket(sWhere)
  280. api.MoveIntoOrOutOfPocket(sWhere, "OUT")
  281.  
  282. return 0
  283.  
  284. #----------------------------------------------------------
  285. #----------------------------------------------------------
  286. def PickUpNewTool(sWhich, api):
  287.  
  288. #----------------------------------------
  289. # Open the cover, should already be ...
  290. #----------------------------------------
  291. isCasketOpened = api.OpenCasket()
  292. if isCasketOpened != 0:
  293. return isCasketOpened #(-6,-7,-8,-9,-10)
  294. #------------------------------------------
  295. # go to top of tool pocket, raise pocket,
  296. # quick release (shoud be done), Drop, Lock
  297. #------------------------------------------
  298. pocket = api.FindToolPocket(sWhich)
  299. api.MoveToTopOfPocket(pocket)
  300. api.ReleaseSpindle("A")
  301. api.RaisePocket(pocket)
  302. api.DropSpindle("A")
  303. api.LockSpindle("A")
  304. #----------------------------------------
  305. # verify that the spindle has a tool ...
  306. #----------------------------------------
  307. if not api.SpindleHasTool("A"):
  308. return -1
  309. #----------------------------------------
  310. # Move out and lower pocket
  311. #----------------------------------------
  312. api.MoveIntoOrOutOfPocket(pocket, "OUT")
  313. api.LowerPocket(pocket)
  314. #----------------------------------------
  315. # close the cover
  316. #----------------------------------------
  317. isCasketClosed = api.CloseCasket()
  318. if isCasketClosed != 0:
  319. return isCasketClosed #(-1,-2, -3, -4, -5)
  320. else:#
  321. return 0
  322.  
  323. #------------------------------------------------------------------
  324. # Utility class clsAPI - has the details of xml and stat
  325. #------------------------------------------------------------------
  326. class clsAPI(object):
  327.  
  328. def __init__(self, x):
  329. self.x = x
  330. self.cnc = linuxcnc
  331. self.stat = self.cnc.stat()
  332. self.command = self.cnc.command()
  333. self.pulseDelay = self.x.getPulseDelay()
  334. self.coverDelay = self.x.getCoverDelay()
  335. self.actuationDelay = self.x.getActuationDelay()
  336. self.feedSpeed = self.x.getFeedSpeed()
  337.  
  338. #------------------------------------------------------------------------------------
  339. #------------------------------------------------------------------------------------
  340. #------------------------------------------------------------------------------------
  341. # casket / lid / cover, all the same ...
  342. #------------------------------------------------------------------------------------
  343. #------------------------------------------------------------------------------------
  344. #------------------------------------------------------------------------------------
  345. def CloseCasket(self):
  346. #----------------------------------------------------------------
  347. # check if already closed (coverclosed)
  348. # check if opened (coveropened)
  349. # if both are true or both are false ... we have a problem ...
  350. #----------------------------------------------------------------
  351. iscoveropened = self.CheckDIN("coveropened", True)
  352. iscoverclosed = self.CheckDIN("coverclosed", False)
  353. if iscoveropened == 1 and iscoverclosed == 1:
  354. print("We have a problem, cover is opened and closed")
  355. return -1
  356. if iscoveropened == 0 and iscoverclosed == 0:
  357. print("We have a problem, cover is not opened and not closed")
  358. return -2
  359. if iscoverclosed == 1: # already closed
  360. print("Cover already closed")
  361. return 0
  362. #----------------------------------------------------------------
  363. # before closing, make sure no pockets are raised by droping them
  364. #----------------------------------------------------------------
  365. DropAllPockets()
  366. #------------------------------------------------------------------------------
  367. # send 0 to the opencover pin
  368. #------------------------------------------------------------------------------
  369. SendDOUT("opencover", 0) # setting to 1 close it ?
  370. #------------------------------------------------------------------------------
  371. # send 1 to the closecover pin
  372. #------------------------------------------------------------------------------
  373. SendDOUT("closecover", 1) # setting to 1 opens it ?
  374. time.sleep(self.pulseDelay) # Pulse signal
  375. SendDOUT("closecover", 0) # setting to 1 opens it ?
  376. #-------------------------------
  377. #wait a certain delay
  378. #-------------------------------
  379. time.sleep(self.coverDelay)
  380. #-------------------------------
  381. # then check if closed
  382. #-------------------------------
  383. iscoveropened = self.CheckDIN("coveropened", True)
  384. iscoverclosed = self.CheckDIN("coverclosed", False)
  385. if iscoveropened == 1 and iscoverclosed == 1:
  386. print("We have a problem, cover is opened and closed")
  387. return -3
  388. if iscoveropened == 0 and iscoverclosed == 0:
  389. print("We have a problem, cover is not opened and not closed")
  390. return -4
  391. if iscoverclosed == 1: # closed
  392. print("Cover Closed")
  393. return 0
  394. else:
  395. print("Not closed yet ... coverDelay too short ?")
  396. return -5
  397. #----------------------------------------------------------
  398. #----------------------------------------------------------
  399. def OpenCasket(self):
  400. #----------------------------------------------------------------
  401. # check if closed (coverclosed)
  402. # check if opened (coveropened)
  403. # if both are true or both are false ... we have a problem ...
  404. #----------------------------------------------------------------
  405. iscoveropened = self.CheckDIN("coveropened", True)
  406. iscoverclosed = self.CheckDIN("coverclosed", False)
  407. if iscoveropened == 1 and iscoverclosed == 1:
  408. print("We have a problem, cover is opened and closed")
  409. return -6
  410. if iscoveropened == 0 and iscoverclosed == 0:
  411. print("We have a problem, cover is not opened and not closed")
  412. return -7
  413. if iscoveropened == 1: # already opened
  414. print("Cover already opened")
  415. return 0
  416. #----------------------------------------------------------
  417. # Just send a 0 to the digital output of closecover
  418. #----------------------------------------------------------
  419. SendDOUT("closecover", 0)
  420. #----------------------------------------------------------
  421. # Now send a pulse to the digital output of opencover
  422. #----------------------------------------------------------
  423. SendDOUT("opencover", 1)
  424. time.sleep(self.pulseDelay) # Pulse signal
  425. SendDOUT("opencover", 0)
  426. #---------------------------------------
  427. #wait and check if opened
  428. #---------------------------------------
  429. time.sleep(self.coverDelay)
  430. #---------------------------------------
  431. # verify it is opened
  432. #---------------------------------------
  433. iscoveropened = self.CheckDIN("coveropened", True)
  434. iscoverclosed = self.CheckDIN("coverclosed", False)
  435. #---------------------------------------
  436. #if both are true ... error, if both are false ... error
  437. #if coveropened = false .. loop ? or raise error ?
  438. #---------------------------------------
  439. if iscoveropened == 1 and iscoverclosed == 1:
  440. print("We have a problem, cover is opened and closed")
  441. return -8
  442. if iscoveropened == 0 and iscoverclosed == 0:
  443. print("We have a problem, cover is not opened and not closed, coverDelay too small ?")
  444. return -9
  445. # Is it opened ?
  446. if iscoveropened == 1: # opened
  447. return 0
  448. else:
  449. print("Not opened, we have a problem ... coverDelay too small ?")
  450. return -10 # not opened we have a problem
  451.  
  452. #------------------------------------------------------------------------------------
  453. #------------------------------------------------------------------------------------
  454. #------------------------------------------------------------------------------------
  455. # SPINDLE
  456. #------------------------------------------------------------------------------------
  457. #------------------------------------------------------------------------------------
  458. #------------------------------------------------------------------------------------
  459.  
  460. #----------------------------------------------------------
  461. # M5 command to stop the spindle
  462. #----------------------------------------------------------
  463. def StopSpindleNow(self):
  464. self.command.mdi("M5") #, lineno())
  465.  
  466. #----------------------------------------------------------
  467. #----------------------------------------------------------
  468. def WaitForSpindleToStop(self):
  469. #--------------------------------------------------
  470. # test if spindleHasStopped = True:
  471. # if not, wait a certain delay, a certain max time
  472. #--------------------------------------------------
  473. if self.isSpindleReallyStopped():
  474. return True
  475. #---------------------------------------------
  476. # if not stopped, send a M5 command to stop it
  477. # wait a certain delay
  478. #---------------------------------------------
  479. self.StopSpindleNow()
  480. stopDelay, maxTrials = self.x.getSpindleStopDelay()
  481. time.sleep(stopDelay)
  482. #---------------------------------------------
  483. # then check again if it has stopped
  484. #---------------------------------------------
  485. for i in range(1, maxTrials +1):
  486. if self.isSpindleReallyStopped():
  487. return True
  488. time.sleep(stopDelay)
  489. #--------------------------------------------------------
  490. # waited maxTrials * stopDelay seconds, still not stopped
  491. #--------------------------------------------------------
  492. return False
  493.  
  494. #----------------------------------------------------------
  495. #----------------------------------------------------------
  496. def isSpindleReallyStopped(self):
  497. isSpindleStopped = self.CheckDIN("spindleHasStopped", True)
  498. print("isSpindleStopped = %s" % isSpindleStopped)
  499. if isSpindleStopped == 0:
  500. return True
  501. else:
  502. return False
  503.  
  504. #----------------------------------------------------------
  505. # raising all spindles ... to make sure they are all raised
  506. #----------------------------------------------------------
  507. def raiseALLspindles(self):
  508. #------------------------------
  509. # loop through all spindles
  510. #------------------------------
  511. #------------------------------------------------
  512. # check first if all spindle are already up
  513. #------------------------------------------------
  514. isSpindleALLup = self.CheckDIN("spindleALLup", True)
  515. if isSpindleALLup == 0:
  516. # nope some are down, so put them all up
  517. validSpindle = ("A", "B", "C")
  518. for i in validSpindle:
  519. self.RaiseSpindle(i)
  520. #------------------------------
  521. # loop through all drills
  522. #------------------------------
  523. firstIndex = self.x.getFirstIndex("Drills")
  524. for i in range(firstIndex, 34, 1):
  525. self.RaiseDrill(i)
  526. #------------------------------
  527. # loop through all side drills
  528. #------------------------------
  529. for i in range(1, 11, 2):
  530. self.RaiseSideDrill(i)
  531.  
  532. #----------------------------------------------------------
  533. #----------------------------------------------------------
  534. def DropSpindle(self,sWhich):
  535. SendDOUT("spindle%srise" % sWhich, 0) # setting to 0 drops it ?
  536. SendDOUT("spindle%sdown" % sWhich, 1) # setting to 1 drops it ?
  537.  
  538. #----------------------------------------------------------
  539. #----------------------------------------------------------
  540. def RaiseSpindle(self,sWhich):
  541. SendDOUT("spindle%sdrop" % sWhich, 0) # setting to 0 to raises it ?
  542. SendDOUT("spindle%srise" % sWhich, 1) # setting to 1 to raises it ?
  543.  
  544. #----------------------------------------------------------
  545. #----------------------------------------------------------
  546. def EnergiseSpindle(self, sWhich):
  547. SendDOUT("spindle%senergise" % sWhich, 1) # setting to 1 to select it ?
  548.  
  549. #----------------------------------------------------------
  550. #----------------------------------------------------------
  551. def ReleaseSpindle(self, sWhich): # pulsed signal
  552. #---------------------------------------------------------------------------
  553. # Send the signal to release the spindle
  554. #---------------------------------------------------------------------------
  555. SendDOUT("spindle%srelease" % sWhich, 1) # Pulse signal
  556. time.sleep(self.pulseDelay) # Pulse signal
  557. SendDOUT("spindle%srelease" % sWhich, 0) # Pulse signal
  558. #---------------------------------------------------------------------------
  559. # check if spindle is released
  560. #---------------------------------------------------------------------------
  561. isSpindleReleased = self.CheckDIN("spindle%sreleased" % sWhich, True)
  562. #---------------------------------------------------------------------------
  563. # if not wait a certain delay and if after delay, still not released, error
  564. #---------------------------------------------------------------------------
  565. if not isSpindleReleased:
  566. time.sleep(self.actuationDelay)
  567. isSpindleReleased = self.CheckDIN("spindle%sreleased" % sWhich, True)
  568. if not isSpindleReleased:
  569. return False
  570. return True
  571.  
  572. #----------------------------------------------------------
  573. #----------------------------------------------------------
  574. def LockSpindle(self, sWhich): #pulsed signal
  575. SendDOUT("spindle%slock" % sWhich, 1) # Pulse signal
  576. time.sleep(self.pulseDelay) # Pulse signal
  577. SendDOUT("spindle%slock" % sWhich, 0) # Pulse signal
  578.  
  579. #----------------------------------------------------------
  580. #----------------------------------------------------------
  581. def SpindleHasTool(self, sWhich):
  582. doesSpindleReleased = self.CheckDIN("spindle%shastool" % sWhich, True)
  583. if doesSpindleReleased == 0:
  584. return False
  585. else:
  586. return True
  587.  
  588. #------------------------------------------------------------------------------------
  589. #------------------------------------------------------------------------------------
  590. #------------------------------------------------------------------------------------
  591. # DRILLS
  592. #------------------------------------------------------------------------------------
  593. #------------------------------------------------------------------------------------
  594. #------------------------------------------------------------------------------------
  595. def DropDrill(self, sWhich):
  596. SendDOUT("spindle%ddrop" % sWhich, 1) # setting to 1 to drop ?
  597.  
  598. #----------------------------------------------------------
  599. #----------------------------------------------------------
  600. def RaiseDrill(self, sWhich):
  601. SendDOUT("spindle%ddrop" % sWhich, 1) # setting to 0 to raise
  602.  
  603. #------------------------------------------------------------------------------------
  604. #------------------------------------------------------------------------------------
  605. #------------------------------------------------------------------------------------
  606. # SIDE DRILLS
  607. #------------------------------------------------------------------------------------
  608. #------------------------------------------------------------------------------------
  609. #------------------------------------------------------------------------------------
  610. def DropSideDrill(self, sWhich):
  611. SendDOUT("spindle%dand%ddrop" % (int(sWhich), int(sWhich) + 1), 1) # setting to 1 to drop ?
  612.  
  613. #----------------------------------------------------------
  614. #----------------------------------------------------------
  615. def RaiseSideDrill(self, sWhich):
  616. SendDOUT("spindle%dand%ddrop" % (int(sWhich), int(sWhich) + 1), 0) # setting to 0 to raise ?
  617.  
  618. #------------------------------------------------------------------------------------
  619. #------------------------------------------------------------------------------------
  620. #------------------------------------------------------------------------------------
  621. # POCKETS
  622. #------------------------------------------------------------------------------------
  623. #------------------------------------------------------------------------------------
  624. #------------------------------------------------------------------------------------
  625. def DropAllPockets(self):
  626. for i in range (1, 4, 1):
  627. SendDOUT("raisepocket%d" % i, 0) # setting to 1 to drop ?
  628.  
  629. #----------------------------------------------------------
  630. #----------------------------------------------------------
  631. def LowerPocket(self,sWhich):
  632. SendDOUT("raisepocket%d" % sWhich, 0) # setting to 1 to drop ?
  633.  
  634. #----------------------------------------------------------
  635. #----------------------------------------------------------
  636. def RaisePocket(self, sWhich): # send output signal to raise pocket (hold)
  637. SendDOUT("raisepocket%d" % sWhich, 1) # setting to 1 to raise it ?
  638.  
  639. #----------------------------------------------------------
  640. #----------------------------------------------------------
  641. def FindFreePocket(self):
  642. #----------------------------------------------------------------
  643. # for each pocket defined, check if it has a tool
  644. # if pocket does not have a tool, return that pocket number
  645. #----------------------------------------------------------------
  646. #---------------------------------
  647. # Query stat digital input status
  648. #---------------------------------
  649. pocket1hastool = self.CheckDIN("pocket1hastool", True)
  650. pocket2hastool = self.CheckDIN("pocket1hastoo2", False)
  651. pocket3hastool = self.CheckDIN("pocket1hastoo3", False)
  652. print("%s - %s - %s" % (pocket1hastool, pocket2hastool, pocket3hastool))
  653. if pocket1hastool == 0:
  654. if pocket2hastool == 0:
  655. if pocket3hastool == 0:
  656. return -1 # all pockets have something
  657. else:
  658. return 3
  659. else:
  660. return 2
  661. else:
  662. return 1
  663.  
  664. #----------------------------------------------------------
  665. #----------------------------------------------------------
  666. def FindToolPocket(toolid):
  667. # from the toolid (1,2,3) find the toolpocket (1,2,3)
  668. return toolid
  669.  
  670. #------------------------------------------------------------------------------------
  671. #------------------------------------------------------------------------------------
  672. #------------------------------------------------------------------------------------
  673. # MOVEMENTS
  674. #------------------------------------------------------------------------------------
  675. #------------------------------------------------------------------------------------
  676. #------------------------------------------------------------------------------------
  677. #
  678. # This section interacts with G-Code using Python
  679. #
  680. #----------------------------------------------------------
  681. #----------------------------------------------------------
  682. def MoveToFrontOfPocket(self, id):
  683. # fetch the front position of said pocket in the xml file
  684. # go to that position in machine coordinates
  685. posX, posY, posZ = self.x.getPocketPos(id, "Front")
  686. self.command.mdi("G53 F%d X%f Y%f Z0.0" % (self.feedSpeed, posX, posY)) #,lineno())
  687. self.command.mdi("G53 F%d Z%f" % (self.feedSpeed, posZ)) #,lineno())
  688.  
  689. #----------------------------------------------------------
  690. #----------------------------------------------------------
  691. def MoveToTopOfPocket(self, id):
  692. # fetch the top position of said pocket in the xml file
  693. # go to that position in machine coordinates
  694. posX, posY, posZ = self.x.getPocketPos(id, "Top")
  695. self.command.mdi("G53 F%d X%f Y%f Z0.0" % (self.feedSpeed, posX, posY)) #,lineno())
  696. self.command.mdi("G53 F%d Z%f" % (self.feedSpeed, posZ)) #,lineno())
  697.  
  698. #----------------------------------------------------------
  699. #----------------------------------------------------------
  700. def MoveIntoOrOutOfPocket(self, id, direction): # either "INTO" or "OUT"
  701. # this requires a length ... found in the XML using getMoveDistance() (NOT)
  702. # this could be calculated ... or do we simply move the the FRONT pos ...
  703. # going to the FRONT position is ok to move OUT, but not for move INTO
  704. # going INTO, simply move to Top Y position, and Front X and Z
  705. posX, posY, posZ = self.x.getPocketPos(id, "Front")
  706. if direction == "INTO": # moving into is moving to the Top X position
  707. posX2, posY2, posZ2 = self.x.getPocketPos(id, "Top")
  708. self.command.mdi("G53 F%d X%f " % (self.feedSpeed, posX2)) #,lineno())
  709. else: # moving out is simply going to Front position
  710. self.command.mdi("G53 F%d X%f " % (self.feedSpeed, posX)) #,lineno())
  711. self.command.mdi("G53 F%d Z0.0 " % self.feedSpeed) #,lineno())
  712.  
  713. #----------------------------------------------------------
  714. #----------------------------------------------------------
  715. def CheckDIN(self, sWhich, doPoll):
  716. index = self.x.getSignalInfos(sWhich)
  717. if doPoll:
  718. self.stat.poll()
  719. return(int(self.stat.din[index])
  720.  
  721. #----------------------------------------------------------
  722. #----------------------------------------------------------
  723. def SendDOUT(sWhich, val)
  724. index = self.x.getSignalInfos(sWhich)
  725. self.command.set_digital_output(index, int(val))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement