How often do triggers happen?

I am trying to get a robot to do something when a part is in a conveyor.

However it seems that when I am checking sometimes the part enters and leaves the conveyor before the system checks if there is a part there. this means that events are being missed. How do I get the system to check the state of the conveyor more often?

def OnRun():

while app.Simulation.IsRunning:
robot = getRobot(robot_comp)
sensor_signal = comp.findBehaviour(“SensorBooleanSignal”)
triggerCondition(lambda: sensor_signal.Value == True)
PotTray = Container.Components[0]

if robot.GraspContainer.ComponentCount == 0:
robot.driveJoints(-14.21,8.71,137.53,0.00,33.76,-28.14)
robot.pick(PotTray, Approach=1, Rz=180, OnFace = ‘top’)
robot.driveJoints(0,8.71,137.53,0.00,33.76,-28.14)

if len(dropConveyor.ChildComponents) == 1:

robot.SignalMapOut.output(100,False)
robot.place(dropConveyor.ChildComponents[0])
delay (2.0)
robot.SignalMapOut.output(100,True)
robot.driveJoints(-14.21,8.71,137.53,0.00,33.76,-28.14)
delay(0.1)

Hi,

I can’t find anything strange in your script so I think the problem is somewhere in the signaling.

The triggerCondition only evaluates the function once a trigger is received by the script. In your case this is every time the sensor_signal turns True or False the function will be evaluated.

What you can do is use condition(lambda: sensor_signal.Value), it works the same as triggerCondition but when the function is True it continues the code and does not wait for a trigger unless the condition is False.

I also made some small improvements to your code, see below:

from vcScript import *

def OnRun():
  robot = getRobot(robot_comp) # now these two lines are executed only ones. 
  sensor_signal = comp.findBehaviour(“SensorBooleanSignal”)
  while True: # While true does the same thing
    triggerCondition(lambda: sensor_signal.Value) # == True is redundant 
    sensor_signal.signal(False) # reset the signal, I don't know if you reset it elsewhere.
    PotTray = Container.Components[0]
    if robot.GraspContainer.ComponentCount == 0:
      robot.driveJoints(-14.21,8.71,137.53,0.00,33.76,-28.14)
      robot.pick(PotTray, Approach=1, Rz=180, OnFace = ‘top’)
      robot.driveJoints(0,8.71,137.53,0.00,33.76,-28.14)
    if len(dropConveyor.ChildComponents) == 1:
      robot.SignalMapOut.output(100,False)
      robot.place(dropConveyor.ChildComponents[0])
      delay (2.0)
      robot.SignalMapOut.output(100,True)
      robot.driveJoints(-14.21,8.71,137.53,0.00,33.76,-28.14)
      delay(0.1)

Regards,