# Pick objects by a sensor

**URL:** <https://forum.visualcomponents.com/t/pick-objects-by-a-sensor/1446>\
**Category:** Python Programming\
**Created:** [June 17, 2020, 1:52pm UTC](https://forum.visualcomponents.com/t/pick-objects-by-a-sensor/1446 "2020-06-17T13:52:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![OmarTaher](https://forum.visualcomponents.com/letter_avatar_proxy/v4/letter/o/b2d939/32.png) [@OmarTaher](https://forum.visualcomponents.com/u/OmarTaher)\
**Post date:** [June 17, 2020, 1:52pm UTC](https://forum.visualcomponents.com/t/pick-objects-by-a-sensor/1446/1 "2020-06-17T13:52:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![captain\_feature](https://forum.visualcomponents.com/user_avatar/forum.visualcomponents.com/captain_feature/32/5547_2.png) [@captain\_feature](https://forum.visualcomponents.com/u/captain_feature)\
**Post date:** [June 17, 2020, 2:04pm UTC](https://forum.visualcomponents.com/t/pick-objects-by-a-sensor/1446/2 "2020-06-17T14:04:53Z")

</div>

Hy,

try this:

box = conveyorIn.ComponentChildren[-1]

Regards  
Feature

---

<div class="post-metadata">

**Author:** ![OmarTaher](https://forum.visualcomponents.com/letter_avatar_proxy/v4/letter/o/b2d939/32.png) [@OmarTaher](https://forum.visualcomponents.com/u/OmarTaher)\
**Post date:** [June 17, 2020, 2:08pm UTC](https://forum.visualcomponents.com/t/pick-objects-by-a-sensor/1446/3 "2020-06-17T14:08:54Z")

</div>

![Capture](https://forum.visualcomponents.com/uploads/default/original/2X/8/842af56adbc6f11c499a241095302e5e03a1da43.png)

@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

---

<div class="post-metadata">

**Author:** ![OmarTaher](https://forum.visualcomponents.com/letter_avatar_proxy/v4/letter/o/b2d939/32.png) [@OmarTaher](https://forum.visualcomponents.com/u/OmarTaher)\
**Post date:** [June 17, 2020, 2:38pm UTC](https://forum.visualcomponents.com/t/pick-objects-by-a-sensor/1446/4 "2020-06-17T14:38:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![captain\_feature](https://forum.visualcomponents.com/user_avatar/forum.visualcomponents.com/captain_feature/32/5547_2.png) [@captain\_feature](https://forum.visualcomponents.com/u/captain_feature)\
**Post date:** [June 17, 2020, 2:50pm UTC](https://forum.visualcomponents.com/t/pick-objects-by-a-sensor/1446/5 "2020-06-17T14:50:18Z")

</div>

> [@OmarTaher](#):
>
> 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? 😉

Regards  
Feature

---

<div class="post-metadata">

**Author:** ![OmarTaher](https://forum.visualcomponents.com/letter_avatar_proxy/v4/letter/o/b2d939/32.png) [@OmarTaher](https://forum.visualcomponents.com/u/OmarTaher)\
**Post date:** [June 17, 2020, 3:07pm UTC](https://forum.visualcomponents.com/t/pick-objects-by-a-sensor/1446/6 "2020-06-17T15:07:56Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![captain\_feature](https://forum.visualcomponents.com/user_avatar/forum.visualcomponents.com/captain_feature/32/5547_2.png) [@captain\_feature](https://forum.visualcomponents.com/u/captain_feature)\
**Post date:** [June 17, 2020, 3:44pm UTC](https://forum.visualcomponents.com/t/pick-objects-by-a-sensor/1446/7 "2020-06-17T15:44:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ceppo](https://forum.visualcomponents.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@ceppo](https://forum.visualcomponents.com/u/ceppo)\
**Post date:** [September 10, 2020, 7:38am UTC](https://forum.visualcomponents.com/t/pick-objects-by-a-sensor/1446/8 "2020-09-10T07:38:57Z")

</div>

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.
