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”)
print(len(conveyorIn.ComponentChildren))
box = conveyorIn.ComponentChildren[1]
Robot.pick(box)

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

Thanks in advance.

Hy,

try this:

box = conveyorIn.ComponentChildren[-1]

Regards
Feature

@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

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

Hy,

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:

Regards
Feature

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.

Regards
Feature

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.