Question about callback function

how to read message from subscriber in service callback function?

in section “Unit 5 Services in ROS: Clients” has a example call service from client
Python Program: simple_service_client.py

#! /usr/bin/env python

import rospy
# Import the service message used by the service /trajectory_by_name
from trajectory_by_name_srv.srv import TrajByName, TrajByNameRequest
import sys

# Initialise a ROS node with the name service_client
rospy.init_node('service_client')
# Wait for the service client /trajectory_by_name to be running
rospy.wait_for_service('/trajectory_by_name')
# Create the connection to the service
traj_by_name_service = rospy.ServiceProxy('/trajectory_by_name', TrajByName)
# Create an object of type TrajByNameRequest
traj_by_name_object = TrajByNameRequest()
# Fill the variable traj_name of this object with the desired value
traj_by_name_object.traj_name = "release_food"
# Send through the connection the name of the trajectory to be executed by the robot
result = traj_by_name_service(traj_by_name_object)
# Print the result given by the service called
print(result)

At final line: print(result), this is print respond message from server. If you know structure of respond message, you can analysis and reuse for many purpose
Please see example 5.6 : How to know the structure of the service message used by the service? to look up structure of message
please respond if i mistake your mean

Thanks for answer, but this answer is not what I want What I mean is that there’s a problem when using two kind callback function in one python file. If so how to read subscriber message in service callback function?

Please provide more context so we can help you.

  • What unit are you on?
  • What exercise are you trying to solve?

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.