ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

Even if your service definition has no fields in the request portion, a request class is still created and your server callback must still adhere to the function signature required of the callback. The signature is described in the API docs. The function should take a request and return a response.

So your code could be roughly updated as:

from pytorch_ros.srv import Classification
from pytorch_ros.srv import ClassificationRequest
from pytorch_ros.srv import ClassificationResponse

class PytorchNode(object):
    def __init__(self):
        classification_service = rospy.Service('classify',
                                               Classification,
                                               self.classify_handle)

    def classify_container_handle(self, request):
        # do some stuff
        # to get the classification
        # .....

        # construct msg and return
        classification_response = ClassificationResponse()
        classification_response.class_name = self.names[classification]
        classification_response.confidence = confidence

        return classification_response

Even if your service definition has no fields in the request portion, a request class is still created and your server callback must still adhere to the function signature required of the callback. The signature is described in the API docs. The function should take a request and return a response.

So your code could be roughly updated as:

from pytorch_ros.srv import Classification
from pytorch_ros.srv import ClassificationRequest
from pytorch_ros.srv import ClassificationResponse

class PytorchNode(object):
    def __init__(self):
        classification_service = rospy.Service('classify',
                                               Classification,
                                               self.classify_handle)

    def classify_container_handle(self, request):
        # do some stuff
        # to get the classification
        # .....

        # construct msg and return
        classification_response = ClassificationResponse()
        classification_response.class_name = self.names[classification]
        classification_response.confidence = confidence

        return classification_response

Note: This is very much what is presented in the Writing a Simple Service and Client (Python) tutorial.

Even if your service definition has no fields in the request portion, a request class is still created and your server callback must still adhere to the function signature required of the callback. The signature is described in the API docs. The function should take a request and return a response.

So your code could be roughly updated as:

from pytorch_ros.srv import Classification
from pytorch_ros.srv import ClassificationRequest
from pytorch_ros.srv import ClassificationResponse

class PytorchNode(object):
    def __init__(self):
        classification_service = rospy.Service('classify',
                                               Classification,
                                               self.classify_handle)

    def classify_container_handle(self, classify_handle(self, request):
        # do some stuff
        # to get the classification
        # .....

        # construct msg and return
        classification_response = ClassificationResponse()
        classification_response.class_name = self.names[classification]
        classification_response.confidence = confidence

        return classification_response

Note: This is very much what is presented in the Writing a Simple Service and Client (Python) tutorial.