launchtree_config.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import rospy
3 from roslaunch.config import ROSLaunchConfig
4 from roslaunch.core import Param
5 
6 class LaunchtreeArg(object):
7  def __init__(self, name, default=None, value=None, doc=None):
8  self.name = name
9  self.default = default
10  self.value = value
11  self.doc = doc
12  def merge(self, other):
13  if self.default is None and other.default is not None:
14  self.default = other.default
15  if self.value is None and other.value is not None:
16  self.value = other.value
17  if self.doc is None and other.doc is not None:
18  self.doc = other.doc
19 
20 class LaunchtreeRemap(object):
21  def __init__(self, from_topic, to_topic):
22  self.from_topic = from_topic
23  self.to_topic = to_topic
24 
25 class LaunchtreeParam(Param):
26  def __init__(self, key, value, command):
27  super(LaunchtreeParam, self).__init__(key, value)
28  self.command = command
29 
30 class LaunchtreeRosparam(object):
31  def __init__(self, command, filename):
32  self.command = command
33  self.filename = filename
34 
35 class LaunchtreeConfig(ROSLaunchConfig):
36 
37  def __init__(self):
38  super(LaunchtreeConfig, self).__init__()
39 
40  self._tree_stack = list()
41  self.tree = dict()
42  self.idx = 0
43 
44  def push_level(self, tree_level, unique=False):
45  if unique:
46  tree_level += ':%d' % self.idx
47  self.idx += 1
48  self._tree_stack.append(tree_level)
49  return tree_level
50 
51  def pop_level(self):
52  return self._tree_stack.pop()
53 
54  def _add_to_tree(self, key, instance):
55  level = self.tree
56  for launch in self._tree_stack:
57  if not launch in level:
58  level[launch] = dict()
59  elif not isinstance(level[launch], dict):
60  old_instance = level[launch]
61  level[launch] = dict()
62  level[launch + ':%d' % self.idx] = old_instance
63  self.idx += 1
64  level = level[launch]
65  if level.has_key(key):
66  if isinstance(level[key], dict) and not '_root' in level[key]:
67  # this assumes that the root is added right after its children
68  level[key]['_root'] = instance
69  elif isinstance(instance, LaunchtreeArg) and isinstance(level[key], LaunchtreeArg):
70  level[key].merge(instance)
71  else:
72  level[key + ':%d' % self.idx] = instance
73  self.idx += 1
74  else:
75  level[key] = instance
76 
77  def add_executable(self, exe):
78  result = super(LaunchtreeConfig, self).add_executable(exe)
79  self._add_to_tree(exe.command, exe)
80  return result
81 
82  def add_param(self, p, filename=None, verbose=True, command=None):
83  p.inconsistent = False
84  if p.key in self.params and (p.value != self.params[p.key].value or self.params[p.key].inconsistent):
85  p.inconsistent = True
86  self.params[p.key].inconsistent = True
87  rospy.logwarn('Inconsistent param: %s\n - %s: %s\n - %s: %s' %
88  (p.key, p.key, str(p.value), self.params[p.key].key, str(self.params[p.key].value)))
89  result = super(LaunchtreeConfig, self).add_param(p, filename, verbose)
90  self._add_to_tree(p.key, p)
91  return result
92 
93  def add_machine(self, m, verbose=True):
94  result = super(LaunchtreeConfig, self).add_machine(m, verbose)
95  self._add_to_tree(m.name, m)
96  return result
97 
98  def add_test(self, test, verbose=True):
99  result = super(LaunchtreeConfig, self).add_test(test, verbose)
100  self._add_to_tree(test.name, test)
101  return result
102 
103  def add_node(self, node, core=False, verbose=True):
104  result = super(LaunchtreeConfig, self).add_node(node, core, verbose)
105  self._add_to_tree(node.name, node)
106  return result
107 
108  def add_arg(self, name, default=None, value=None, doc=None):
109  self._add_to_tree(name, LaunchtreeArg(name, default, value, doc))
110 
111  def add_remap(self, from_topic, to_topic):
112  self._add_to_tree(from_topic, LaunchtreeRemap(from_topic, to_topic))
113 
114  def add_rosparam(self, command, filename, unique_name):
115  self._add_to_tree(unique_name, LaunchtreeRosparam(command, filename))
def add_param(self, p, filename=None, verbose=True, command=None)
def add_rosparam(self, command, filename, unique_name)
def add_arg(self, name, default=None, value=None, doc=None)
def __init__(self, name, default=None, value=None, doc=None)
def add_node(self, node, core=False, verbose=True)
def push_level(self, tree_level, unique=False)


rqt_launchtree
Author(s): Philipp Schillinger
autogenerated on Mon Jun 10 2019 14:55:27