Esempio n. 1
0
def _process_io_command(command, opts):
    """
    Process io command.
    :param command: Command tuple
    :param opts: UserOptions tuple
    :return:
    """
    io_data = []  # empty data container

    # Interpret digital output command
    if opts.Include_digital_output:
        if command.digital_output is not None:
            io_type = BINARY_OUT
            for io in command.digital_output:
                formatted_io = postproc.fill_template(
                    io,
                    STRUCTURES[io_type],
                    TEMPLATES[io_type])
                io_data.append(formatted_io)
        # if command.analog_outputs is not None:
        #     io_type = ANALOG_OUT
        #     for io in command.analog_outputs:
        #         formatted_io = postproc.fill_template(
        #             io,
        #             STRUCTURES[io_type],
        #             TEMPLATES[io_type])
        #         io_data.append(formatted_io)

    if io_data:
        formatted_ios = '\n'.join(io_data)
        return formatted_ios
Esempio n. 2
0
def _process_motion_command(command, opts):
    """
    Process motion command.
    :param command: Command tuple
    :param opts: UserOptions tuple
    :return:
    """
    motion_data_type = None
    motion_data = []  # empty data container

    # Interpret linear motion command
    if opts.Use_linear_motion:
        motion_type = MOVE_LIN
        if command.pose is not None:
            motion_data.extend(_convert_pose(command.pose))
            if command.configuration is not None:
                if command.external_axes is not None:
                    motion_data_type = E6POS
                    external_axes = [axis if axis is not None else 0 for axis in command.external_axes]
                    motion_data.extend(external_axes)
                else:
                    motion_data_type = POS
                motion_data.extend(_convert_configuration(command.configuration))
            else:
                motion_data_type = FRAME
        else:
            raise ValueError('Invalid command')

    # Interpret nonlinear motion command
    elif opts.Use_nonlinear_motion:
        if opts.Use_continuous_motion:
            motion_type = MOVE_CPTP
        else:
            motion_type = MOVE_PTP
        if command.axes is not None:
            motion_data.extend(command.axes)
            if command.external_axes is not None:
                motion_data_type = E6AXIS
                external_axes = [axis if axis is not None else 0 for axis in command.external_axes]
                motion_data.extend(external_axes)
            else:
                motion_data_type = AXIS
        elif command.pose is not None:
            motion_data_type = FRAME
            motion_data.extend(_convert_pose(command.pose))
        else:
            raise ValueError('Invalid command')

    else:  # User never supplied a motion type
        raise ValueError('Invalid motion type')

    # Format parameters into string
    motion_data = [general_utils.num_to_str(d, include_sign=False, precision=3)
                   for d in motion_data]

    # Structure and format data, command
    formatted_motion_data = postproc.fill_template(
        motion_data,
        STRUCTURES[motion_data_type],
        TEMPLATES[motion_data_type])

    formatted_motion = postproc.fill_template(
        formatted_motion_data,
        STRUCTURES[motion_type],
        TEMPLATES[motion_type])
    return formatted_motion
Esempio n. 3
0
def _process_motion_command(command, opts):  # Implement in base class!
    """
    Process motion command.
    :param command: Command tuple
    :param opts: UserOptions tuple
    :return:
    """
    motion_type = None
    target_data_type = None
    target_data = []

    # Interpret linear motion command
    if opts.Use_linear_motion:
        if command.pose is not None:
            motion_type = MOVE_L
            target_data_type = ROBTARGET
            pose = _convert_pose(command.pose)
            params = [
                general_utils.num_to_str(p, include_sign=False, precision=3)
                for p in pose
            ]
            target_data.extend(params)
            if command.configuration is not None:
                configuration = _convert_configuration(command.configuration)
                params = [
                    general_utils.num_to_str(p,
                                             include_sign=False,
                                             precision=3,
                                             simplify_ints=True)
                    for p in configuration
                ]
                target_data.extend(params)
            else:
                target_data.extend(rapid_config.DEFAULT_CONF)
            if command.external_axes is not None:
                external_axes = [
                    axis if axis is not None else '9E9'
                    for axis in command.external_axes
                ]
                params = [
                    general_utils.num_to_str(p,
                                             include_sign=False,
                                             precision=3)
                    for p in external_axes
                ]
                target_data.extend(params)
            else:
                target_data.extend(rapid_config.DEFAULT_EXAX)

        else:
            raise ValueError('Invalid command')

    # Interpret nonlinear motion command
    elif opts.Use_nonlinear_motion:
        if command.axes is not None:
            motion_type = MOVE_ABS_J
            target_data_type = JOINTTARGET
            axes = command.axes
            params = [
                general_utils.num_to_str(p, include_sign=False, precision=3)
                for p in axes
            ]
            target_data.extend(params)
            if command.external_axes is not None:
                external_axes = [
                    axis if axis is not None else '9E9'
                    for axis in command.external_axes
                ]
                params = [
                    general_utils.num_to_str(p,
                                             include_sign=False,
                                             precision=3)
                    for p in external_axes
                ]
                target_data.extend(params)
            else:
                target_data.extend(rapid_config.DEFAULT_EXAX)

        elif command.pose is not None:
            motion_type = MOVE_J
            target_data_type = ROBTARGET

            pose = _convert_pose(command.pose)
            params = [
                general_utils.num_to_str(p, include_sign=False, precision=3)
                for p in pose
            ]
            target_data.extend(params)
            if command.configuration is not None:
                configuration = _convert_configuration(command.configuration)
                params = [
                    general_utils.num_to_str(p,
                                             include_sign=False,
                                             precision=3,
                                             simplify_ints=True)
                    for p in configuration
                ]
                target_data.extend(params)
            else:
                target_data.extend(rapid_config.DEFAULT_CONF)
            if command.external_axes is not None:
                external_axes = [
                    axis if axis is not None else '9E9'
                    for axis in command.external_axes
                ]
                params = [
                    general_utils.num_to_str(p,
                                             include_sign=False,
                                             precision=3)
                    for p in external_axes
                ]
                target_data.extend(params)
            else:
                target_data.extend(rapid_config.DEFAULT_EXAX)
        else:
            raise ValueError('Invalid command')

    else:  # User never supplied a motion type
        raise ValueError('Invalid motion type')

    # Structure and format data, command
    formatted_target_data = postproc.fill_template(
        target_data, STRUCTURES[target_data_type], TEMPLATES[target_data_type])

    if opts.Use_motion_as_variables:
        formatted_variable = postproc.fill_template(formatted_target_data,
                                                    STRUCTURES[VARIABLE],
                                                    TEMPLATES[VARIABLE])
        return formatted_variable
    else:
        motion_data = [
            motion_type, formatted_target_data, rapid_config.DEFAULT_SPEED,
            rapid_config.DEFAULT_ZONE, rapid_config.DEFAULT_TOOL,
            rapid_config.DEFAULT_WOBJ
        ]

        formatted_motion = postproc.fill_template(motion_data,
                                                  STRUCTURES[MOVE],
                                                  TEMPLATES[MOVE])
        return formatted_motion