ddynamic_reconfigure.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 """
00004 Dynamic dynamic reconfigure server.
00005 
00006 Just register your variables for the dynamic reconfigure
00007 and call start with a callback.
00008 
00009 Author: Sammy Pfeiffer
00010 """
00011 
00012 from dynamic_reconfigure.server import Server
00013 from dynamic_reconfigure.parameter_generator_catkin import ParameterGenerator
00014 from dynamic_reconfigure.encoding import extract_params
00015 from rospkg import RosPack
00016 import rospy
00017 
00018 
00019 class DDynamicReconfigure(ParameterGenerator):
00020     """Dynamic reconfigure server that can be instanced directly."""
00021 
00022     def __init__(self, name=None):
00023         global id
00024         self.group = self.Group(self, "Default", "", True, 0, 0)
00025         id = 1
00026         if name is None:
00027             self.name = rospy.get_name() + "_dyn_rec"
00028         else:
00029             self.name = name
00030         self.constants = []
00031         rp = RosPack()
00032         self.dynconfpath = rp.get_path('dynamic_reconfigure')
00033 
00034     def get_type(self):
00035         class TypeClass(object):
00036             def __init__(self, config_description):
00037                 self.config_description = config_description
00038                 self.min = {}
00039                 self.max = {}
00040                 self.defaults = {}
00041                 self.level = {}
00042                 self.type = {}
00043                 self.all_level = 0
00044 
00045                 for param in extract_params(config_description):
00046                     self.min[param['name']] = param['min']
00047                     self.max[param['name']] = param['max']
00048                     self.defaults[param['name']] = param['default']
00049                     self.level[param['name']] = param['level']
00050                     self.type[param['name']] = param['type']
00051                     self.all_level = self.all_level | param['level']
00052         return TypeClass(self.group.to_dict())
00053 
00054     def add_variable(self, name, description, default=None, min=None, max=None, edit_method=""):
00055         """Register variable, like gen.add() but deducting the type"""
00056         if type(default) == int:
00057             if edit_method == "":
00058                 self.add(name, "int", 0, description, default, min, max)
00059             else: # enum
00060                 self.add(name, "int", 0, description, default, min, max, edit_method)
00061         elif type(default) == float:
00062             self.add(name, "double", 0, description, default, min, max)
00063         elif type(default) == str:
00064             self.add(name, "str", 0, description, default)
00065         elif type(default) == bool:
00066             self.add(name, "bool", 0, description, default)
00067 
00068         return default
00069 
00070 
00071     def get_variable_names(self):
00072         """Return the names of the dynamic reconfigure variables"""
00073         names = []
00074         for param in self.group.parameters:
00075             names.append(param['name'])
00076         return names
00077 
00078 
00079     def start(self, callback):
00080         self.dyn_rec_srv = Server(self.get_type(), callback, namespace=self.name)


ddynamic_reconfigure_python
Author(s):
autogenerated on Thu Sep 22 2016 03:18:57