def createBox(RDK=None):
    if RDK is None:
        RDK = Robolink()

    global BOX_SIZE_XYZ
    global USE_METRIC
    global PARENT
    global CONV_PARENT

    RDK.Render(False)

    x, y, z = BOX_SIZE_XYZ
    if USE_METRIC:
        new_box = RDK.AddFile(REF_BOX_MM_PATH, PARENT)
        new_box.setName(BOX_ITEM_NAME_MM % (x, y, z))
    else:
        new_box = RDK.AddFile(REF_BOX_IN_PATH, PARENT)
        new_box.setName(BOX_ITEM_NAME_IN % (x, y, z))

    new_box.setPose(eye(4))
    new_box.Scale([x, y, z])
    RDK.Update()

    if CONV_PARENT is not None:
        new_box.setParentStatic(CONV_PARENT)

    new_box.setVisible(True)
    RDK.Render(True)
Exemple #2
0
def AttachCamera():
    RDK = Robolink()

    item2station_pose = eye(4)
    view_pose_last = eye(4)
    last_item = None

    RDK.Render()

    run = RunApplication()
    while run.Run():
        # Retrieve user selection
        selected_items = RDK.Selection()
        if len(selected_items) <= 0:
            last_item = None
            continue

        # Use the first selected item to attach the camera
        item = selected_items[0]

        # Prevent selecting programs or instructions or anything that doesn't move
        if item.type == ITEM_TYPE_ROBOT or item.type == ITEM_TYPE_TOOL or item.type == ITEM_TYPE_FRAME or item.type == ITEM_TYPE_OBJECT or item.type == ITEM_TYPE_TARGET:
            item_pose = item.PoseAbs(
            )  # Selected item pose with respect to the station reference
            item2station_pose = item_pose.inv()

            if last_item != item:
                # If it is the first time we select this item: update the relationship camera 2 item pose
                view_pose = RDK.ViewPose(
                )  # View Pose (camera pose with respect to the station reference)
                camera2item_pose = (item2station_pose * view_pose.inv()).inv()
                msg = 'Camera attached to %s' % item.Name()
                print(msg)
                RDK.ShowMessage(msg, False)
                last_item = item

            else:
                # calculate the new view pose and udpate it
                view_pose = camera2item_pose * item2station_pose

                # Only update if the view pose changed
                if view_pose != view_pose_last:
                    view_pose_last = view_pose
                    RDK.setViewPose(view_pose)
                    RDK.Render()