more stable implementation of speech stuff
This commit is contained in:
@@ -13,9 +13,15 @@ from controller import inform_controller_factory
|
||||
in_progress = False
|
||||
state = 'idle'
|
||||
|
||||
IMITATE = 'repeat'
|
||||
KILL = 'kill'
|
||||
REVIVE = 'go'
|
||||
STOP = 'stop'
|
||||
|
||||
voc_state = {
|
||||
'idle': 'start',
|
||||
'imitate': 'stop'
|
||||
'idle': [IMITATE, KILL],
|
||||
'imitate': [STOP, KILL],
|
||||
'killed': [REVIVE]
|
||||
}
|
||||
|
||||
_inform_controller = inform_controller_factory('speech')
|
||||
@@ -23,10 +29,17 @@ _inform_controller = inform_controller_factory('speech')
|
||||
|
||||
def done_cb(_, result):
|
||||
global in_progress, state
|
||||
rospy.loginfo(result)
|
||||
if result.word == 'start' and _inform_controller('imitate'):
|
||||
rospy.loginfo('SPEECH CLIENT: {}'.format(result))
|
||||
if result is None:
|
||||
in_progress = False
|
||||
return
|
||||
if result.word == IMITATE and _inform_controller('imitate'):
|
||||
state = 'imitate'
|
||||
elif result.word == 'stop' and _inform_controller('stop'):
|
||||
elif result.word == STOP and _inform_controller('stop'):
|
||||
state = 'idle'
|
||||
elif result.word == KILL and _inform_controller('kill'):
|
||||
state = 'killed'
|
||||
elif result.word == REVIVE and _inform_controller('revive'):
|
||||
state = 'idle'
|
||||
in_progress = False
|
||||
|
||||
@@ -46,11 +59,10 @@ if __name__ == '__main__':
|
||||
client.cancel_goal()
|
||||
in_progress = False
|
||||
state = 'idle'
|
||||
continue
|
||||
|
||||
if not in_progress:
|
||||
in_progress = True
|
||||
client.send_goal(RequestSpeechGoal([voc_state[state]]),
|
||||
done_cb)
|
||||
rospy.Rate(2).sleep()
|
||||
|
||||
else:
|
||||
if not in_progress:
|
||||
in_progress = True
|
||||
client.send_goal(RequestSpeechGoal(voc_state[state]),
|
||||
done_cb)
|
||||
rospy.Rate(4).sleep()
|
||||
|
||||
Reference in New Issue
Block a user