Gripper Simulation

To control the Brooks PreciseFlex grippers from a simulation, including the dual gripper, follow the steps outlined in this section.

1.Right-click your program, and add a Program Call Instruction.

2.Enter “Gripper(gripper ID, gripper value)”. For example, “Gripper(2, 50)” to move the gripper #2 of a dual gripper to 50 mm.

a.You can shorten the call to “Gripper(gripper value)” with a single gripper.

b.If more than one robot is present, use “Gripper(gripper ID, gripper value, item.ptr)”. For example, “Gripper(2, 50, item.ptr)” will move the gripper #2 of a dual gripper to 50 mm, ensuring the parent robot is linked to the program.

3.Add the Gripper() instruction as the first instruction of all subprograms and after all subprogram calls. This is to ensure compatibility with the post processor. Duplicated Gripper() instructions are expected.

4.Add a Python script, rename it to “Gripper”.

5.Edit the “Gripper” Python script and paste the following:

from robodk import robolink

import sys

 

if len(sys.argv) < 2:

quit()

 

def get_item(ptr_item, RDK):

item = robolink.Item(RDK, str(ptr_item), robolink.ITEM_TYPE_PROGRAM)

if not item.Valid(True):

    return None

return item

 

RDK = robolink.Robolink()

gripper_id = -1

gripper_value = 0

prog_item = None

 

# Get the gripper ID, value and the caller

if len(sys.argv) == 2:

gripper_value = float(sys.argv[1])

elif len(sys.argv) >= 4:

gripper_id = int(sys.argv[1])

gripper_value = float(sys.argv[2])

prog_item = get_item(int(sys.argv[3]), RDK)

elif len(sys.argv) == 3:

prog_item = get_item(int(sys.argv[2]), RDK)

if prog_item:

    gripper_value = float(sys.argv[1])

else:

    gripper_id = int(sys.argv[1])

    gripper_value = float(sys.argv[2])

 

# Get candidates

grippers = [x for x in RDK.ItemList(robolink.ITEM_TYPE_ROBOT_AXES) if 'gripper' in x.Name().lower() and len(x.Joints().tolist()) == 1]

if len(grippers) > 1 and prog_item:

robot_item = prog_item.getLink(robolink.ITEM_TYPE_ROBOT)

if not robot_item.Valid():

    robot_item = RDK.ItemUserPick("Select the linked robot", robolink.ITEM_TYPE_ROBOT)

    prog_item.setRobot(robot_item)

 

def get_flat_childs(item):

    childs = item.Childs()

    for child in item.Childs():

        childs.extend(get_flat_childs(child))

    return childs

 

childs = get_flat_childs(robot_item)

grippers = [x for x in childs if x.Type() == robolink.ITEM_TYPE_ROBOT and len(x.Joints().tolist()) == 1]

 

if not grippers:

RDK.ShowMessage('Unable to find a gripper!', False)

 

# Try to find the right gripper id (i.e. Dual Gripper 1)

gripper = grippers[0]

if gripper_id > 0:

gripper_ids = [g for g in grippers if g.Name().endswith(str(gripper_id))]

if gripper_ids:

    gripper = gripper_ids[0]

 

gripper.MoveJ([gripper_value])

Note that this method is also compatible with the Brooks post processor.