Get service message data
I have a service node server that handles a simple request by a client. The client sends an id (as a string), which the server then should read out. I am using rospy.
If I print the message in the server, it says "request: 1". I want to only extract the "1". How do I do that?
Rephrasing a bit: what "member" of the message do I have to call to get the raw data? Something like message.data
.
Here's the handler:
def handle_cac(request):
# receive goal id, return goal information
print("Received this message: ")
print request.data # this does not work! I'd like to just get the raw id, e.g. "1"
for goals in root.getchildren():
for goal in goals.getchildren():
print goal.tag
print goal.attrib
if goal.attrib.text == request.data:
print "Found goal: " + goal.name
# print((root.findall("goals"))[0][0].attribute)
return "nothing"
And here's the client:
def cac_client(request_message):
print "Running request"
rospy.wait_for_service('CAC')
try:
GetGoal = rospy.ServiceProxy('CAC', cac)
resp1 = GetGoal(request_message)
print resp1
return resp1
except rospy.ServiceException, e:
print "Service call failed: %s" %e
if __name__ == "__main__":
cac_client("1")
what type of service are you using? What are you writing in your client? Could it be that you are actually writing
request: 1
in it?I added the client's code to the question.
What service type is that? I see
cac
, but I don't know what this is supposed to be. You can actually have a look at thecac
definition yourself. This is the data member...E.g. the
AddTwoInts.srv
of thebeginner_tutorials
has the membersa
andb
.Sorry, I was not sure what you meant. This is what it looks like:
string request \--- string response
. Ignore the\
, didn't know how to escape the-
in this comment. Also, the type seems to be "cacRequest", which is normal for services, right?yes, basically from the srv definition you posted, two "messages" are created, which are called cacRequest and cacResponse, in this case...
How do I access the raw string I sent via these messages?
some patience, man ;-D