Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- #
- #-----------------------------------------------------------------------------------
- import linuxcnc
- from interpreter import *
- from emccanon import MESSAGE, SET_MOTION_OUTPUT_BIT, CLEAR_MOTION_OUTPUT_BIT,SET_AUX_OUTPUT_BIT,CLEAR_AUX_OUTPUT_BIT
- #from util import lineno
- #-----------------------------------------------------------------------------------
- throw_exceptions = 1 # raises InterpreterException if execute() or read() fail
- #-----------------------------------------------------------------------------------
- #import TopLevel # Needed ?
- from stdglue import change_prolog, change_epilog, init_stdglue # done in TopLevel.py ...
- import xmlBiesse
- import time
- import sys
- #-------------------------------------------------------------------------------------------
- # MAIN FUNCTION : change_remap
- #
- # from REMAP=M6 modalgroup=6 prolog=change_prolog python=change_remap epilog=change_epilog
- # - change_prolog and change_epilog are in stdglue.py
- #-------------------------------------------------------------------------------------------
- #------------------------------------------------------------------
- # MAIN ALGO
- #------------------------------------------------------------------
- # param : selected tool
- #
- # in machine coordinates
- #
- # raise all spindles ... drills ... side drills ... DONE raiseALLspindles()
- #
- # selectedtool = int(self.params["selected_tool"])
- # if selectedtool > 500:
- # drop Side Drill selectedtool - 500 DONE DropSideDrill(i)
- # elif (selectedtool > 400 and selectedtool < 500):
- # drop Drill selectedtool - 400 DONE DropDrill(i)
- # else:
- # if selectedtool = 11:
- # drop spindle C DONE DropSpindle("C")
- # Energise spindle C DONE EnergiseSpindle("C")
- # return INTERP_OK DONE
- # elif selectedtool = 10:
- # drop spindle B DONE DropSpindle("B")
- # Energise spindle B DONE EnergiseSpindle("B")
- # return INTERP_OK DONE
- # elif selectedtool > 0 and selectedtool < 4: #only 3 tools for A
- # Energise spindle A DONE EnergiseSpindle("A")
- # # now time to see if already in spindle
- # find free pocket DONE FindFreePocket()
- # if free pocket number is equal to selectedtool then already in spindle,
- # drop spindle A DONE DropSpindle("A")
- # return INTERP_OK DONE
- #------------------------------------------------------------------
- # # not in spindle
- #
- # #Energise spindle A DONE EnergiseSpindle("A")
- #
- # If not found
- # DROP current tool in free pocket
- # make sure casket is opened WorkingOnIt
- # find free pocket DONE FindFreePocket
- # move to FRONT of said pocked TBD1
- # raise said pocket DONE RaisePocket(i)
- # Drop Spindle 1 DONE DropSpindle("A")
- # move INTO said pocket TBD2 MoveIntoOrOutOfPocket
- # release tool DONE ReleaseSpindle("A")
- # raise spindle 1 DONE RaiseSpindle("A")
- # move back to FRONT of said pocket TBD1
- # lower said pocket DONE LowerPocket(i)
- #
- # PICKUP selected tool in according pocket
- # make sure casket is opened WorkingOnIt
- # find in which pocket is the tool DONE FindToolPocket(i)
- # move to TOP of said pocket TBD3
- # raise said pocket DONE RaisePocket(i)
- # unlock spindle 1 (should be) DONE ReleaseSpindle("A")
- # drop spindle 1 DONE DropSpindle("A")
- # lock spindle 1 DONE LockSpindle("A")
- # move OUT of said pocket TBD2 MoveIntoOrOutOfPocket
- # lower said pocket DONE LowerPocket(i)
- # close casket DONE CloseCasket
- #
- # when done, change the world coordinate system to reflect the new offsets for the selected spindle
- # (G10 L20 X0 Y0 Z0) ...
- #
- #
- #
- #
- #
- #
- #
- #
- #------------------------------------------------------------------
- #------------------------------------------------------------------
- def change_remap(self, **words):
- for key in words:
- MESSAGE("word '%s' = %f" % (key, words[key]))
- if words.has_key('p'):
- MESSAGE("the P word was present")
- if words.has_key('q'):
- MESSAGE("the Q word was present")
- # check if parameters are needed here ....
- #print(pi()) # to test if available with TopLevel.py ...
- try:
- #---------------------------------------------------------------------
- # XML - Objects to fetch needed infos ...
- #---------------------------------------------------------------------
- xBiesse = xmlBiesse.xmlBiesse() # the xml interface
- api = clsAPI(xBiesse) # the utility functions defined below
- #---------------------------------------------------------------------
- # check for spindleHasStopped if not raise error WaitForSpindleToStop
- if api.WaitForSpindleToStop() == False:
- msg = "Spindle Motor is not stopped"
- self.set_errormsg(msg) # replace builtin error message
- return INTERP_ERROR
- #------------------------------------------------------------------
- # we are good to go
- #------------------------------------------------------------------
- api.raiseALLspindles()
- selectedtool = int(self.params["selected_tool"])
- if selectedtool > 500:
- api.DropSideDrill(selectedtool - 500)
- elif (selectedtool > 400 and selectedtool < 500):
- api.DropDrill(selectedtool - 400)
- else:
- if selectedtool == 11:
- if api.SpindleHasTool("C"):
- api.DropSpindle("C")
- api.EnergiseSpindle("C")
- return INTERP_OK
- else:
- msg = "Spindle C has no tool"
- self.set_errormsg(msg)
- return INTERP_ERROR
- elif selectedtool == 10:
- if api.SpindleHasTool("B"):
- api.DropSpindle("B")
- api.EnergiseSpindle("B")
- return INTERP_OK
- else:
- msg = "Spindle B has no tool"
- self.set_errormsg(msg)
- return INTERP_ERROR
- elif selectedtool > 0 and selectedtool < 4: #only 3 tools for A (1, 2, 3)
- api.EnergiseSpindle("A")
- # now time to see if already in spindle
- freePocket = api.FindFreePocket()
- print("freePocket = %s" % freePocket)
- currenttool = int(self.params["tool_in_spindle"])
- if freePocket == -1:
- # what is in spindle 1 ? check if spindle has tool
- if api.SpindleHasTool("A"): # we have a problem
- msg = "No Free Pockets and Spindle A has a tool"
- self.set_errormsg(msg)
- return INTERP_ERROR
- else: # if not, go get the one needed
- #------------------------------------------
- # PICKUP selected tool in according pocket
- #------------------------------------------
- res = PickUpNewTool(selectedtool, api)
- if res != 0:
- msg = "Error while picking up a new tool, err number: %d" % res
- self.set_errormsg(msg) # replace builtin error message
- return INTERP_ERROR
- else:
- #------------------------------------
- # DROP current tool in free pocket
- #------------------------------------
- # check if spindle has tool
- if not api.SpindleHasTool("A"):
- msg = "Error while droping a tool, Spindle A has no tool to drop"
- self.set_errormsg(msg) # replace builtin error message
- return INTERP_ERROR
- res = DropCurrentTool(currenttool, freePocket, api)
- if res != 0:
- msg = "Error while droping the current tool, err number: %d" % res
- self.set_errormsg(msg) # replace builtin error message
- return INTERP_ERROR
- #------------------------------------------
- # PICKUP selected tool in according pocket
- #------------------------------------------
- res = PickUpNewTool(selectedtool, api)
- if res != 0:
- msg = "Error while picking up a new tool, err number: %d" % res
- self.set_errormsg(msg) # replace builtin error message
- return INTERP_ERROR
- elif selectedtool == 0:
- freePocket = api.FindFreePocket()
- print("freePocket = %s" % freePocket)
- currenttool = int(self.params["tool_in_spindle"])
- if freePocket == -1:
- if api.SpindleHasTool("A"): # we have a problem
- msg = "T0 M6: Error, No Free Pockets and Spindle A has a tool"
- self.set_errormsg(msg)
- return INTERP_ERROR
- else: # if not, do nothing, M0 is to remove a tool, which is absent
- pass
- else:
- if api.SpindleHasTool("A"): # We have a tool to drop
- res = DropCurrentTool(currenttool, freePocket, api)
- if res != 0:
- msg = "T0 M6: Error while droping the current tool, err number: %d" % res
- self.set_errormsg(msg) # replace builtin error message
- return INTERP_ERROR
- else:
- pass
- else:
- msg = "Wrong tool number either 0 to remove it from spindle or 1,2,3. Tool given: %d" % selectedtool
- self.set_errormsg(msg) # replace builtin error message
- return INTERP_ERROR
- #-----------------------------------------
- # We have errors ! catch and return error
- #-----------------------------------------
- except InterpreterException,e:
- msg = "%d: '%s' - %s" % (e.line_number,e.line_text, e.error_message)
- self.set_errormsg(msg) # replace builtin error message
- return INTERP_ERROR
- except IOError as e:
- print "I/O error({0}): {1}".format(e.errno, e.strerror)
- return INTERP_ERROR
- except ValueError:
- print "Could not convert data to an integer."
- return INTERP_ERROR
- except ZeroDivisionError as detail:
- print 'Handling run-time error:', detail
- return INTERP_ERROR
- except:
- print "Unexpected error:", sys.exc_info()[0]
- raise
- finally:
- print 'Finally, have a nice day!'
- #-----------------------
- # all fine, return ok !
- #-----------------------
- return INTERP_OK
- #----------------------------------------------------------
- #----------------------------------------------------------
- def DropCurrentTool(sWhere, api): #(sWhere = 1,2,3)
- #----------------------------------------
- # Open the cover
- #----------------------------------------
- isCasketOpened = api.OpenCasket()
- if isCasketOpened != 0:
- return isCasketOpened #(-6,-7,-8,-9,-10)
- #----------------------------------------
- # move to front, Raise pocket, Drop,
- # move into, release
- #----------------------------------------
- api.MoveToFrontOfPocket(sWhere)
- api.RaisePocket(sWhere)
- api.DropSpindle("A")
- api.MoveIntoOrOutOfPocket(sWhere, "INTO")
- api.ReleaseSpindle("A")
- #----------------------------------------
- # verify that the spindle has no tool ...
- #----------------------------------------
- if api.SpindleHasTool("A"):
- return -1
- #----------------------------------------
- # Raise, move out, lower pocket
- #----------------------------------------
- api.RaiseSpindle("A")
- api.LowerPocket(sWhere)
- api.MoveIntoOrOutOfPocket(sWhere, "OUT")
- return 0
- #----------------------------------------------------------
- #----------------------------------------------------------
- def PickUpNewTool(sWhich, api):
- #----------------------------------------
- # Open the cover, should already be ...
- #----------------------------------------
- isCasketOpened = api.OpenCasket()
- if isCasketOpened != 0:
- return isCasketOpened #(-6,-7,-8,-9,-10)
- #------------------------------------------
- # go to top of tool pocket, raise pocket,
- # quick release (shoud be done), Drop, Lock
- #------------------------------------------
- pocket = api.FindToolPocket(sWhich)
- api.MoveToTopOfPocket(pocket)
- api.ReleaseSpindle("A")
- api.RaisePocket(pocket)
- api.DropSpindle("A")
- api.LockSpindle("A")
- #----------------------------------------
- # verify that the spindle has a tool ...
- #----------------------------------------
- if not api.SpindleHasTool("A"):
- return -1
- #----------------------------------------
- # Move out and lower pocket
- #----------------------------------------
- api.MoveIntoOrOutOfPocket(pocket, "OUT")
- api.LowerPocket(pocket)
- #----------------------------------------
- # close the cover
- #----------------------------------------
- isCasketClosed = api.CloseCasket()
- if isCasketClosed != 0:
- return isCasketClosed #(-1,-2, -3, -4, -5)
- else:#
- return 0
- #------------------------------------------------------------------
- # Utility class clsAPI - has the details of xml and stat
- #------------------------------------------------------------------
- class clsAPI(object):
- def __init__(self, x):
- self.x = x
- self.cnc = linuxcnc
- self.stat = self.cnc.stat()
- self.command = self.cnc.command()
- self.pulseDelay = self.x.getPulseDelay()
- self.coverDelay = self.x.getCoverDelay()
- self.actuationDelay = self.x.getActuationDelay()
- self.feedSpeed = self.x.getFeedSpeed()
- #------------------------------------------------------------------------------------
- #------------------------------------------------------------------------------------
- #------------------------------------------------------------------------------------
- # casket / lid / cover, all the same ...
- #------------------------------------------------------------------------------------
- #------------------------------------------------------------------------------------
- #------------------------------------------------------------------------------------
- def CloseCasket(self):
- #----------------------------------------------------------------
- # check if already closed (coverclosed)
- # check if opened (coveropened)
- # if both are true or both are false ... we have a problem ...
- #----------------------------------------------------------------
- iscoveropened = self.CheckDIN("coveropened", True)
- iscoverclosed = self.CheckDIN("coverclosed", False)
- if iscoveropened == 1 and iscoverclosed == 1:
- print("We have a problem, cover is opened and closed")
- return -1
- if iscoveropened == 0 and iscoverclosed == 0:
- print("We have a problem, cover is not opened and not closed")
- return -2
- if iscoverclosed == 1: # already closed
- print("Cover already closed")
- return 0
- #----------------------------------------------------------------
- # before closing, make sure no pockets are raised by droping them
- #----------------------------------------------------------------
- DropAllPockets()
- #------------------------------------------------------------------------------
- # send 0 to the opencover pin
- #------------------------------------------------------------------------------
- SendDOUT("opencover", 0) # setting to 1 close it ?
- #------------------------------------------------------------------------------
- # send 1 to the closecover pin
- #------------------------------------------------------------------------------
- SendDOUT("closecover", 1) # setting to 1 opens it ?
- time.sleep(self.pulseDelay) # Pulse signal
- SendDOUT("closecover", 0) # setting to 1 opens it ?
- #-------------------------------
- #wait a certain delay
- #-------------------------------
- time.sleep(self.coverDelay)
- #-------------------------------
- # then check if closed
- #-------------------------------
- iscoveropened = self.CheckDIN("coveropened", True)
- iscoverclosed = self.CheckDIN("coverclosed", False)
- if iscoveropened == 1 and iscoverclosed == 1:
- print("We have a problem, cover is opened and closed")
- return -3
- if iscoveropened == 0 and iscoverclosed == 0:
- print("We have a problem, cover is not opened and not closed")
- return -4
- if iscoverclosed == 1: # closed
- print("Cover Closed")
- return 0
- else:
- print("Not closed yet ... coverDelay too short ?")
- return -5
- #----------------------------------------------------------
- #----------------------------------------------------------
- def OpenCasket(self):
- #----------------------------------------------------------------
- # check if closed (coverclosed)
- # check if opened (coveropened)
- # if both are true or both are false ... we have a problem ...
- #----------------------------------------------------------------
- iscoveropened = self.CheckDIN("coveropened", True)
- iscoverclosed = self.CheckDIN("coverclosed", False)
- if iscoveropened == 1 and iscoverclosed == 1:
- print("We have a problem, cover is opened and closed")
- return -6
- if iscoveropened == 0 and iscoverclosed == 0:
- print("We have a problem, cover is not opened and not closed")
- return -7
- if iscoveropened == 1: # already opened
- print("Cover already opened")
- return 0
- #----------------------------------------------------------
- # Just send a 0 to the digital output of closecover
- #----------------------------------------------------------
- SendDOUT("closecover", 0)
- #----------------------------------------------------------
- # Now send a pulse to the digital output of opencover
- #----------------------------------------------------------
- SendDOUT("opencover", 1)
- time.sleep(self.pulseDelay) # Pulse signal
- SendDOUT("opencover", 0)
- #---------------------------------------
- #wait and check if opened
- #---------------------------------------
- time.sleep(self.coverDelay)
- #---------------------------------------
- # verify it is opened
- #---------------------------------------
- iscoveropened = self.CheckDIN("coveropened", True)
- iscoverclosed = self.CheckDIN("coverclosed", False)
- #---------------------------------------
- #if both are true ... error, if both are false ... error
- #if coveropened = false .. loop ? or raise error ?
- #---------------------------------------
- if iscoveropened == 1 and iscoverclosed == 1:
- print("We have a problem, cover is opened and closed")
- return -8
- if iscoveropened == 0 and iscoverclosed == 0:
- print("We have a problem, cover is not opened and not closed, coverDelay too small ?")
- return -9
- # Is it opened ?
- if iscoveropened == 1: # opened
- return 0
- else:
- print("Not opened, we have a problem ... coverDelay too small ?")
- return -10 # not opened we have a problem
- #------------------------------------------------------------------------------------
- #------------------------------------------------------------------------------------
- #------------------------------------------------------------------------------------
- # SPINDLE
- #------------------------------------------------------------------------------------
- #------------------------------------------------------------------------------------
- #------------------------------------------------------------------------------------
- #----------------------------------------------------------
- # M5 command to stop the spindle
- #----------------------------------------------------------
- def StopSpindleNow(self):
- self.command.mdi("M5") #, lineno())
- #----------------------------------------------------------
- #----------------------------------------------------------
- def WaitForSpindleToStop(self):
- #--------------------------------------------------
- # test if spindleHasStopped = True:
- # if not, wait a certain delay, a certain max time
- #--------------------------------------------------
- if self.isSpindleReallyStopped():
- return True
- #---------------------------------------------
- # if not stopped, send a M5 command to stop it
- # wait a certain delay
- #---------------------------------------------
- self.StopSpindleNow()
- stopDelay, maxTrials = self.x.getSpindleStopDelay()
- time.sleep(stopDelay)
- #---------------------------------------------
- # then check again if it has stopped
- #---------------------------------------------
- for i in range(1, maxTrials +1):
- if self.isSpindleReallyStopped():
- return True
- time.sleep(stopDelay)
- #--------------------------------------------------------
- # waited maxTrials * stopDelay seconds, still not stopped
- #--------------------------------------------------------
- return False
- #----------------------------------------------------------
- #----------------------------------------------------------
- def isSpindleReallyStopped(self):
- isSpindleStopped = self.CheckDIN("spindleHasStopped", True)
- print("isSpindleStopped = %s" % isSpindleStopped)
- if isSpindleStopped == 0:
- return True
- else:
- return False
- #----------------------------------------------------------
- # raising all spindles ... to make sure they are all raised
- #----------------------------------------------------------
- def raiseALLspindles(self):
- #------------------------------
- # loop through all spindles
- #------------------------------
- #------------------------------------------------
- # check first if all spindle are already up
- #------------------------------------------------
- isSpindleALLup = self.CheckDIN("spindleALLup", True)
- if isSpindleALLup == 0:
- # nope some are down, so put them all up
- validSpindle = ("A", "B", "C")
- for i in validSpindle:
- self.RaiseSpindle(i)
- #------------------------------
- # loop through all drills
- #------------------------------
- firstIndex = self.x.getFirstIndex("Drills")
- for i in range(firstIndex, 34, 1):
- self.RaiseDrill(i)
- #------------------------------
- # loop through all side drills
- #------------------------------
- for i in range(1, 11, 2):
- self.RaiseSideDrill(i)
- #----------------------------------------------------------
- #----------------------------------------------------------
- def DropSpindle(self,sWhich):
- SendDOUT("spindle%srise" % sWhich, 0) # setting to 0 drops it ?
- SendDOUT("spindle%sdown" % sWhich, 1) # setting to 1 drops it ?
- #----------------------------------------------------------
- #----------------------------------------------------------
- def RaiseSpindle(self,sWhich):
- SendDOUT("spindle%sdrop" % sWhich, 0) # setting to 0 to raises it ?
- SendDOUT("spindle%srise" % sWhich, 1) # setting to 1 to raises it ?
- #----------------------------------------------------------
- #----------------------------------------------------------
- def EnergiseSpindle(self, sWhich):
- SendDOUT("spindle%senergise" % sWhich, 1) # setting to 1 to select it ?
- #----------------------------------------------------------
- #----------------------------------------------------------
- def ReleaseSpindle(self, sWhich): # pulsed signal
- #---------------------------------------------------------------------------
- # Send the signal to release the spindle
- #---------------------------------------------------------------------------
- SendDOUT("spindle%srelease" % sWhich, 1) # Pulse signal
- time.sleep(self.pulseDelay) # Pulse signal
- SendDOUT("spindle%srelease" % sWhich, 0) # Pulse signal
- #---------------------------------------------------------------------------
- # check if spindle is released
- #---------------------------------------------------------------------------
- isSpindleReleased = self.CheckDIN("spindle%sreleased" % sWhich, True)
- #---------------------------------------------------------------------------
- # if not wait a certain delay and if after delay, still not released, error
- #---------------------------------------------------------------------------
- if not isSpindleReleased:
- time.sleep(self.actuationDelay)
- isSpindleReleased = self.CheckDIN("spindle%sreleased" % sWhich, True)
- if not isSpindleReleased:
- return False
- return True
- #----------------------------------------------------------
- #----------------------------------------------------------
- def LockSpindle(self, sWhich): #pulsed signal
- SendDOUT("spindle%slock" % sWhich, 1) # Pulse signal
- time.sleep(self.pulseDelay) # Pulse signal
- SendDOUT("spindle%slock" % sWhich, 0) # Pulse signal
- #----------------------------------------------------------
- #----------------------------------------------------------
- def SpindleHasTool(self, sWhich):
- doesSpindleReleased = self.CheckDIN("spindle%shastool" % sWhich, True)
- if doesSpindleReleased == 0:
- return False
- else:
- return True
- #------------------------------------------------------------------------------------
- #------------------------------------------------------------------------------------
- #------------------------------------------------------------------------------------
- # DRILLS
- #------------------------------------------------------------------------------------
- #------------------------------------------------------------------------------------
- #------------------------------------------------------------------------------------
- def DropDrill(self, sWhich):
- SendDOUT("spindle%ddrop" % sWhich, 1) # setting to 1 to drop ?
- #----------------------------------------------------------
- #----------------------------------------------------------
- def RaiseDrill(self, sWhich):
- SendDOUT("spindle%ddrop" % sWhich, 1) # setting to 0 to raise
- #------------------------------------------------------------------------------------
- #------------------------------------------------------------------------------------
- #------------------------------------------------------------------------------------
- # SIDE DRILLS
- #------------------------------------------------------------------------------------
- #------------------------------------------------------------------------------------
- #------------------------------------------------------------------------------------
- def DropSideDrill(self, sWhich):
- SendDOUT("spindle%dand%ddrop" % (int(sWhich), int(sWhich) + 1), 1) # setting to 1 to drop ?
- #----------------------------------------------------------
- #----------------------------------------------------------
- def RaiseSideDrill(self, sWhich):
- SendDOUT("spindle%dand%ddrop" % (int(sWhich), int(sWhich) + 1), 0) # setting to 0 to raise ?
- #------------------------------------------------------------------------------------
- #------------------------------------------------------------------------------------
- #------------------------------------------------------------------------------------
- # POCKETS
- #------------------------------------------------------------------------------------
- #------------------------------------------------------------------------------------
- #------------------------------------------------------------------------------------
- def DropAllPockets(self):
- for i in range (1, 4, 1):
- SendDOUT("raisepocket%d" % i, 0) # setting to 1 to drop ?
- #----------------------------------------------------------
- #----------------------------------------------------------
- def LowerPocket(self,sWhich):
- SendDOUT("raisepocket%d" % sWhich, 0) # setting to 1 to drop ?
- #----------------------------------------------------------
- #----------------------------------------------------------
- def RaisePocket(self, sWhich): # send output signal to raise pocket (hold)
- SendDOUT("raisepocket%d" % sWhich, 1) # setting to 1 to raise it ?
- #----------------------------------------------------------
- #----------------------------------------------------------
- def FindFreePocket(self):
- #----------------------------------------------------------------
- # for each pocket defined, check if it has a tool
- # if pocket does not have a tool, return that pocket number
- #----------------------------------------------------------------
- #---------------------------------
- # Query stat digital input status
- #---------------------------------
- pocket1hastool = self.CheckDIN("pocket1hastool", True)
- pocket2hastool = self.CheckDIN("pocket1hastoo2", False)
- pocket3hastool = self.CheckDIN("pocket1hastoo3", False)
- print("%s - %s - %s" % (pocket1hastool, pocket2hastool, pocket3hastool))
- if pocket1hastool == 0:
- if pocket2hastool == 0:
- if pocket3hastool == 0:
- return -1 # all pockets have something
- else:
- return 3
- else:
- return 2
- else:
- return 1
- #----------------------------------------------------------
- #----------------------------------------------------------
- def FindToolPocket(toolid):
- # from the toolid (1,2,3) find the toolpocket (1,2,3)
- return toolid
- #------------------------------------------------------------------------------------
- #------------------------------------------------------------------------------------
- #------------------------------------------------------------------------------------
- # MOVEMENTS
- #------------------------------------------------------------------------------------
- #------------------------------------------------------------------------------------
- #------------------------------------------------------------------------------------
- #
- # This section interacts with G-Code using Python
- #
- #----------------------------------------------------------
- #----------------------------------------------------------
- def MoveToFrontOfPocket(self, id):
- # fetch the front position of said pocket in the xml file
- # go to that position in machine coordinates
- posX, posY, posZ = self.x.getPocketPos(id, "Front")
- self.command.mdi("G53 F%d X%f Y%f Z0.0" % (self.feedSpeed, posX, posY)) #,lineno())
- self.command.mdi("G53 F%d Z%f" % (self.feedSpeed, posZ)) #,lineno())
- #----------------------------------------------------------
- #----------------------------------------------------------
- def MoveToTopOfPocket(self, id):
- # fetch the top position of said pocket in the xml file
- # go to that position in machine coordinates
- posX, posY, posZ = self.x.getPocketPos(id, "Top")
- self.command.mdi("G53 F%d X%f Y%f Z0.0" % (self.feedSpeed, posX, posY)) #,lineno())
- self.command.mdi("G53 F%d Z%f" % (self.feedSpeed, posZ)) #,lineno())
- #----------------------------------------------------------
- #----------------------------------------------------------
- def MoveIntoOrOutOfPocket(self, id, direction): # either "INTO" or "OUT"
- # this requires a length ... found in the XML using getMoveDistance() (NOT)
- # this could be calculated ... or do we simply move the the FRONT pos ...
- # going to the FRONT position is ok to move OUT, but not for move INTO
- # going INTO, simply move to Top Y position, and Front X and Z
- posX, posY, posZ = self.x.getPocketPos(id, "Front")
- if direction == "INTO": # moving into is moving to the Top X position
- posX2, posY2, posZ2 = self.x.getPocketPos(id, "Top")
- self.command.mdi("G53 F%d X%f " % (self.feedSpeed, posX2)) #,lineno())
- else: # moving out is simply going to Front position
- self.command.mdi("G53 F%d X%f " % (self.feedSpeed, posX)) #,lineno())
- self.command.mdi("G53 F%d Z0.0 " % self.feedSpeed) #,lineno())
- #----------------------------------------------------------
- #----------------------------------------------------------
- def CheckDIN(self, sWhich, doPoll):
- index = self.x.getSignalInfos(sWhich)
- if doPoll:
- self.stat.poll()
- return(int(self.stat.din[index])
- #----------------------------------------------------------
- #----------------------------------------------------------
- def SendDOUT(sWhich, val)
- index = self.x.getSignalInfos(sWhich)
- self.command.set_digital_output(index, int(val))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement