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

Revision history [back]

click to hide/show revision 1
initial version

The request and response parts of a service request are both allowed to be empty. For example, std_srvs/Empty is an officially supported type: http://docs.ros.org/melodic/api/std_srvs/html/srv/Empty.html

As a note, the handler for rospy.Service must always return the service's result type, even if it is empty. The rospy.Service docs explicitly state that returning None from the service handler is considered a failure of the service call:

handler (fn(req)->resp) - callback function for processing service request. Function takes in a ServiceRequest and returns a ServiceResponse of the appropriate type. Function may also return a list, tuple, or dictionary with arguments to initialize a ServiceResponse instance of the correct type. If handler cannot process request, it may either return None, to indicate failure, or it may raise a rospy.ServiceException to send a specific error message to the client. Returning None is always considered a failure.