def __init__(self, name): """ :param name: The name of the node """ rospy.loginfo("Starting %s" % name) self._hmm_lib = ProbRepLib() self._hmm_lib.print_hmms_available() self.services = {} # Automatically creating a service for all the entries in 'qsrrep_lib.rep_io.available_services' # Passing the key of the dict entry to the service to identify the right function to call for i, k in enumerate(available_services.keys()): # The outer lambda function creates a new scope for the inner lambda function # This is necessary to preserve the value of k, otherwise it will have the same value for all services # x will be substituded by the service request self.services[k] = rospy.Service( "~" + k, QSRProbRep, (lambda b: lambda x: self.callback(x, b))(k))
def __init__(self, name): """ :param name: The name of the node """ rospy.loginfo("Starting %s" % name) self._lib = ProbRepLib() self.services = {} for namespace, services in ServiceManager.available_services.items(): # Automatically creating a service for all the entries in 'qsrrep_lib.rep_io.available_services' # Passing the key of the dict entry to the service to identify the right function to call for i, service in enumerate(services): # The outer lambda function creates a new scope for the inner lambda function # This is necessary to preserve the value of k, otherwise it will have the same value for all services # x will be substituded by the service request self.services[service] = rospy.Service( "~" + namespace + "/" + service, QSRProbRep, (lambda a, b: lambda x: self.callback(x, a, b))(namespace, service))