Here's an example of how to write a ROS service using Python that receives a pose message and returns a float feedback:
main.py600 chars21 linesExplanation:
The first line of the file simply tells the shell that this file should be interpreted with Python.
Next, we import the necessary packages. We need rospy to use the ROS Python API, Pose to represent the pose message, and SetBool and SetBoolResponse to create a service that returns a feedback value.
We define the feedback_service function, which takes a SetBool request as input and returns a SetBoolResponse. The request includes a Boolean value that we can set to True to indicate success and a feedback message that we'll set to the feedback value that we compute. For now, we simply return a fixed feedback value of 1.0.
We define the feedback_server function, which initializes the ROS node, creates a new service with the name /feedback_service, and tells the node to keep running until it receives a SIGINT signal.
Finally, we call feedback_server to start the service. When run, the service will be ready to receive initial SetBool requests with a True value and return the computed feedback message.
gistlibby LogSnag