more stable implementation of speech stuff

This commit is contained in:
Pavel Lutskov
2019-02-02 13:38:35 +01:00
parent 3217b7f841
commit 655c5418fd
7 changed files with 77 additions and 279 deletions

View File

@@ -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()