Exemple #1
0
    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}"
            )