Пример #1
0
def set_feeder_heights():
    
    
    nvStore = psypnp.nv.NVStorage(psypnp.config.storagekeys.FeedSearchStorage)
    
    
    selFeeders = psypnp.ui.getSelectedFeeders()
    
    defName = nvStore.feedname
    if len(selFeeders) == 1:
        defName = selFeeders[0]
        
    if defName is None or not len(defName):
        defName = '8mmStrip' # some default value
    
    
    feedSearch = psypnp.search.prompt_for_feeders_by_name("Name of feeder, or substring thereof to match many", defName)

    if feedSearch is None or feedSearch.searched is None or not len(feedSearch.searched):
        return
    
    nvStore.feedname = feedSearch.searched
    
    if not len(feedSearch.results):
        psypnp.ui.showError("No feeders match name '%s'" % pname, 'None found')
        return
    
    height = get_height_len()
    if height is None:
        return

    numChanged = 0
    for afeeder in feedSearch.results:
        apart = afeeder.getPart()
        if apart is not None:
            pHeight = apart.getHeight()
            if DoSubtractPartHeightFromLevel:
                feederHeight = height.subtract(pHeight)
            else:
                feederHeight = height
            refHole = afeeder.getReferenceHoleLocation()
            if refHole is not None:
                numChanged += 1
                newHole = Location(refHole.getUnits(), refHole.getX(), refHole.getY(), 0, 0)
                newZ = Location(feederHeight.getUnits(), 0, 0, feederHeight.getValue(), 0)
                newHole = newHole.add(newZ)
                psypnp.debug.out.buffer("Setting ref hole for %s to %s" % (afeeder.getName(), str(newHole)))
                afeeder.setReferenceHoleLocation(newHole)
    
    print("Number feeders affected: %i" % numChanged)
    gui.getFeedersTab().repaint()
    psypnp.showMessage("Set level Z for %i feeders" % numChanged)
Пример #2
0
def check_feeder_heights():
    global StorageParentName

    cur_feeder_index = get_current_idx()
    #next_feeder_index = get_next_feeder_index(cur_feeder_index)

    curFeed = get_current_feeder()
    if curFeed is None:
        return False
    if not curFeed.isEnabled():
        # we may have a stale current index
        reset_idx_counter()
        psypnp.ui.showError("Stale feed index, have reset. Please go again.")
        return True

    #curFeed = get_next_feeder_from(next_feeder_index)
    feederPart = curFeed.getPart()
    print("Will move to feeder %i\n%s     \nwith part   \n%s    " %
          (cur_feeder_index, str(curFeed.getName()), str(feederPart.getId())))

    # always safeZ
    machine.defaultHead.moveToSafeZ()
    # we don't want to go straight to the cam location--first XY,
    # then Z
    feedPickLoc = curFeed.getPickLocation()
    safeMoveLocation = Location(feedPickLoc.getUnits(), feedPickLoc.getX(),
                                feedPickLoc.getY(), 0, 45)
    MovableUtils.moveToLocationAtSafeZ(machine.defaultHead.defaultNozzle,
                                       safeMoveLocation)

    #print("WOULD MOVE FIRST TO: %s" % str(safeMoveLocation))

    locDepthZ = feedPickLoc.getZ()
    if MinSaneHeightAbs > abs(locDepthZ):
        print("Something weird with this feed -- height is %s" %
              str(locDepthZ))
        psypnp.ui.showError("Feeder height is strange: %s" % curFeed.getId())
        return False

    # length "down" to bottom of feed pick location, e.g. -35.00
    locDepthZLength = Length(locDepthZ, feedPickLoc.getUnits())

    # height of part, this is how much above the bottom of the feed pick
    # location openpnp will travel before picking up
    partHeight = feederPart.getHeight()

    actualDepthZTravelled = locDepthZLength
    if DoSubtractPartHeightFromLevel:
        print("Removing part height from travel depth")
        actualDepthZTravelled = locDepthZLength.add(partHeight)

    # target location "real" depth openpnp will travel (as Location object)
    locRealDepth = Location(feedPickLoc.getUnits(), 0, 0,
                            actualDepthZTravelled.getValue(), 0)

    # safe depth to travel to, basically real location depth + MinSaneHeightAbs (mm)
    locSafeDepth = locRealDepth.add(
        Location(LengthUnit.Millimeters, 0, 0, MinSaneHeightAbs, 45))

    # our first stage move is the (x,y) "safe" location with safe motion down
    locDownFirstStage = safeMoveLocation.add(locSafeDepth)
    # go there now
    machine.defaultHead.defaultNozzle.moveTo(locDownFirstStage)
    #print("NOW MOVE TO: %s" % str(locDownFirstStage))

    # now lets slow down
    curSpeed = machine.getSpeed()
    machine.setSpeed(0.25)

    #locFinalApproach = safeMoveLocation.add(locRealDepth)
    #locFinalApproach = feedPickLoc.subtract(locRealDepth)Location(feedPickLoc.getUnits(), 0, 0, actualDepthZTravelled.getValue(), 0)
    locFinalApproach = Location(feedPickLoc.getUnits(), feedPickLoc.getX(),
                                feedPickLoc.getY(),
                                actualDepthZTravelled.getValue(),
                                feedPickLoc.getRotation())

    #print("WILL FINALLY MOVE TO: %s" % str(locFinalApproach))
    #print("ORIG FEEDPICK LOC: %s" % str(feedPickLoc))
    machine.defaultHead.defaultNozzle.moveTo(locFinalApproach)
    machine.setSpeed(curSpeed)

    keepShowing = True
    while keepShowing:
        sel = psypnp.getOption("Result",
                               "How does %s look?" % curFeed.getName(), [
                                   'Thrilled!', 'Set Height', 'Up 0.1',
                                   'Down 0.1', 'Up 1', 'Down 1'
                               ])

        if sel is None:
            machine.defaultHead.moveToSafeZ()
            return False
        keepShowing = False

        if sel == 0:
            # all good
            increment_idx_counter(cur_feeder_index)
            machine.defaultHead.moveToSafeZ()
            return True
        if sel == 1:
            # calculate height based on this
            # take the part height and call the feeder that much lower
            nozLoc = machine.defaultHead.defaultNozzle.location
            nozHeight = Length(nozLoc.getZ(), nozLoc.getUnits())
            feederHeight = nozHeight
            if DoSubtractPartHeightFromLevel:
                print("Adding part height to travel depth")
                feederHeight = nozHeight.subtract(partHeight)
            # now get the reference hole location
            refHole = curFeed.getReferenceHoleLocation()
            # create a new hole without a Z
            newHole = Location(refHole.getUnits(), refHole.getX(),
                               refHole.getY(), 0, refHole.getRotation())
            # finally, add the feederHeight we determined
            #newHeight = nozLoc.getZ()
            newZLoc = Location(feederHeight.getUnits(), 0, 0,
                               feederHeight.getValue(), 0)

            newHole = newHole.add(newZLoc)

            #print("WILL Set ref hole for %s to %s" % (feederPart.getName(), str(newHole)))
            curFeed.setReferenceHoleLocation(newHole)
            machine.defaultHead.moveToSafeZ()
            increment_idx_counter(cur_feeder_index)
            return True
        if sel == 2:  # Up 0.1
            feedPickLoc = feedPickLoc.add(
                Location(LengthUnit.Millimeters, 0, 0, 0.1, 0))
            machine.defaultHead.defaultNozzle.moveTo(feedPickLoc)

            keepShowing = True
        if sel == 3:  # Down 0.1
            feedPickLoc = feedPickLoc.subtract(
                Location(LengthUnit.Millimeters, 0, 0, 0.1, 0))
            machine.defaultHead.defaultNozzle.moveTo(feedPickLoc)
            keepShowing = True
        if sel == 4:  # Up 1
            feedPickLoc = feedPickLoc.add(
                Location(LengthUnit.Millimeters, 0, 0, 1, 0))
            machine.defaultHead.defaultNozzle.moveTo(feedPickLoc)
            keepShowing = True
        if sel == 5:  # Down 1
            feedPickLoc = feedPickLoc.subtract(
                Location(LengthUnit.Millimeters, 0, 0, 1, 0))
            machine.defaultHead.defaultNozzle.moveTo(feedPickLoc)
            keepShowing = True

    return False