Small works Machine process comp ex.

Forum Forums Visual Components 4.0 Component Modeling Small works Machine process comp ex.

Be sure to read the Forum Rules and Guidelines before start using the Forum.


This topic contains 0 replies, has 1 voice, and was last updated by line_out line_out 1 year, 1 month ago.

Viewing 1 post (of 1 total)
  • Author
  • #2619

    Below you find a short example how to make a component compatible with the works machine process command. The only thing the component needs is one String signal called task.

    Then we wait for that signal to be triggered, we check the values, and use up the process time, then we signal back that the process is done. The dummy delay could of course be replaced with some nice servo action or similar.

    The dictionary¬†“compsInWorld” contains the names of all comps in the world as keys, and the value is in turn a dict with the components behaviors names as keys and the actual behavior as value. In this way we can quickly find the corresponding component and TaskDone signal.

    from vcScript import *

    comp = getComponent()

    def OnSignal( signal ):
    global queue
    if signal.Name == ‘task’ and signal.Value:

    def OnStart():
    global compsInWorld
    compsInWorld = {}
    for x in getApplication().Components:
    behavs = [(b.Name, b) for b in x.Behaviours]
    compsInWorld[x.Name] = dict(behavs)

    def OnRun():
    global queue

    queue = []
    while True:
    condition(lambda: queue)
    task = queue.pop()
    #task ex = 5.0,WorksProcess #4,123
    vals = task.split(“,”)
    processtime = float(vals[0])
    worksProcessComponent = vals[1]
    #In this example we are expecting the machine command to be of type int
    machineCommand = int(vals[2]) if type(eval(vals[2])) == int else 1

    if machineCommand == 1:
    #do something
    #Do something else

    taskDone = compsInWorld[worksProcessComponent][“TaskDone”]

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.