Pick objects by a sensor

I have a sensor and motor connected to a conveyor. When the sensor sense a box, the conveyor stops as i want. But the robot picks random boxes from the conveyor.
How can I make it pick the box that triggered the sensor ?

my code is:
app = getApplication()
conveyorIn= app.findComponent(“Conveyor”)
box = conveyorIn.ComponentChildren[1]

I think the problem is in line 4 as the index chosen from the Component Children list changes everytime

Thanks in advance.


try this:

box = conveyorIn.ComponentChildren[-1]


@captain_feature It picks the motor and the sensor first and then the boxes are picked correctly.

I just want it to pick the box that triggered the sensor everytime the sensor is triggered

So i replace the -1 by -3 and it worked perfectly fine :slight_smile:
what is the concept behind it?


that’s Phyton! -> “-1” = Last element of list, "-2! gets the second to last element of list, …

In your case you have the luck that are always 3 boxes on the conveyor when the robot picks one? :wink:


I am supposed to program the robot to work for different speed of feeders and conveyors. How can I make the picking of the box i want independant of the number of boxes on the conveyor?

Maybe the conveyor has vcContainer which contains all boxes?
Then you need to identify the right one and grab it.

Do you search the Forum for similar requests? Maybe other persons had the Same issue.


1 Like

You could make a subroutine in the program tab for the robot where you manually set it to pick the box from the sensor and then you can call that subroutine in python when needed.