def __init__(self): super().__init__('slide_show') self._bridge = cv_bridge.CvBridge() dir_desc = ParameterDescriptor() # TODO(sloretz) Allow changing directory dir_desc.read_only = True dir_desc.description = 'Directory from which images will be published' dir_desc.type = ParameterType.PARAMETER_STRING dir_desc.name = 'directory' self.declare_parameter(dir_desc.name, os.path.abspath(os.curdir), dir_desc) self._dirpath = self.get_parameter(dir_desc.name).value self._current_file = None image_qos = QoSProfile(history=QoSHistoryPolicy.KEEP_LAST, durability=QoSDurabilityPolicy.TRANSIENT_LOCAL, reliability=QoSReliabilityPolicy.RELIABLE, depth=1) self._image_pub = self.create_publisher(Image, 'images', image_qos) period_desc = ParameterDescriptor() # TODO(sloretz) allow changing period period_desc.read_only = True period_desc.description = 'Time between publishing images (seconds)' period_desc.type = ParameterType.PARAMETER_DOUBLE period_desc.name = 'period' self.declare_parameter(period_desc.name, 5.0, period_desc) period = self.get_parameter(period_desc.name).value self._next_slide_timer = self.create_timer(period, self.on_timer) self.publish_next()
def _declare_qos_parameters(entity_type: Union[Type[Publisher], Type[Subscription]], node: 'Node', topic_name: Text, qos: QoSProfile, options: QoSOverridingOptions) -> QoSProfile: """ Declare QoS parameters for a Publisher or a Subscription. :param entity_type: Either `rclpy.node.Publisher` or `rclpy.node.Subscription`. :param node: Node used to declare the parameters. :param topic_name: Topic name of the entity being created. :param qos: Default QoS settings of the entity being created, that will be overridden with the user provided QoS parameter overrides. :param options: Options that indicates which parameters are going to be declared. """ if not issubclass(entity_type, (Publisher, Subscription)): raise TypeError( 'Argument `entity_type` should be a subclass of Publisher or Subscription' ) entity_type_str = 'publisher' if issubclass(entity_type, Publisher) else 'subscription' id_suffix = '' if options.entity_id is None else f'_{options.entity_id}' name = f'qos_overrides.{topic_name}.{entity_type_str}{id_suffix}.' '{}' description = '{}' f' for {entity_type_str} `{topic_name}` with id `{options.entity_id}`' allowed_policies = _get_allowed_policies(entity_type) for policy in options.policy_kinds: if policy not in allowed_policies: continue policy_name = policy.name.lower() descriptor = ParameterDescriptor() descriptor.description = description.format(policy_name) descriptor.read_only = True try: param = node.declare_parameter( name.format(policy_name), _get_qos_policy_parameter(qos, policy), descriptor) except ParameterAlreadyDeclaredException: param = node.get_parameter(name.format(policy_name)) _override_qos_policy_with_param(qos, policy, param) if options.callback is not None: result = options.callback(qos) if not result.successful: raise InvalidQosOverridesError( f"{description.format('Provided QoS overrides')}, are not valid: {result.reason}" )
def add(self, param_name, param_type=None, default=None, description=None, min=None, max=None, step=None): describtor = ParameterDescriptor() describtor.name = param_name if description is None: describtor.description = param_name else: describtor.description = description if param_type is None and default is not None: param_type = type(default) py2ros_param_type = { None: ParameterType.PARAMETER_NOT_SET, bool: ParameterType.PARAMETER_BOOL, int: ParameterType.PARAMETER_INTEGER, float: ParameterType.PARAMETER_DOUBLE, str: ParameterType.PARAMETER_STRING } param_type = py2ros_param_type.get(param_type, param_type) describtor.type = param_type if param_type == ParameterType.PARAMETER_INTEGER: if step is None: step = 1 if all(x is not None or isinstance(x, int) for x in [min, max, step]): param_range = IntegerRange() param_range.from_value = min param_range.to_value = max param_range.step = step describtor.integer_range = [param_range] if param_type == ParameterType.PARAMETER_DOUBLE: if step is None: step = 0.01 if all(x is not None for x in [min, max]): param_range = FloatingPointRange() param_range.from_value = float(min) param_range.to_value = float(max) param_range.step = float(step) describtor.floating_point_range = [param_range] type2default_default = { ParameterType.PARAMETER_NOT_SET: 0, ParameterType.PARAMETER_BOOL: False, ParameterType.PARAMETER_INTEGER: 0, ParameterType.PARAMETER_DOUBLE: 0.0, ParameterType.PARAMETER_STRING: "" } if default is None: default = type2default_default[param_type] self.param_cache.append((param_name, default, describtor))