Ejemplo n.º 1
0
def update_plot(data):
    """
    This function is the blood and guts of the program. It mines the information
    from the input stream and updates the plot data for each step of the
    animation.
    """
    # update the data
    update_plot.exec_path
    update_plot.filepos
    update_plot.pause
    update_plot.isstep
    if not update_plot.pause:
        while 1:
            path_and_error = []
            # Read the first line after the previous parse. This line should
            # contain the block label (SD), (SE), (LG) or (TR).
            if not options.stdintrue:
                curpos = instream.tell()
            line = instream.readline()
            if len(line) == 0:
                update_plot.pause = True
                return ax1xy, ax1xryr, execp, ax2xy, ax2xryr
            if '(SE)' in line:
                if not options.stdintrue:
                    update_plot.filepos.append(curpos)
                if len(se_meta) == 0:
                    if (nop.get_block_meta(instream, se_meta)):
                        update_plot.pause = True
                        return ax1xy, ax1xryr, execp, ax2xy, ax2xryr
                    del se_meta['k']
                    # I hate doing this, but for now, parse_path_and_error()
                    # doesn't store k, it needs to be taken from the metadata.
                    for key in se_meta:
                        se_meta[key] -= 1
                nop.parse_path_and_error(instream, nmpc, path_and_error)
                path_and_error = np.array(path_and_error)
                break

        # xmin, xmax = ax.get_xlim()
        xrdata = path_and_error[:, se_meta['x']] - path_and_error[:, se_meta['ex']]
        yrdata = path_and_error[:, se_meta['y']] - path_and_error[:, se_meta['ey']]
        ax1xy.set_data(path_and_error[:, se_meta['x']],
                       path_and_error[:, se_meta['y']])
        ax1xryr.set_data(xrdata, yrdata)
        ax2xy.set_data(path_and_error[:, se_meta['x']]
                            - path_and_error[0, se_meta['x']],
                       path_and_error[:, se_meta['y']]
                            - path_and_error[0, se_meta['y']])
        ax2xryr.set_data(xrdata - path_and_error[0, se_meta['x']],
                       yrdata - path_and_error[0, se_meta['y']])
        for k in range(0, nmpc['C']):
            update_plot.exec_path[0].append(path_and_error[k, se_meta['x']])
            update_plot.exec_path[1].append(path_and_error[k, se_meta['y']])
        execp.set_data(update_plot.exec_path[0], update_plot.exec_path[1])
    if update_plot.isstep:
        update_plot.isstep = False
        update_plot.pause = True
    return ax1xy, ax1xryr, execp, ax2xy, ax2xryr
Ejemplo n.º 2
0
# that waypoint is listed.
#

while 1:
    path_and_error = []
    lagrange_and_gradient = []
    # Read the first line after the previous parse. This line should contain
    # the block label (SD), (SE), (LG) or (TR).
    line = instream.readline()
    if len(line) == 0:
        break
    # Detect the report of SD convergence.
    if '(SD)' in line:
        # If we don't have the meta-data, store it.
        if len(sd_meta) == 0:
            if (nop.get_block_meta(instream, sd_meta)):
                break
        if (nop.parse_sd_stats(instream, sd_loops, sd_loop_time)):
            break
    # Detect the state and error output block (SE)
    if '(SE)' in line:
        if len(se_meta) == 0:
            if (nop.get_block_meta(instream, se_meta)):
                break
            del se_meta['k']
            # I hate doing this, but for now, parse_path_and_error() doesn't
            # store k, so it needs to be taken from the meta data.
            for key in se_meta:
                se_meta[key] -= 1
        if (nop.parse_path_and_error(instream, nmpc, path_and_error)):
            break