Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 import rospy
00036
00037 class ROSParams(object):
00038 """
00039 Helper class to be used for grabbing parameters off the parameter server at startup.
00040
00041 Example usage:
00042
00043 from starmac_roslib.ros_params import ROSParams
00044
00045 class MyNodeParams(ROSParams):
00046 param_defaults = {'param_one': 2.3, 'param_two': 0.0}
00047
00048 class MyNode:
00049 ...
00050 def init_params(self):
00051 self.params = MyNodeParams()
00052
00053 def some_method(self):
00054 foo = self.params.param_one * 42
00055 """
00056 param_defaults = {}
00057
00058 def __init__(self, get_params=True, quiet=False):
00059 if get_params:
00060 self.get_params(quiet=quiet)
00061
00062 def get_params(self,quiet=False):
00063 """
00064 Loads parameter values from the parameter server, using defaults from self.param_defaults
00065 Unless the quiet parameter is set, an info message is printed giving the parameter name,
00066 the set value of the parameter, its type and default value.
00067 """
00068 for param_name, default_value in self.param_defaults.items():
00069 value = rospy.get_param("~" + param_name, default_value)
00070 self.__setattr__(param_name,value)
00071 if not quiet:
00072 rospy.loginfo('Parameter %s = %s (%s) (default %s)' %
00073 (param_name,
00074 str(value),
00075 str(type(value)),
00076 str(self.param_defaults[param_name])
00077 ))
00078