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