示例#1
0
def get_camera_info_for_robot(robot_name: str) -> CameraInfo:
    """
        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)
        fn = None
    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 = f"Invalid data in file {fn}"
        raise InvalidCameraInfo(msg) from e

    check_camera_info_sane_for_DB17(camera_info)

    return camera_info
示例#2
0
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"])
示例#3
0
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")
示例#4
0
def load_configuration(realpath, contents) -> EasyNodeConfig:
    # 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)
            raise  # ide not smart
        if not isinstance(data, dict):
            msg = f"Expected a dict, got {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 = f"Invalid configuration: missing field {key!r}."
            raise dtu.DTConfigException(msg)

        if not isinstance(description, (str, NoneType)):
            msg = f"Description should be a string, not {type(description).__name__}."
            raise dtu.DTConfigException(msg)

        if data:
            msg = f"Spurious fields found: {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 = f"Invalid configuration at {realpath}: "
        dtu.raise_wrapped(dtu.DTConfigException, e, msg, compact=True)