def get_camera_info_for_robot(robot_name): """ Returns a CameraInfo object for the given robot. This is in a good format to pass to PinholeCameraModel: self.pcm = PinholeCameraModel() self.pcm.fromCameraInfo(self.ci) The fields are simply lists (not array or matrix). Raises: NoCameraInfoAvailable if no info available InvalidCameraInfo if the info exists but is invalid """ if robot_name == dtu.DuckietownConstants.ROBOT_NAME_FOR_TESTS: calib_data = dtu.yaml_load(default_camera_info) else: # find the file fn = get_camera_info_config_file(robot_name) # load the YAML calib_data = dtu.yaml_load_file(fn, plain_yaml=True) # convert the YAML try: camera_info = camera_info_from_yaml(calib_data) except InvalidCameraInfo as e: msg = 'Invalid data in file %s' % fn dtu.raise_wrapped(InvalidCameraInfo, e, msg) #check_camera_info_sane_for_DB17(camera_info) return camera_info
def parse_reg_test(): x = dtu.yaml_load(s) if isinstance(x['description'], unicode): msg = 'I do not expect Unicode' msg += '\n' + x.__repr__() raise ValueError(msg) _ = dtu.instantiate(x['constructor'], x['parameters'])
def parse_reg_fail(): x = dtu.yaml_load(s_fail) print x.__repr__() try: _ = dtu.instantiate(x['constructor'], x['parameters']) except RTParseError: pass else: raise Exception('Expected failure')
def get_homography_for_robot(robot_name): dtu.check_isinstance(robot_name, str) # find the file if robot_name == dtu.DuckietownConstants.ROBOT_NAME_FOR_TESTS: data = dtu.yaml_load(homography_default) else: fn = get_homography_info_config_file(robot_name) # load the YAML data = dtu.yaml_load_file(fn) # convert the YAML homography = homography_from_yaml(data) #check_homography_sane_for_DB17(homography) return homography
def load_configuration(realpath, contents): # TODO: load "version" string try: try: data = dtu.yaml_load(contents) except Exception as e: msg = 'Could not parse YAML file properly:' dtu.raise_wrapped(dtu.DTConfigException, e, msg, compact=True) if not isinstance(data, dict): msg = 'Expected a dict, got %s.' % type(data).__name__ raise dtu.DTConfigException(msg) try: parameters = data.pop('parameters') subscriptions = data.pop('subscriptions') publishers = data.pop('publishers') contracts = data.pop('contracts') description = data.pop('description') except KeyError as e: key = e.args[0] msg = 'Invalid configuration: missing field %r.' % (key) raise dtu.DTConfigException(msg) if not isinstance(description, (str, NoneType)): msg = 'Description should be a string, not %s.' % type( description).__name__ raise dtu.DTConfigException(msg) if data: msg = 'Spurious fields found: %s' % sorted(data) raise dtu.DTConfigException(msg) parameters = load_configuration_parameters(parameters) subscriptions = load_configuration_subscriptions(subscriptions) contracts = load_configuration_contracts(contracts) publishers = load_configuration_publishers(publishers) return EasyNodeConfig(filename=realpath, parameters=parameters, contracts=contracts, subscriptions=subscriptions, publishers=publishers, package_name=None, description=description, node_type_name=None) except dtu.DTConfigException as e: msg = 'Invalid configuration at %s: ' % realpath dtu.raise_wrapped(dtu.DTConfigException, e, msg, compact=True)