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 """
34 Python client API for dynamic_reconfigure (L{DynamicReconfigureClient}) as well as
35 example server implementation (L{DynamicReconfigureServer}).
36 """
37
38 from __future__ import with_statement
39
40 import roslib; roslib.load_manifest('dynamic_reconfigure')
41 import rospy
42 import rosservice
43 import threading
44 import time
45 import copy
46 from dynamic_reconfigure import DynamicReconfigureCallbackException
47 from dynamic_reconfigure.srv import Reconfigure as ReconfigureSrv
48 from dynamic_reconfigure.msg import Config as ConfigMsg
49 from dynamic_reconfigure.msg import ConfigDescription as ConfigDescrMsg
50 from dynamic_reconfigure.msg import IntParameter, BoolParameter, StrParameter, DoubleParameter, ParamDescription
51 from dynamic_reconfigure.encoding import *
52
55 self.mutex = threading.Lock()
56 self.type = type
57 self.config = type.defaults.copy()
58
59 self.description = encode_description(type)
60 self._copy_from_parameter_server()
61 self.callback = callback
62 self._clamp(self.config)
63
64
65 self.config['groups'] = get_tree(self.description)
66 self.config = initial_config(encode_config(self.config), type.config_description)
67
68 self.descr_topic = rospy.Publisher('~parameter_descriptions', ConfigDescrMsg, latch=True)
69 self.descr_topic.publish(self.description);
70
71 self.update_topic = rospy.Publisher('~parameter_updates', ConfigMsg, latch=True)
72 self._change_config(self.config, type.all_level)
73
74 self.set_service = rospy.Service('~set_parameters', ReconfigureSrv, self._set_callback)
75
77 with self.mutex:
78 new_config = copy.deepcopy(self.config)
79 new_config.update(changes)
80 self._clamp(new_config)
81 return self._change_config(new_config, self._calc_level(new_config, self.config))
82
84 for param in extract_params(self.type.config_description):
85 try:
86 self.config[param['name']] = rospy.get_param("~" + param['name'])
87 except KeyError:
88 pass
89
91 for param in extract_params(self.type.config_description):
92 rospy.set_param('~' + param['name'], self.config[param['name']])
93
95 self.config = self.callback(config, level)
96 if self.config is None:
97 msg = 'Reconfigure callback should return a possibly updated configuration.'
98 rospy.logerr(msg)
99 raise DynamicReconfigureCallbackException(msg)
100
101 self._copy_to_parameter_server()
102
103 self.update_topic.publish(encode_config(self.config))
104
105 return self.config
106
108 level = 0
109 for param in extract_params(self.type.config_description):
110 if config1[param['name']] != config2[param['name']]:
111 level |= param['level']
112
113 return level
114
116 for param in extract_params(self.type.config_description):
117 maxval = self.type.max[param['name']]
118 minval = self.type.min[param['name']]
119 val = config[param['name']]
120 if val > maxval and maxval != "":
121 config[param['name']] = maxval
122 elif val < minval and minval != "":
123 config[param['name']] = minval
124
127