Feeder Signal programming

Im looking to create different components depending on what signal i set in the feeder.
Currently im looking at the shape feeder.
Say that i have two signals
CreateSignal1 - when set high creates a ball
CreateSignal2 - when set high creates a barrel

how do i code this in the script?


Your signals should be connected to your Pythonscript. Click on them and in Connections put your Script in there.

You should also have two ComponentCreator that create the ball and the barrel.

In the Script:
comp = getComponent()
creator1 = comp.findBehaviour('ComponentCreator1')
creator2 = comp.findBehaviour('ComponentCreator2')

def OnSignal(signal):
   if signal.Name == 'CreateSignal1' and signal.Value:
   elif signal.Name == 'CreateSignal2' and signal.Value:

Hello Again
I tried to apply your code to a basic feeder but i feel that something is missing to handle if i switch signals. As it is now, i can only create one of the parts on a given signal. What am i missing?

Try_1.vcmx (38.7 KB)

Yeah sorry, forgot to mention this. There can only be one connection between input and output of behaviours so we need to also connect the chosen creator to the path before we create.

creator1 = comp.findBehaviour('ComponentCreator_1')
creator1_out = creator1.getConnector('Output')
creator2 = comp.findBehaviour('ComponentCreator_2')
creator2_out = creator2.getConnector('Output')
path_in = comp.findBehaviour('OutPath').getConnector('Input')

def OnSignal(signal):
   if signal.Name == 'CreateSignal1' and signal.Value:
   elif signal.Name == 'CreateSignal2' and signal.Value:
1 Like

Ahh, works fine. there is one problem when connecting an external signal source via OPCUA.
When toggling between signals, the creator lags a bit before switching. To avoid this i would like to add the functionality to only create a new part on the rising edge of the in signal.
I have studied the Shape-feeder script and it seems to have the functionality that i need.
I tried to impliment the code thus far into that script instead but there where no parts created.

In the while-loop of the script i copied and modified the code like this in its own if-statement:

if comp.CreateOnlyOnSignal:
      triggerCondition(lambda: getTrigger() == createSignal_1 and createSignal_1.Value)
    # try to create a part
    part = creator1.create()
    # if part creation is succesful (e.g. conveyor not blocked)
    if part:
      m = poseProp.Value
      if offsetEnabled.Value:
      if turnEnabled.Value:
      part.MovementOrigin = m
      if comp.StationaryCreator:
        triggerCondition(lambda: getTrigger() == transSignal and not transSignal.Value)
      msg("Component creation failed. Output blocked?")

    if not comp.CreateOnlyOnSignal:
      # Delay and check that interval is not zero
      delay(max(comp.CreationInterval, .0000001) )

But there where no components showing up unfortunately, Try_2.vcmx (56.4 KB)

Hey, I looked at your first example again (try1) and the reason for the lag was because the ComponentCreator had the CreateSignal set as Transitionsignal. The problem with this is everytime a Component is created the Transitionsignal, which in this case is CreateSignal, will become True and once the Component is out it will become False again.

If you need this information then you should use another signal. The CreateSignals should only be used to signal the creation of components.

The component is already only being created on the rising edge of the signal in the first example.
The OnSignal event is called everytime the value switches between True and False. That’s why we have the second condition in the if statement: and signal.Value. This checks if the signal is True and only then does it create the component.

You can also change the signal to False again after creating the component. That way you don’t have to change the signal twice.

signal.Value = False

Ahh perfect, now it works when switching the signals.
Got one final issue,but i solved it but i might just as well tell for reference.
When first changing the singal from a server, the solution generated two item of the same type.
This is due to that the update mode is set to cyclic. You need to change this to event-based in order to generate one item on each rising edge.
This is done in the connectivitytab->server->server to simulation and on the properties panel you can change the updatemode.
Thanks for the help barismungan !
Much appreciated