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 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))