Brooks

要控制 Brooks PreciseFlex 的夹爪,或是双夹爪完成仿真,可以跟着以下指南进行操作:

1.右键单击程序。点击:添加指令,再选择:程序调用指令。

2.添加程序调用指令的时候需要先命名,命名方法:Gripper(夹爪ID,夹爪值)。那么就是:Gripper(2, 50) ,意思是将双夹爪中的 2 号夹爪移动到 50 毫米处。

a.你也可以简化掉夹爪ID,命名为:Gripper(夹爪值)

b.如果存在多个机器人,也可以使用这样命名:Gripper(夹爪 ID, 夹爪值, item.ptr)。例如命名为:Gripper(2, 50, item.ptr) ,将把双夹爪中的 2 号夹爪移动到 50 毫米处,确保父机器人与程序相连。

3.在所有子程序的起始处以及所有子程序调用之后添加Gripper()指令。这是为了确保与后处理器的兼容性。预计会出现重复的Gripper()指令。

4.添加Python 脚本,命名为:Gripper。

5.编辑Python 脚本:Gripper,并粘贴以下内容:

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, possibly 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 'intelliguide' 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])

这种方法也兼容Brooks后处理器。