예제 #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 __init__(self, boot_spec, value,
              dt=Constants.DEFAULT_SIMULATION_DT):
     self.timestamp = time.time()
     self.dt = dt
     self.value = value
     self.spec = BootSpec.from_yaml(boot_spec)
     self.commands = self.spec.get_commands().get_default_value()
     self.commands_source = Constants.CMD_SOURCE_REST
예제 #3
0
def check_conversions(x):
    spec = BootSpec.from_yaml(x)
    assert isinstance(spec, BootSpec)
    spec_struct = spec.to_yaml()
    assert isinstance(spec_struct, dict)
    spec_struct_yaml = yaml.dump(spec_struct)
    spec_struct2 = yaml.load(spec_struct_yaml)
    spec2 = spec.from_yaml(spec_struct2)
    assert spec == spec2
예제 #4
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
예제 #5
0
 def __init__(self, boot_spec,
              dt=Constants.DEFAULT_SIMULATION_DT, t0=None, y0=None):
     if t0 is None:
         t0 = time.time()
     self.timestamp = t0
     self.dt = dt
     if not isinstance(boot_spec, BootSpec):
         boot_spec = BootSpec.from_yaml(boot_spec) 
     self.spec = boot_spec
     self.commands = self.spec.get_commands().get_default_value()
     self.commands_source = Constants.CMD_SOURCE_REST
     self.y0 = y0
예제 #6
0
def dummy_robot_from_spec(boot_spec_yaml):
    boot_spec = BootSpec.from_yaml(boot_spec_yaml)
    robot = DummyRobot(boot_spec)
    return robot
예제 #7
0
def check_parsing(x):
    BootSpec.from_yaml(x)