def get_field(self, comp):
        field = m3t.user_select_msg_field(comp.status)
        self.idx = 0
        if hasattr(m3t.get_msg_field_value(comp.status, field), '__len__'):
            self.repeated = True
            print 'Select index of repeated fields to monitor: [0]'
            self.idx = m3t.get_int(0)

        return field
Ejemplo n.º 2
0
def do_plot(proxy):
    print 'Starting plot...'
    print 'Enter log name [foo]'
    logname = m3t.get_string('foo')
    ns = proxy.get_log_num_samples(logname)
    if ns == 0:
        return
    print '-------- Available components --------'
    names = proxy.get_log_component_names(logname)
    for i in range(len(names)):
        print names[i]
    print '--------------------------------------'
    print 'Select component: [', names[0], ']'
    name = m3t.get_string(names[0])
    print '--------------------------------------'
    print 'Num samples available: ', ns
    print 'Enter start sample idx: [0]'
    start = max(0, m3t.get_int(0))
    print 'Enter end sample idx: [', ns - 1, ']'
    end = min(ns - 1, m3t.get_int(ns - 1))
    print '--------------------------------------'
    print ' Select field to plot...'
    comp = mcf.create_component(name)
    proxy.register_log_component(comp)
    field = m3t.user_select_msg_field(comp.status)

    repeated = False
    idx = 0
    if hasattr(m3t.get_msg_field_value(comp.status, field), '__len__'):
        repeated = True
        print 'Select index of repeated field to monitor: [0]'
        idx = m3t.get_int(0)

    print 'Fetching data...'
    data = []

    for i in range(start, end):
        proxy.load_log_sample(logname, i)
        if repeated:
            v = m3t.get_msg_field_value(comp.status, field)[idx]
        else:
            v = m3t.get_msg_field_value(comp.status, field)
        data.append(v)
        #       m3t.plot(data)
    m3t.mplot(data, range(len(data)))
Ejemplo n.º 3
0
def do_plot(proxy):
       print 'Starting plot...'
       print 'Enter log name [foo]'
       logname=m3t.get_string('foo')
       ns=proxy.get_log_num_samples(logname)
       if ns==0:
              return
       print '-------- Available components --------'
       names=proxy.get_log_component_names(logname)
       for i in range(len(names)):
              print names[i]
       print '--------------------------------------'
       print 'Select component: [',names[0],']'
       name=m3t.get_string(names[0])
       print '--------------------------------------'
       print 'Num samples available: ',ns
       print 'Enter start sample idx: [0]'
       start=max(0,m3t.get_int(0))
       print 'Enter end sample idx: [',ns-1,']'
       end=min(ns-1,m3t.get_int(ns-1))
       print '--------------------------------------'
       print ' Select field to plot...'
       comp=mcf.create_component(name)
       proxy.register_log_component(comp)
       field=m3t.user_select_msg_field(comp.status)
              
       repeated = False
       idx = 0
       if hasattr(m3t.get_msg_field_value(comp.status,field),'__len__'):
              repeated = True
              print 'Select index of repeated field to monitor: [0]'
              idx = m3t.get_int(0)              
              
       print 'Fetching data...'
       data=[]

       for i in range(start,end):
              proxy.load_log_sample(logname,i)
              if repeated:
                     v=m3t.get_msg_field_value(comp.status,field)[idx]
              else:
                     v=m3t.get_msg_field_value(comp.status,field)       
              data.append(v)
              #       m3t.plot(data)
       m3t.mplot(data,range(len(data)))
Ejemplo n.º 4
0
def do_scope(proxy):
    print 'Starting scope...'
    print 'Enter log name [foo]'
    logname = m3t.get_string('foo')
    ns = proxy.get_log_num_samples(logname)
    print 'Num samples available: ', ns
    if ns == 0:
        return
    print '-------- Available components --------'
    names = proxy.get_log_component_names(logname)
    for i in range(len(names)):
        print names[i]
    print '--------------------------------------'
    print 'Select component: [', names[0], ']'
    name = m3t.get_string(names[0])
    comp = mcf.create_component(name)
    proxy.register_log_component(comp)
    scope = m3t.M3Scope(xwidth=ns - 1)
    print '--------------------------------------'
    print 'Num samples available: ', ns
    print 'Enter start sample idx: [0]'
    start = max(0, m3t.get_int(0))
    print 'Enter end sample idx: [', ns - 1, ']'
    end = min(ns - 1, m3t.get_int(ns - 1))
    print '--------------------------------------'
    print 'Select field to monitor'

    field = m3t.user_select_msg_field(comp.status)

    repeated = False
    idx = 0
    if hasattr(m3t.get_msg_field_value(comp.status, field), '__len__'):
        repeated = True
        print 'Select index of repeated field to monitor: [0]'
        idx = m3t.get_int(0)

    for i in range(start, end):
        proxy.load_log_sample(logname, i)
        if repeated:
            v = m3t.get_msg_field_value(comp.status, field)[idx]
        else:
            v = m3t.get_msg_field_value(comp.status, field)
        scope.plot(v)
        time.sleep(0.05)
Ejemplo n.º 5
0
def do_scope(proxy):
       print 'Starting scope...'
       print 'Enter log name [foo]'
       logname=m3t.get_string('foo')
       ns=proxy.get_log_num_samples(logname)
       print 'Num samples available: ',ns
       if ns==0:
              return
       print '-------- Available components --------'
       names=proxy.get_log_component_names(logname)
       for i in range(len(names)):
              print names[i]
       print '--------------------------------------'
       print 'Select component: [',names[0],']'
       name=m3t.get_string(names[0])
       comp=mcf.create_component(name)
       proxy.register_log_component(comp)
       scope=m3t.M3Scope(xwidth=ns-1)
       print '--------------------------------------'
       print 'Num samples available: ',ns
       print 'Enter start sample idx: [0]'
       start=max(0,m3t.get_int(0))
       print 'Enter end sample idx: [',ns-1,']'
       end=min(ns-1,m3t.get_int(ns-1))
       print '--------------------------------------'
       print 'Select field to monitor'
       
       field=m3t.user_select_msg_field(comp.status)
       
       repeated = False
       idx = 0
       if hasattr(m3t.get_msg_field_value(comp.status,field),'__len__'):
              repeated = True
              print 'Select index of repeated field to monitor: [0]'
              idx = m3t.get_int(0)              
       
       for i in range(start,end):
              proxy.load_log_sample(logname,i)
              if repeated:
                     v=m3t.get_msg_field_value(comp.status,field)[idx]
              else:
                     v=m3t.get_msg_field_value(comp.status,field)
              scope.plot(v)
              time.sleep(0.05)
	for i in range(len(cnames)):
		print i,' : ',cnames[i]
	print '-------------------------'
	print 'Enter component id'
	cid=m3t.get_int()
	name=cnames[cid]
	comps.append(mcf.create_component(name))
if len(comps)==0:
	print 'No components selected'
	exit()

for c in comps:
	proxy.subscribe_status(c)
	proxy.publish_command(c)

field=m3t.user_select_msg_field(comps[0].status)
print 'Number of samples [100]?'
ns=m3t.get_int(100)
log=[]
for i in range(len(comps)):
	log.append([])
try:
	ts=time.time()
	for i in range(ns):
		proxy.step()
		idx=0
		print '---------'
		for c in comps:
			v=m3t.get_msg_field_value(c.status,field)
			log[idx].append(v)
			idx=idx+1
Ejemplo n.º 7
0
def do_dump(proxy):
    print 'Starting dump...'
    print 'Enter log name [foo]'
    logname = m3t.get_string('foo')
    ns = proxy.get_log_num_samples(logname)
    if ns == 0:
        return
    print '-------- Available components --------'
    names = proxy.get_log_component_names(logname)
    for i in range(len(names)):
        print names[i]
    print '--------------------------------------'
    print 'Select component: [', names[0], ']'
    name = m3t.get_string(names[0])
    print '--------------------------------------'
    print 'Num samples available: ', ns
    print 'Enter start sample idx: [0]'
    start = max(0, m3t.get_int(0))
    print 'Enter end sample idx: [', ns - 1, ']'
    end = min(ns - 1, m3t.get_int(ns - 1))
    print '--------------------------------------'
    comp = mcf.create_component(name)
    proxy.register_log_component(comp)
    fields = []
    print 'Dump all data?[n]'
    if m3t.get_yes_no('n'):
        '''print 'Fetching data...'
              fn=m3t.get_m3_log_path()+logname+'/'+logname+'_dump.yaml'
              f=file(fn,'w')
              print 'Saving...',fn
              f.write(yaml.safe_dump(comp.status, default_flow_style=False,width=200))
              f.close()'''
        fields = comp.status.DESCRIPTOR.fields_by_name.keys()
        print fields
    else:
        print ' Select fields to plot...'
        while True:
            fields.append(m3t.user_select_msg_field(comp.status))
            print 'Another field [n]?'
            if not m3t.get_yes_no('n'):
                break
    print 'Fetching data...'
    data = {}
    for k in fields:
        data[k] = []
        print '---------------------------'
        print k
        print m3t.get_msg_field_value(comp.status, k)
        print dir(m3t.get_msg_field_value(comp.status, k))

        if hasattr(m3t.get_msg_field_value(comp.status, k), '__len__'):
            for j in range(len(m3t.get_msg_field_value(comp.status, k))):
                data[k].append([])

    for i in range(start, end):
        proxy.load_log_sample(logname, i)
        for k in fields:
            repeated = False
            # skip protobuf subclasses (like base) for now.  note we'll want this for humanoid
            if hasattr(m3t.get_msg_field_value(comp.status, k),
                       '__metaclass__'):
                pass
            elif hasattr(m3t.get_msg_field_value(comp.status, k), '__len__'):
                for j in range(len(m3t.get_msg_field_value(comp.status, k))):
                    data[k][j].append(
                        m3t.get_msg_field_value(comp.status, k)[j])
            else:
                data[k].append(m3t.get_msg_field_value(comp.status, k))
    fn = m3t.get_m3_log_path() + logname + '/' + logname + '_dump.yaml'
    f = file(fn, 'w')
    print 'Saving...', fn
    print data
    f.write(yaml.safe_dump(data, default_flow_style=False, width=200))
    f.close()
Ejemplo n.º 8
0
print '-------------------------'
print 'Enter component id'
cid = m3t.get_int()
print 'Select Y-Range? [n]'
yrange = None
if m3t.get_yes_no('n'):
    yrange = []
    print 'Min?'
    yrange.append(m3t.get_int())
    print 'Max?'
    yrange.append(m3t.get_int())
name = comps[cid]
comp = mcf.create_component(name)
proxy.subscribe_status(comp)
#proxy.publish_param(comp)
field = m3t.user_select_msg_field(comp.status)
repeated = False
idx = 0
if hasattr(m3t.get_msg_field_value(comp.status, field), '__len__'):
    repeated = True
    print 'Select index of repeated field to monitor: [0]'
    idx = m3t.get_int(0)

scope = m3t.M3Scope(xwidth=100, yrange=yrange)
try:
    ts = time.time()
    while True:
        proxy.step()
        if repeated:
            v = m3t.get_msg_field_value(comp.status, field)[idx]
        else:
Ejemplo n.º 9
0
def do_dump(proxy):
       print 'Starting dump...'
       print 'Enter log name [foo]'
       logname=m3t.get_string('foo')
       ns=proxy.get_log_num_samples(logname)
       if ns==0:
              return
       print '-------- Available components --------'
       names=proxy.get_log_component_names(logname)
       for i in range(len(names)):
              print names[i]
       print '--------------------------------------'
       print 'Select component: [',names[0],']'
       name=m3t.get_string(names[0])
       print '--------------------------------------'
       print 'Num samples available: ',ns
       print 'Enter start sample idx: [0]'
       start=max(0,m3t.get_int(0))
       print 'Enter end sample idx: [',ns-1,']'
       end=min(ns-1,m3t.get_int(ns-1))
       print '--------------------------------------'
       comp=mcf.create_component(name)
       proxy.register_log_component(comp)
       fields=[]
       print 'Dump all data?[n]'       
       if m3t.get_yes_no('n'):
              '''print 'Fetching data...'
              fn=m3t.get_m3_log_path()+logname+'/'+logname+'_dump.yaml'
              f=file(fn,'w')
              print 'Saving...',fn
              f.write(yaml.safe_dump(comp.status, default_flow_style=False,width=200))
              f.close()'''
              fields=comp.status.DESCRIPTOR.fields_by_name.keys()
              print fields
       else:
              print ' Select fields to plot...'
              while True:
                     fields.append(m3t.user_select_msg_field(comp.status))
                     print 'Another field [n]?'
                     if not m3t.get_yes_no('n'):
                            break
       print 'Fetching data...'
       data={}
       for k in fields:
              data[k]=[]
              print '---------------------------'
              print k
              print m3t.get_msg_field_value(comp.status,k)
              print dir(m3t.get_msg_field_value(comp.status,k))
              
              if hasattr(m3t.get_msg_field_value(comp.status,k),'__len__'):
                     for j in range(len(m3t.get_msg_field_value(comp.status,k))):
                            data[k].append([])
                     
                     
       for i in range(start,end):
              proxy.load_log_sample(logname,i)
              for k in fields:
                     repeated = False
                     # skip protobuf subclasses (like base) for now.  note we'll want this for humanoid
                     if hasattr(m3t.get_msg_field_value(comp.status,k),'__metaclass__'):
                            pass
                     elif hasattr(m3t.get_msg_field_value(comp.status,k),'__len__'):       
                            for j in range(len(m3t.get_msg_field_value(comp.status,k))):
                                   data[k][j].append(m3t.get_msg_field_value(comp.status,k)[j])
                     else:
                            data[k].append(m3t.get_msg_field_value(comp.status,k))
       fn=m3t.get_m3_log_path()+logname+'/'+logname+'_dump.yaml'
       f=file(fn,'w')
       print 'Saving...',fn
       print data
       f.write(yaml.safe_dump(data, default_flow_style=False,width=200))
       f.close()