1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 try:
34 import roslib; roslib.load_manifest('dynamic_reconfigure')
35 except:
36 pass
37 import rospy
38 import inspect
39 import copy
40
41 from dynamic_reconfigure.msg import Config as ConfigMsg
42 from dynamic_reconfigure.msg import ConfigDescription as ConfigDescrMsg
43 from dynamic_reconfigure.msg import Group as GroupMsg
44 from dynamic_reconfigure.msg import GroupState
45 from dynamic_reconfigure.msg import IntParameter, BoolParameter, StrParameter, DoubleParameter, ParamDescription
46
50
52 return self.__dict__.items()
53
55 for key, val in items:
56 self.__dict__[key] = val
57
60
63
66
69
70 __getattr__ = __getitem__
71 __setattr__ = __setitem__
72
75
77 c = type(self)({})
78 for key, value in self.iteritems():
79 c[copy.deepcopy(key)] = copy.deepcopy(value)
80
81 return c
82
83
91
93 group_list = []
94
95 msg = GroupMsg()
96
97 msg.name = group['name']
98 msg.id = group['id']
99 msg.parent = group['parent']
100 msg.type = group['type']
101
102 for param in group['parameters']:
103 msg.parameters.append(ParamDescription(param['name'], param['type'], param['level'], param['description'], param['edit_method']))
104
105 group_list.append(msg)
106 for next in group['groups']:
107 group_list.extend(encode_groups(msg, next))
108
109 return group_list
110
112 msg = ConfigMsg()
113 for k, v in config.items():
114
115 if type(v) == int: msg.ints.append(IntParameter(k, v))
116 elif type(v) == bool: msg.bools.append(BoolParameter(k, v))
117 elif type(v) == str: msg.strs.append(StrParameter(k, v))
118 elif type(v) == float: msg.doubles.append(DoubleParameter(k, v))
119 elif type(v) == dict or isinstance(v, Config):
120 if flat is True:
121 def flatten(g):
122 groups = []
123 for name, group in g['groups'].items():
124 groups.extend(flatten(group))
125 groups.append(GroupState(group['name'], group['state'], group['id'], group['parent']))
126 return groups
127 msg.groups.append(GroupState(v['name'], v['state'], v['id'], v['parent']))
128 msg.groups.extend(flatten(v))
129 else:
130 msg.groups = [GroupState(x['name'], x['state'], x['id'], x['parent']) for x in v]
131
132 return msg
133
135 try:
136 state = group.state
137 except AttributeError:
138 state = True
139 if hasattr(group, 'type'):
140 type = group.type
141 else:
142 type =''
143 return Config({
144 'id' : group.id,
145 'parent' : group.parent,
146 'name' : group.name,
147 'type' : type,
148 'state': state,
149 'groups' : Config({}),
150 'parameters' : Config({}),
151 })
152
154 mins = decode_config(msg.min)
155 maxes = decode_config(msg.max)
156 defaults = decode_config(msg.dflt)
157 groups = {}
158 grouplist = msg.groups
159
160 def params_from_msg(msg):
161 params = []
162 for param in msg.parameters:
163 name = param.name
164 params.append({
165 'name': name,
166 'min' : mins[name],
167 'max' : maxes[name],
168 'default' : defaults[name],
169 'type' : param.type,
170 'level': param.level,
171 'description' : param.description,
172 'edit_method' : param.edit_method,
173 })
174 return params
175
176
177 for group in grouplist:
178 if group.id == 0:
179 groups = group_dict(group)
180 groups['parameters'] = params_from_msg(group)
181
182 def build_tree(group):
183 children = Config({})
184 for g in grouplist:
185 if g.id == 0:
186 pass
187 elif g.parent == group['id']:
188 gd = group_dict(g)
189
190 gd['parameters'] = params_from_msg(g)
191 gd['groups'] = build_tree(gd)
192
193 children[gd['name']] = gd
194 return children
195
196 groups['groups'] = build_tree(groups)
197
198 return groups
199
201 if group is None:
202 for x in m.groups:
203 if x.id == 0:
204 group = x
205
206 children = Config({})
207 for g in m.groups:
208 if g.id == 0:
209 pass
210 elif g.parent == group.id:
211 gd = group_dict(g)
212
213 gd['groups'] = get_tree(m, g)
214 children[gd['name']] = gd
215
216 if group.id == 0:
217 ret = group_dict(group)
218 ret['groups'] = children
219 return ret
220 else:
221 return children
222
224 d = Config([(kv.name, kv.value) for kv in msg.bools + msg.ints + msg.strs + msg.doubles])
225 def gt(m, descr, group = None):
226
227 if group is None:
228 for x in m.groups:
229 if x.id == 0:
230 group = x
231
232 children = Config({})
233 for g in m.groups:
234 if g.id == 0:
235 pass
236 elif g.parent == group.id:
237 gd = group_dict(g)
238
239 def find_state(gr, dr):
240 for g in dr['groups']:
241 if g['id'] == gr['id']:
242 gr['state'] = g['state']
243 return
244 else:
245 find_state(gr, g)
246 return
247
248 find_state(gd, descr)
249
250
251 gd['groups'] = gt(m, descr, g)
252 children[gd['name']] = gd
253
254 if group.id == 0:
255 ret = group_dict(group)
256 ret['groups'] = children
257 return ret
258 else:
259 return children
260
261 if not msg.groups == [] and description is not None:
262 d["groups"] = gt(msg, description)
263
264 def add_params(group, descr):
265 for param in descr['parameters']:
266 group['parameters'][param['name']] = d[param['name']]
267 for n, g in group['groups'].items():
268 for dr in descr['groups']:
269 if dr['name'] == g['name']:
270 add_params(g, dr)
271
272 add_params(d['groups'], description)
273
274 return d
275
277 d = Config([(kv.name, kv.value) for kv in msg.bools + msg.ints + msg.strs + msg.doubles])
278 if not msg.groups == [] and description is not None:
279 d["groups"] = get_tree(msg)
280
281 def add_params(group, descr):
282 for param in descr['parameters']:
283 if param['name'] in d.keys():
284 group[param['name']] = d[param['name']]
285 for n, g in group['groups'].items():
286 for nr, dr in descr['groups'].items():
287 if dr['name'] == g['name']:
288 add_params(g, dr)
289
290 add_params(d['groups'], description)
291
292 return d
293
295 params = []
296 params.extend(group['parameters'])
297 try:
298 for n,g in group['groups'].items():
299 params.extend(extract_params(g))
300 except AttributeError:
301 for g in group['groups']:
302 params.extend(extract_params(g))
303 return params
304
306 parents = []
307 for p in descriptions['group']:
308 if p['id'] == group['parent']:
309 parents.extend(get_parents(p, descriptions))
310 parents.append(p)
311 return parents
312