Why is this simple service not returning anything ?
Hi,
I am new to ROS and have a little problem regarding services.
Right now I am sending a request to the server, triggering the handle_speech function.
In this function I subscribe to the pocketsphinx recognizer/output node.
When I return an integer value from here, the client receives it and shows it to me.
But when I return a value from the speechCB callback function, the client shows nothing.
What am I doing wrong here?
Edit: Now it is working, but this code is not my best coding ;)
#!/usr/bin/env python
import roslib; roslib.load_manifest('kmr01')
from kmr01.srv import *
import rospy
from std_msgs.msg import String
command = 0
def handle_speech(req):
print "handling speech input"
rospy.Subscriber('recognizer/output', String, speechCb)
r = rospy.Rate(10.0)
while not rospy.is_shutdown():
r.sleep()
print "sleeping"
if command != 0:
return RecognizeSpeechResponse(command)
def speechCb(msg):
global command
print "speechCB"
if msg.data.find("forward") > -1:
command = 2
elif msg.data.find("stop") > -1 or msg.data.find("halt") > -1:
command = 1
print "nothing recognized"
command = 99
def recognize_speech_server():
rospy.init_node('recognize_speech_server')
s = rospy.Service('recognize_speech', RecognizeSpeech, handle_speech)
print "Ears wide open ..."
rospy.spin()
if __name__ == "__main__":
recognize_speech_server()
Regards Max