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 from dynamic_reconfigure import DynamicReconfigureCallbackException
46 from dynamic_reconfigure.srv import Reconfigure as ReconfigureSrv
47 from dynamic_reconfigure.msg import Config as ConfigMsg
48 from dynamic_reconfigure.msg import ConfigDescription as ConfigDescrMsg
49 from dynamic_reconfigure.msg import IntParameter, BoolParameter, StrParameter, DoubleParameter, ParamDescription
50 from dynamic_reconfigure.encoding import *
51
54 self.mutex = threading.Lock()
55 self.type = type
56 self.config = type.defaults
57 self.description = encode_description(type)
58 self._copy_from_parameter_server()
59 self.callback = callback
60 self._clamp(self.config)
61
62 self.descr_topic = rospy.Publisher('~parameter_descriptions', ConfigDescrMsg, latch=True)
63 self.descr_topic.publish(self.description);
64
65 self.update_topic = rospy.Publisher('~parameter_updates', ConfigMsg, latch=True)
66 self._change_config(self.config, type.all_level)
67
68 self.set_service = rospy.Service('~set_parameters', ReconfigureSrv, self._set_callback)
69
71 with self.mutex:
72 new_config = dict(self.config)
73 new_config.update(changes)
74 self._clamp(new_config)
75 return self._change_config(new_config, self._calc_level(new_config, self.config))
76
78 for param in self.type.config_description:
79 try:
80 self.config[param['name']] = rospy.get_param("~" + param['name'])
81 except KeyError:
82 pass
83
85 for param in self.type.config_description:
86 rospy.set_param('~' + param['name'], self.config[param['name']])
87
89 self.config = self.callback(config, level)
90 if self.config is None:
91 msg = 'Reconfigure callback should return a possibly updated configuration.'
92 rospy.logerr(msg)
93 raise DynamicReconfigureCallbackException(msg)
94
95 self._copy_to_parameter_server()
96
97 self.update_topic.publish(encode_config(self.config))
98
99 return self.config
100
102 level = 0
103 for param in self.type.config_description:
104 if config1[param['name']] != config2[param['name']]:
105 level |= param['level']
106
107 return level
108
110 for param in self.type.config_description:
111 maxval = self.type.max[param['name']]
112 minval = self.type.min[param['name']]
113 val = config[param['name']]
114 if val > maxval and maxval != "":
115 config[param['name']] = maxval
116 elif val < minval and minval != "":
117 config[param['name']] = minval
118
121