Pick Random Part | Delta Robot

Hello. I’m working with a Delta Robot and I want it to pick 2 random parts from a box, could anyone help me here, please?

Thanks in advance.

Hello. You can use a Python script to achieve this effect, similar to this script:

from vcScript import *
from random import *
def OnSignal( signal ):

def OnRun():
  while True:
    ran = 2
    while i < ran:
      a = random()*7
      if int(a)!=b or i == 0:
        print int(a)
        i += 1
        b = int(a)
    print '------------------'

This is a small demo using the random() function, you can use it to get the component number you need to grab, then use “comp (here refers to the box).ChildComponents” to get the component handle, after that, you can You can use the pick() function in the vcHelpers .Robot2 module to grab objects, and the place() function to place components. Usually this method is used on robots. When you are not sure or have not set up your grabbing component as a robot, you can also use “comp (here refers to the grabbed component).PositionMatrix” to get the position matrix of the component and use the vcMatrix module to get it coordinates, which also includes tracking issues. There is a tracking plugin in the forum that can help with this.

Thank you a lot for the help. Do you know if there’s any way I can do that easier with the PickAndPlace Controller?

I checked the PickAndPlace component, it doesn’t seem to have a random function, I also checked its code by the way, the unloading of the pallet is from line 371 (May 2022), so after a quick check I currently have The conclusion is that it may not have been designed with randomness in mind, which should be to avoid strange results due to randomness. If you must use the PickAndPlace component to grab randomly, you may have to change the prefabricated code. Here I offer three ideas: 1. You can change the code of PickAndPlace so that it can accept grab random components; 2. You can change the code for loading the tray, and when loading the tray, the order of the components in the tray’s ChildComponents list will be messed up, so that the order in which the subsequent Controller operates the robot will also be messed up; 3. The last one is in my opinion. The most convenient is to use the Pick() and Place() functions I mentioned to you. In my opinion, creating a piece of code is much easier than changing a piece of code.

1 Like

Although I’m comfortable programming, I have never done it in Visual Components, that’s why I was looking for an alternative. I will try to implement the code. Your help is very much appreciated, thank you!