3 Light Tower

Hello,

I want to control a 3 light tower without a python script, just by using boolean variables.

The lights of the tower should react to the change of the SensorBooleanSignal of a conveyor sensor. That means for example if a TRUE-statement of the sensor is detected, the light “green” should shine.

Is there any possibility to contol a 3 light tower in general respectively with the help of boolean variables?

I just want to learn the basics of using variables, without a python script and robots.

Since the 3 light tower does not by default have any signals in it, you cannot really avoid writing a few lines of python code to implement this.

Hy,

no fear about python-scripting. → It opens so much awesome possiblities! → Look in VC-Help under ReferenceGuide/Python API for References and search the forum for already solved topics…

Regards
Feature

Okay okay, but I can include signals in form of boolean signals to the light tower, right?!

I can connect the signals to the output signal of the conveyer. After that I don’t know how the variables could change the state of the lights. How could I use references to the colors?!

What would the python script for example look like?!

Hi,

Yes you can add boolean signals:

After having added the script you have to connect the signals with it:

Here is an example of a script that might help you:

from vcScript import *

def OnSignal( signal ):
  print "A signal was received"
  if signal == signal_green and signal_green.Value == True:
    #switch off other signals
    signal_yellow.Value = False
    signal_red.Value = False
    #set properties
    light_green.Value = True
    light_yellow.Value = False
    light_red.Value = False
    print "Light changed to green."
    print "State of the signals: \t","green=",signal_green.Value, "\tyellow=",signal_yellow.Value, "\tred=", signal_red.Value
  elif signal == signal_yellow and signal_yellow.Value == True:
    #switch off other signals
    signal_green.Value = False
    signal_red.Value = False
    #set properties
    light_green.Value = False
    light_yellow.Value = True
    light_red.Value = False
    print "Light changed to yellow."
    print "State of the signals: \t","green=",signal_green.Value, "\tyellow=",signal_yellow.Value, "\tred=", signal_red.Value
  elif signal == signal_red and signal_red.Value == True:
    #switch off other signals
    signal_green.Value = False
    signal_yellow.Value = False
    #set properties
    light_green.Value = False
    light_yellow.Value = False
    light_red.Value = True
    print "Light changed to red."
    print "State of the signals: \t","green=",signal_green.Value, "\tyellow=",signal_yellow.Value, "\tred=", signal_red.Value
  if signal == signal_green and signal_green.Value == False:
    #reset property
    light_green.Value = False
    print "Green light is switched off."
    print "State of the signals: \t","green=",signal_green.Value, "\tyellow=",signal_yellow.Value, "\tred=", signal_red.Value
  elif signal == signal_yellow and signal_yellow.Value == False:
    #reset property
    light_yellow.Value = False
    print "Yellow light is switched off."
    print "State of the signals: \t","green=",signal_green.Value, "\tyellow=",signal_yellow.Value, "\tred=", signal_red.Value
  elif signal == signal_red and signal_red.Value == False:
    #reset property
    light_red.Value = False
    print "Red light is switched off."
    print "State of the signals: \t","green=",signal_green.Value, "\tyellow=",signal_yellow.Value, "\tred=", signal_red.Value

def OnRun():
  pass

comp = getComponent()

signal_green = comp.getBehaviour("Green")
signal_yellow = comp.getBehaviour("Yellow")
signal_red = comp.getBehaviour("Red")

light_green = comp.getProperty("Green")
light_yellow = comp.getProperty("Yellow")
light_red = comp.getProperty("Red")

There are different ways how to use signals. Here you can learn more about it:

Have a nice day.

3 Likes

Thanks for the impression and the script.

The function “OnSignal” is triggered ones or every time a signal gets true?

If I implement a while-loop in the OnRun-function and start the simulation my program crash…Why this happen?

My sample script is attached.

from vcScript import *


comp = getComponent()


signal_phase = comp.getBehaviour("Phase")

light_yellow = comp.getProperty("Yellow")
light_green = comp.getProperty("Green")
light_red = comp.getProperty("Red")

x = 0


def OnSignal (signal_phase):
  x = 1
  if x == 1:
    light_green.Value = True
    light_yellow.Value = True
    light_red.Value = True
    return
    
  elif x == 2:
    light_green.Value = False
    light_yellow.Value = False
    light_red.Value = False
    x = 0
    return
       
def OnRun():
  pass
  

.

Hy,

may you have no delay?

Regards
Feature