コード例 #1
0
ファイル: mimic_program.py プロジェクト: tws0002/Mimic
def _show_program_in_output_window(robot, processor, program):
    """
    Display program in the output window.
    :param robot:
    :param processor:
    :param program:
    :return:
    """
    # Update the output-text viewer in the Mimic UI
    details = 'Type of robot     : {} {} ({})\n' \
              'Type of processor : {} {} ({})\n' \
              'Path to template  : {}\n' \
              'Path to output    : {}\n' \
              '\n'

    target_ctrl_path = mimic_utils.get_target_ctrl_path(robot)
    filled_details = details.format(
        mimic_utils.get_robot_type(robot),
        mimic_utils.get_robot_subtype(robot), robot, processor.type_robot,
        processor.type_processor, processor.__class__.__name__,
        postproc.confirm_path_exists(processor.get_program_template_path()),
        postproc.confirm_path_exists(processor.get_program_output_path()))

    pm.scrollField(OUTPUT_WINDOW_NAME, insertText=filled_details, edit=True)

    pm.scrollField(OUTPUT_WINDOW_NAME, insertText=program + '\n', edit=True)
コード例 #2
0
ファイル: mimic_program.py プロジェクト: tws0002/Mimic
def _check_robot_postproc_compatibility(robot, processor):
    """
    Verify the compatibility of the selected robot and the processor.
    :return:
    """
    warning = ''
    robot_type = mimic_utils.get_robot_type(robot)
    processor_type = processor.type_robot

    if robot_type != processor_type:
        warning = 'WARNING!\n' \
                  'The type of robot ({}) \n' \
                  'and type of processor ({}) \n' \
                  'selected are incompatible!\n' \
            .format(robot_type, processor_type)
    return warning
コード例 #3
0
ファイル: mimic_program.py プロジェクト: tws0002/Mimic
def _sample_frame_get_pose(robot_name, frame):
    """
    Get robot Pose from an animation frame.
    :param robot_name: Name of the robot
    :param frame: Frame to sample
    :return:
    """
    # Set the time
    # TODO: Implement this in parent function
    pm.currentTime(frame)

    # tool_name = get_tool_name(robot_name)
    tool_name = mimic_utils.get_tool_ctrl_path(robot_name)
    try:  # Try to grab the named tool
        tool_object = pm.ls(tool_name)[
            0]  # Try to get tool, may raise an exception
    except IndexError:  # No tool attached, use flange
        tool_name = mimic_utils.get_tcp_hdl_path(robot_name)

    # Local Base Frame controller (circle control at base of the robot).
    base_name = pm.ls(mimic_utils.get_local_ctrl_path(robot_name))[0]

    # Get name of the tcp and base
    world_matrix = '.worldMatrix'
    tcp_name_world_matrix = tool_name + world_matrix
    base_name_world_matrix = base_name + world_matrix

    # TRANSLATIONS

    # Get translation with respect to Maya's world frame
    tcp_translation = pm.xform(tool_name, query=True, rp=True, ws=True)
    base_translation = pm.xform(base_name, query=True, rp=True, ws=True)

    # ROTATIONS

    # Get TCP rotation with respect to Maya's world frame
    _tcp_matrix = pm.getAttr(tcp_name_world_matrix, time=frame)
    tcp_rotation = general_utils.matrix_get_rotations(_tcp_matrix)

    # Get Base rotation with respect to Maya's world frame
    _base_matrix = pm.getAttr(base_name_world_matrix, time=frame)
    base_rotation = general_utils.matrix_get_rotations(_base_matrix)

    # TRANSFORMATIONS

    # Compose 4x4 matrices using the rotation and translation from the above
    tcp_matrix_4x4 = general_utils.matrix_compose_4x4(tcp_rotation,
                                                      tcp_translation)
    base_matrix_4x4 = general_utils.matrix_compose_4x4(base_rotation,
                                                       base_translation)

    # Invert the base matrix
    base_matrix_4x4 = general_utils.matrix_get_inverse(base_matrix_4x4)

    # Get pose itself
    initial_pose_matrix = general_utils.matrix_multiply(
        base_matrix_4x4, tcp_matrix_4x4)

    # CONVERSIONS

    # Decompose the initial pose matrix
    initial_translation = general_utils.matrix_get_translation(
        initial_pose_matrix)
    initial_rotations = general_utils.matrix_get_rotations(initial_pose_matrix)

    # Rearrange from Maya CS (mcs) to Robot CS (rcs)
    indices = [2, 0, 1]
    new_translation = [initial_translation[i] * 10
                       for i in indices]  # cm to mm
    new_rotation = [[initial_rotations[i][j] for j in indices]
                    for i in indices]

    # Define rotation matrix and convert the rotations based robot type
    # Based on the orientation of the coordinate frame of the mounting flange
    # TODO: Integrate this with rigs, unclear and shouldn't be hardcoded
    robot_type = mimic_utils.get_robot_type(robot_name)
    if robot_type == 'ABB':
        conversion_rotation = [[0, 0, -1], [0, 1, 0], [1, 0, 0]]
    # elif robot_type == 'KUKA':
    #     conversion_rotation = [
    #         [0, -1, 0],
    #         [0, 0, 1],
    #         [-1, 0, 0]
    #     ]
    else:
        raise Exception('Robot type not supported for Pose movement')

    # Perform the conversion operation itself
    converted_rotation = general_utils.matrix_multiply(conversion_rotation,
                                                       new_rotation)

    # Compose pose
    pose_matrix = general_utils.matrix_compose_4x4(converted_rotation,
                                                   new_translation)

    # Decompose pose as expected for output
    pose = general_utils.matrix_decompose_4x4_completely(pose_matrix)
    return pose