示例#1
0
def call_service(node_handle, service, args=None):
    # Given the service name, fetch the type and class of the service,
    # and a request instance

    # This should be equivalent to rospy.resolve_name.
    service = expand_topic_name(service, node_handle.get_name(),
                                node_handle.get_namespace())

    service_names_and_types = dict(node_handle.get_service_names_and_types())
    service_type = service_names_and_types.get(service)
    if service_type is None:
        raise InvalidServiceException(service)
    # service_type is a tuple of types at this point; only one type is supported.
    if len(service_type) > 1:
        node_handle.get_logger().warning(
            'More than one service type detected: {}'.format(service_type))
    service_type = service_type[0]

    service_class = get_service_class(service_type)
    inst = get_service_request_instance(service_type)

    # Populate the instance with the provided args
    args_to_service_request_instance(service, inst, args)

    client = node_handle.create_client(service_class, service)

    future = client.call_async(inst)
    spin_until_future_complete(node_handle, future)
    if future.result() is not None:
        # Turn the response into JSON and pass to the callback
        json_response = extract_values(future.result())
    else:
        raise Exception(future.exception())

    return json_response
示例#2
0
def get_service_request_typedef_recursive(servicetype):
    """ Returns a list of typedef dicts for this type and all contained type fields """
    # Get an instance of the service request class and get its typedef
    instance = ros_loader.get_service_request_instance(servicetype)
    typedef = _get_typedef(instance)

    # Return the list of sub-typedefs
    return _get_subtypedefs_recursive(typedef, [])
def get_service_request_typedef_recursive(servicetype):
    """ Returns a list of typedef dicts for this type and all contained type fields """
    # Get an instance of the service request class and get its typedef
    instance = ros_loader.get_service_request_instance(servicetype)
    typedef = _get_typedef(instance)
    
    # Return the list of sub-typedefs
    return _get_subtypedefs_recursive(typedef, [])
 def test_irregular_servicenames(self):
     irregular = ["roscpp//GetLoggers", "/roscpp/GetLoggers/",
     "/roscpp/GetLoggers", "//roscpp/GetLoggers", "/roscpp//GetLoggers",
     "roscpp/GetLoggers//", "/roscpp/GetLoggers//", "roscpp/GetLoggers/",
     "roscpp//GetLoggers//"]
     for x in irregular:
         self.assertNotEqual(ros_loader.get_service_class(x), None)
         self.assertNotEqual(ros_loader.get_service_instance(x), None)
         self.assertNotEqual(ros_loader.get_service_request_instance(x), None)
         self.assertNotEqual(ros_loader.get_service_response_instance(x), None)
示例#5
0
 def test_irregular_servicenames(self):
     irregular = ["roscpp//GetLoggers", "/roscpp/GetLoggers/",
                  "/roscpp/GetLoggers", "//roscpp/GetLoggers", "/roscpp//GetLoggers",
                  "roscpp/GetLoggers//", "/roscpp/GetLoggers//", "roscpp/GetLoggers/",
                  "roscpp//GetLoggers//"]
     for x in irregular:
         self.assertNotEqual(ros_loader.get_service_class(x), None)
         self.assertNotEqual(ros_loader.get_service_instance(x), None)
         self.assertNotEqual(
             ros_loader.get_service_request_instance(x), None)
         self.assertNotEqual(
             ros_loader.get_service_response_instance(x), None)
 def test_srv_cache(self):
     common = ["roscpp/GetLoggers", "roscpp/SetLoggerLevel",
     "std_srvs/Empty", "nav_msgs/GetMap", "nav_msgs/GetPlan",
     "sensor_msgs/SetCameraInfo", "topic_tools/MuxAdd",
     "topic_tools/MuxSelect", "tf2_msgs/FrameGraph",
     "rospy_tutorials/BadTwoInts", "rospy_tutorials/AddTwoInts"]
     for x in common:
         self.assertNotEqual(ros_loader.get_service_class(x), None)
         self.assertNotEqual(ros_loader.get_service_instance(x), None)
         self.assertNotEqual(ros_loader.get_service_request_instance(x), None)
         self.assertNotEqual(ros_loader.get_service_response_instance(x), None)
         self.assertTrue(x in ros_loader._loaded_srvs)
示例#7
0
 def test_srv_cache(self):
     common = ["roscpp/GetLoggers", "roscpp/SetLoggerLevel",
               "std_srvs/Empty", "nav_msgs/GetMap", "nav_msgs/GetPlan",
               "sensor_msgs/SetCameraInfo", "topic_tools/MuxAdd",
               "topic_tools/MuxSelect", "tf2_msgs/FrameGraph",
               "rospy_tutorials/BadTwoInts", "rospy_tutorials/AddTwoInts"]
     for x in common:
         self.assertNotEqual(ros_loader.get_service_class(x), None)
         self.assertNotEqual(ros_loader.get_service_instance(x), None)
         self.assertNotEqual(
             ros_loader.get_service_request_instance(x), None)
         self.assertNotEqual(
             ros_loader.get_service_response_instance(x), None)
         self.assertTrue(x in ros_loader._loaded_srvs)
示例#8
0
def call_service(service, args=None):
    # Given the service name, fetch the type and class of the service,
    # and a request instance
    service_type = get_service_type(str(service))
    if service_type is None:
        raise InvalidServiceException(service)
    service_class = get_service_class(service_type)
    inst = get_service_request_instance(service_type)

    # Populate the instance with the provided args
    args_to_service_request_instance(service, inst, args)

    # Call the service
    proxy = ServiceProxy(service, service_class)
    response = proxy.call(inst)

    # Turn the response into JSON and pass to the callback
    json_response = extract_values(response)

    return json_response
示例#9
0
def call_service(service, args=None):
    # Given the service name, fetch the type and class of the service,
    # and a request instance
    service_type = get_service_type(str(service))
    if service_type is None:
        raise InvalidServiceException(service)
    service_class = get_service_class(service_type)
    inst = get_service_request_instance(service_type)

    # Populate the instance with the provided args
    args_to_service_request_instance(service, inst, args)

    # Call the service
    proxy = ServiceProxy(service, service_class)
    response = proxy.call(inst)

    # Turn the response into JSON and pass to the callback
    json_response = extract_values(response)

    return json_response
示例#10
0
def get_service_request_typedef(servicetype):
    """ Returns a typedef dict for the service request class for the specified service type """
    # Get an instance of the service request class and return its typedef
    instance = ros_loader.get_service_request_instance(servicetype)
    return _get_typedef(instance)
def get_service_request_typedef(servicetype):
    """ Returns a typedef dict for the service request class for the specified service type """
    # Get an instance of the service request class and return its typedef
    instance = ros_loader.get_service_request_instance(servicetype)
    return _get_typedef(instance)