How to use the haros.metamodel.Parameter function in haros

To help you get started, we’ve selected a few haros examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github git-afsantos / haros / haros / config_builder.py View on Github external
def _new_resource(self, rosname, call, cls):
        config = self.node.configuration
        if cls is Topic:
            return Topic(config, rosname, message_type=call.type)
        elif cls is Service:
            return Service(config, rosname, message_type=call.type)
        elif cls is Parameter:
            return Parameter(config, rosname, call.type, None)
        assert False, "Unknown Resource class {}".format(cls.__name__)
github git-afsantos / haros / haros / metamodel.py View on Github external
def __init__(self, config, rosname, ptype, value,
                 node_scope = False, launch = None, conditions = None):
        Resource.__init__(self, config, rosname, conditions = conditions)
        self.type = ptype or Parameter.type_of(value)
        self.value = value
        self.node_scope = node_scope
        self.reads = []
        self.writes = []
        self.launch = launch
        self._location = launch.location if launch is not None else None
        self.location2 = loc_to_loc2(self._location)
github git-afsantos / haros / haros / config_builder.py View on Github external
def _yaml_param(self, name, value, conditions, private=True,
                    line=None, col=None):
        private = private and name.startswith("~")
        pns = self.private_ns
        node_scope = not self.node is None
        items = self._unfold(name, value)
        for name, value, independent in items:
            independent = name.startswith("/") or name.startswith("~")
            if independent and name.startswith("~"):
                rosname = RosName(name, "/roslaunch", "/roslaunch")
            else:
                rosname = RosName(name, pns, pns)
            param = Parameter(self.configuration, rosname, None, value,
                              node_scope = node_scope,
                              launch = self.launch_file, conditions = conditions)
            if param._location is not None:
                param._location.line = line
                param._location.column = col
            if independent or not private:
                self._add_param(param, self.parameters)
            else:
                self._add_param(param, self._params)
github git-afsantos / haros / haros / config_builder.py View on Github external
def _new_resource(self, rosname, call, cls):
        config = self.node.configuration
        if cls is Topic:
            return Topic(config, rosname, message_type=call.type)
        elif cls is Service:
            return Service(config, rosname, message_type=call.type)
        elif cls is Parameter:
            return Parameter(config, rosname, call.type, None)
        assert False, "Unknown Resource class {}".format(cls.__name__)
github git-afsantos / haros / haros / config_builder.py View on Github external
def _add_param(self, config, name, datum):
        if config.parameters.get(name) is not None:
            self.log.warning(self._W_EXISTS, config.name, "param", name)
            return False
        ptype = datum["param_type"]
        value = datum.get("default_value")
        param = Parameter(config, RosName(name), ptype, value)
        param.location2 = JSON_to_loc2(datum.get("traceability"))
        config.parameters.add(param)
        return True
github git-afsantos / haros / haros / config_builder.py View on Github external
instance._location.column = col
        node.instances.append(instance)
        if not condition is True:
            instance.conditions.append(condition)
        previous = self.configuration.nodes.add(instance)
        new_scope = LaunchScope(self, self.configuration, self.launch_file,
            ns=ns, node=instance, remaps=instance.remaps,
            params=self.parameters, args=self.arguments,
            conditions=instance.conditions)
        self.children.append(new_scope)
        pns = new_scope.private_ns
        for param in self._params:
            rosname = RosName(param.rosname.given, pns, pns)
            conditions = param.conditions + instance.conditions
            self.log.debug("Creating new forward Parameter %s.", rosname.full)
            new_param = Parameter(self.configuration, rosname, param.type,
                param.value, node_scope=param.node_scope,
                launch=param.launch_file, conditions=conditions)
            new_param._location = param._location
            self.parameters.append(new_param)
        return new_scope
github git-afsantos / haros / haros / config_builder.py View on Github external
def make_params(self, name, ptype, value, condition, line=None, col=None):
        if not value is None:
            value = self._convert_value(str(value), ptype)
            ptype = Parameter.type_of(value)
        conditions = list(self.conditions)
        if not condition is True:
            conditions.append(condition)
        if ptype == "yaml" or isinstance(value, dict):
            self._yaml_param(name, value, conditions, line=line, col=col)
        else:
            rosname = RosName(name, self.private_ns, self.private_ns)
            param = Parameter(self.configuration, rosname, ptype, value,
                              node_scope = not self.node is None,
                              launch = self.launch_file,
                              conditions = conditions)
            if param._location is not None:
                param._location.line = line
                param._location.column = col
            if not self.node and rosname.is_private:
                self._add_param(param, self._params)
            else:
                self._add_param(param, self.parameters)