Esempio n. 1
0
def plot_trends(fr, id=None, instr=3, cmd=30, make_plot=True):
    """A file stream of packets is filtered and plotted
    
    The packet stream is stored as a dictionary of lists, with each list
    corresponding to a servo ID.
    
    Parameters
    ----------
    fr : file stream
        e.g. via ``open('file', 'r')``
    (optional)
    id : list/tuple of integers
        ID #s to keep
    instr : list/tuple of integers
        instruction values to keep
    cmd : integer
        command value to keep
    make_plot : boolean
        If False, plotting is skipped.
    
    Returns
    ----------
    plotting_dict : dictionary
        the dictionary storing the lists that would be plotted
    """
    # Get values from PyDyConfigParser:
    cfg = PyDyConfigParser()
    cfg.read()
    subplot_dict = cfg.get_plot_config()
    id_dict = cfg.get_id_to_device_dict()

    # get list of packets, each packet is a list of integers
    packets = PyDyParser.filtering_method(fr, f_id=id, f_instr=instr, \
            f_cmd=cmd, sync_split=True)

    plotting_dict = {}
    for packet in packets:
        if packet[0] != "255":
            xval = [float(packet[0])]
            packet = packet[1:]
        else:
            xval = []
        
        # packet_id = str(packet[_id])
        packet_id = packet[_id]
        
        if packet_id in plotting_dict.keys():
            plotting_dict[packet_id].append(sum_single_cmd_val(packet, cmd, id_dict))
        else:
            plotting_dict[packet_id] = [ sum_single_cmd_val(packet, cmd, id_dict) ]

    # plotkeys is the list (and order) of plots to make
    if id is None:
        plotkeys = plotting_dict.keys()
    else:
        plotkeys = PyDyParser._is_list(id)
        # This preserves the user-specified order, but tosses IDs that weren't
        # in the filtered packets.
        plotkeys = [x for x in plotkeys if x in plotting_dict.keys()]

    # Generate the plots
    fignum = 1
    plt.figure(1)
    cnt = 0;
    for key in plotkeys:
        # If reached the limit of 'plots per window,' then next plots
        # are in a new window.
        if cnt == len(subplot_dict.keys()):
            fignum += 1
            plt.figure(fignum)
            cnt = 0
        
        plt.subplot(subplot_dict[cnt])
        plt.plot(plotting_dict[key])
        plt.title("{1} ID: {0}".format(key, id_dict[key]))
        
        cnt += 1

    if make_plot:
        plt.show()

    # script pauses until plot window is closed.

    return plotting_dict
Esempio n. 2
0
print '\t'.join(PDP.translate_packet([0xff,0xff,0x00,0x04,0x03,0x04,0x01,0xf3], z)) # write
print '\t'.join(PDP.translate_packet([0xff,0xff,0x00,0x03,0x03,0x04,0xf2], z)) # write
print '\t'.join(PDP.translate_packet([0xff,0xff,0x01,0x04,0x02,0x00,0x03,0xf5], z)) #read data
print '\t'.join(PDP.translate_packet([0xff,0xff,0x00,0x02,0x06,0xf7], z)) #reset
print '\t'.join(PDP.translate_packet([0xff,0xff,0x01,0x02,0x01,0xfb], z)) #ping
print '\t'.join(PDP.translate_packet([0xff,0xff,0x01,0x02,0x05,0xf7], z)) #action
print '\t'.join(PDP.translate_packet([0xff,0xff,0x00,0x07,0x03,0x1e,0x00,0x02,0x00,0x02,0xd3], z)) #example 18

print "\nWith timestamps..."
print "\t".join(PDP.translate_packet([123.445,0xff,0xff,0x00,0x04,0x03,0x04,0x01,0xf3], z)) # write
print "\t".join(PDP.translate_packet([123.445,0xff,0xff,0x00,0x04,0x03,0x04,0x01,0xf3], z, True)) # write
print '\t'.join(PDP.translate_packet([123.445, \
        0XFF,0XFF,0XFE,0X18,0X83,0X1E,0X04,
        0X00,0X10,0X00,0X50,0X01,
        0X01,0X20,0X02,0X60,0X03,
        0X02,0X30,0X00,0X70,0X01,
        0X03,0X20,0X02,0X80,0X03,
        0X12], z, True) )
print "\nSplit sync packet"
mypackets = PDPar.make_packets_from_sync_write_packet([ \
        0XFF,0XFF,0XFE,0X18,0X83,0X1E,0X04,
        0X00,0X10,0X00,0X50,0X01,
        0X01,0X20,0X02,0X60,0X03,
        0X02,0X30,0X00,0X70,0X01,
        0X03,0X20,0X02,0X80,0X03,
        0X12])

for x in mypackets:
    print x
    print "\t".join(PDP.translate_packet(x, z, True))
Esempio n. 3
0
def plot_trends(fr, id=None, instr=3, cmd=30, make_plot=True):
    """A file stream of packets is filtered and plotted
    
    The packet stream is stored as a dictionary of lists, with each list
    corresponding to a servo ID.
    
    Parameters
    ----------
    fr : file stream
        e.g. via ``open('file', 'r')``
    (optional)
    id : list/tuple of integers
        ID #s to keep
    instr : list/tuple of integers
        instruction values to keep
    cmd : integer
        command value to keep
    make_plot : boolean
        If False, plotting is skipped.
    
    Returns
    ----------
    plotting_dict : dictionary
        the dictionary storing the lists that would be plotted
    """
    # Get values from PyDyConfigParser:
    cfg = PyDyConfigParser()
    cfg.read()
    subplot_dict = cfg.get_plot_config()
    id_dict = cfg.get_id_to_device_dict()

    # get list of packets, each packet is a list of integers
    packets = PyDyParser.filtering_method(fr, f_id=id, f_instr=instr, \
            f_cmd=cmd, sync_split=True)

    plotting_dict = {}
    for packet in packets:
        if packet[0] != "255":
            xval = [float(packet[0])]
            packet = packet[1:]
        else:
            xval = []

        # packet_id = str(packet[_id])
        packet_id = packet[_id]

        if packet_id in plotting_dict.keys():
            plotting_dict[packet_id].append(
                sum_single_cmd_val(packet, cmd, id_dict))
        else:
            plotting_dict[packet_id] = [
                sum_single_cmd_val(packet, cmd, id_dict)
            ]

    # plotkeys is the list (and order) of plots to make
    if id is None:
        plotkeys = plotting_dict.keys()
    else:
        plotkeys = PyDyParser._is_list(id)
        # This preserves the user-specified order, but tosses IDs that weren't
        # in the filtered packets.
        plotkeys = [x for x in plotkeys if x in plotting_dict.keys()]

    # Generate the plots
    fignum = 1
    plt.figure(1)
    cnt = 0
    for key in plotkeys:
        # If reached the limit of 'plots per window,' then next plots
        # are in a new window.
        if cnt == len(subplot_dict.keys()):
            fignum += 1
            plt.figure(fignum)
            cnt = 0

        plt.subplot(subplot_dict[cnt])
        plt.plot(plotting_dict[key])
        plt.title("{1} ID: {0}".format(key, id_dict[key]))

        cnt += 1

    if make_plot:
        plt.show()

    # script pauses until plot window is closed.

    return plotting_dict