Go to the documentation of this file.00001
00002
00003 """
00004 Dynamic dynamic reconfigure server example with a class.
00005
00006 Author: Sammy Pfeiffer
00007 """
00008
00009 import rospy
00010 from ddynamic_reconfigure_python.ddynamic_reconfigure import DDynamicReconfigure
00011
00012 class Example(object):
00013 def __init__(self):
00014
00015 self.ddr = DDynamicReconfigure("class_example")
00016
00017
00018 self.ddr.add_variable("decimal", "float/double variable", 0.0, -1.0, 1.0)
00019 self.ddr.add_variable("integer", "integer variable", 0, -1, 1)
00020 self.ddr.add_variable("bool", "bool variable", True)
00021 self.ddr.add_variable("string", "string variable", "string dynamic variable")
00022 enum_method = self.ddr.enum([ self.ddr.const("Small", "int", 0, "A small constant"),
00023 self.ddr.const("Medium", "int", 1, "A medium constant"),
00024 self.ddr.const("Large", "int", 2, "A large constant"),
00025 self.ddr.const("ExtraLarge", "int", 3, "An extra large constant")],
00026 "An enum example")
00027 self.ddr.add_variable("enumerate", "enumerate variable", 1, 0, 3, edit_method=enum_method)
00028
00029 self.add_variables_to_self()
00030
00031 self.ddr.start(self.dyn_rec_callback)
00032
00033 def add_variables_to_self(self):
00034 var_names = self.ddr.get_variable_names()
00035 for var_name in var_names:
00036 self.__setattr__(var_name, None)
00037
00038 def dyn_rec_callback(self, config, level):
00039 rospy.loginfo("Received reconf call: " + str(config))
00040
00041 var_names = self.ddr.get_variable_names()
00042 for var_name in var_names:
00043 self.__dict__[var_name] = config[var_name]
00044 return config
00045
00046 if __name__ == '__main__':
00047 rospy.init_node('test_ddynrec')
00048
00049
00050 E = Example()
00051
00052 rospy.spin()