Пример #1
0
def boot_spec_from_ros_message(msg):
    ''' Infers the boot spec from a ROS message. '''

    # Previously, we used to write only the range as a string
    # for example, '[[0,1],[0,1],[0,1]]'
    # But now, we use the YAML spec directly.
    spec_string = msg.commands_spec

    if spec_string[0] == '[':
        commands_spec = eval(spec_string) # XXX: not safe 
        sensels_shape = msg.sensel_shape # TODO: check coherence

        nu = len(commands_spec)
        spec = {
                'observations': {
                     'shape': list(sensels_shape),
                     'range': [0, 1], # XXX: we need something else here
                     'format': 'C'
                },
                'commands': {
                     'shape': [nu],
                     'range': map(list, commands_spec),
                     'format': ['C'] * nu
                }
        }
        return BootSpec.from_yaml(spec)
    elif spec_string[0] == '{':
        return BootSpec.from_yaml(yaml_load(spec_string))

    else:
        raise ValueError('Cannot interpret spec for msg:\n%s' % spec_string)
Пример #2
0
def load_extra(extra_table, index):
    extra_string = str(extra_table[index])
    extra_string = zlib.decompress(extra_string)
    extra = yaml_load(extra_string)
    if not isinstance(extra, dict):
        msg = ('Expected to deserialize a dict, obtained %r' 
               % describe_type(extra))
        raise Exception(msg)
    return extra
Пример #3
0
def spec_from_group(group):
    data_table = group.boot_stream
    if 'boot_spec' in data_table.attrs:
        # Old version
        specs = str(data_table.attrs['boot_spec'])
    else:
        specs = str(group.boot_spec[0])
    spec = BootSpec.from_yaml(yaml_load(specs))
    return spec