Created
October 25, 2013 05:18
-
-
Save imrehg/7149731 to your computer and use it in GitHub Desktop.
Automation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################## | |
from vcScript import * | |
comp = getComponent() | |
def OnSignal( signal ): | |
global componentEntering, queue, portIndex | |
# When component is trying to pass the transfer the index of the port is added to request queue | |
if signal == componentEntering: | |
queue.append([portIndex.Value, componentEntering.Value]) # list of lists ~ [index, part] | |
# PortDistance calculates the correct distance of a desired port for shuttle to move to the right position. | |
def PortDistance(targetIndex): | |
global comp, placesA, placesB | |
if targetIndex < len(placesA): | |
port = targetIndex | |
frame = comp.findFeature('SideAFrameIn'+str(port)) | |
else: | |
port = targetIndex - len(placesA) | |
frame = comp.findFeature('SideBFrameIn'+str(port)) | |
portPlace = frame.NodePositionMatrix.P.Y | |
return portPlace | |
# choosePathPort chooses which end of the path gets connected to the flowproxy | |
def choosePathPort(targetPort): | |
global comp, placesA, placesB | |
sideACount=len(placesA) | |
if targetPort<sideACount: | |
return 0 | |
else: | |
return 1 | |
# chooseDirection chooses which way the path gets driven | |
def chooseDirection(io, port): | |
global comp, placesA, placesB | |
sideACount=len(placesA) | |
if io == 'in': | |
if port<sideACount: | |
return VC_PATH_FORWARD | |
else: | |
return VC_PATH_BACKWARD | |
else: | |
if port<sideACount: | |
return VC_PATH_BACKWARD | |
else: | |
return VC_PATH_FORWARD | |
def OnRun(): | |
global componentEntering, queue, portIndex, comp, placesA, placesB | |
queue = [] | |
comp = getComponent() | |
flow = comp.findBehaviour('FlowProxy') | |
portIndex = comp.findBehaviour('PortIndexSignal') | |
componentEntering = comp.findBehaviour('ComponentEnteringSignal') | |
shuttlePath = comp.findBehaviour('MainPath__HIDE__') | |
servo = comp.findBehaviour('ServoController') | |
shuttleSignal = comp.findBehaviour('ShuttleSignal') | |
routing= comp.findBehaviour('RoutingRule') | |
shuttleTransition = comp.findBehaviour('shuttleTransition') | |
statistics = comp.findBehaviour('Statistics') | |
# read port places in lists placesA and placesB | |
comp.SideA_PortPlaces = comp.SideA_PortPlaces.replace(';',',') | |
placesA = comp.SideA_PortPlaces.split(',') | |
comp.SideB_PortPlaces = comp.SideB_PortPlaces.replace(';',',') | |
placesB = comp.SideB_PortPlaces.split(',') | |
overall_count = len(placesA)+len(placesB) | |
placesA = map(lambda x: float(x), placesA) | |
placesB = map(lambda x: float(x), placesB) | |
while True: | |
statistics.State = 'Idle' | |
if len(queue) == 0: | |
if comp.UseIdlePosition: | |
servo.move(comp.IdlePosition) | |
# lets wait for a trigger if the queue is empty | |
triggerCondition(lambda: getTrigger() == componentEntering and componentEntering.Value != None) | |
task = queue.pop(0) # let's take the first request in the queue | |
firstInQueue = task[0] | |
part = task[1] | |
statistics.State = 'Busy' | |
servo.move(PortDistance(firstInQueue)) # move shuttle to the requested port in zero time | |
flow.connectInternally(firstInQueue,shuttlePath.getConnector(choosePathPort(firstInQueue))) # connect the shuttle path to the flowProxy in port | |
shuttlePath.Direction=chooseDirection('in',firstInQueue) | |
shuttlePath.Enabled = True # Take the component into shuttle | |
triggerCondition(lambda: getTrigger() == shuttleSignal) # wait for the component to arrive in the middle of the shuttle | |
shuttlePath.Enabled = False | |
targetPort = -1 | |
while targetPort == -1: | |
targetPort = routing.processRoute(firstInQueue, part, flow) # Take target port from the routing rule | |
if targetPort == -1: | |
delay(1) | |
servo.move(PortDistance(targetPort)) | |
flow.connectInternally(targetPort,shuttlePath.getConnector(choosePathPort(targetPort))) # connect the shuttle path to the flowProxy out port | |
shuttlePath.Direction=chooseDirection('out',targetPort) | |
shuttlePath.Enabled=True | |
triggerCondition(lambda: getTrigger() == shuttleTransition and shuttleTransition.Value ==0) # wait for component to exit shuttlePath | |
shuttlePath.Enabled=False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment