Skip to content

Commit

Permalink
Merge pull request #11 from HLP-R/multiple_speech_calls
Browse files Browse the repository at this point in the history
adding functionality to allow for multiple service calls. This preven…
  • Loading branch information
vchu committed Nov 8, 2016
2 parents 5f44670 + 3e5780f commit 08555ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions hlpr_speech_recognition/config/speech.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ speech:
command_type: 'StampedString' # default StampedString (string vs. stampedstring)
rec_threshold: 300 # default 300
service_topic: 'get_last_speech_cmd' # default 'get_last_speech_cmd'
leave_command: false # default false

Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class SpeechListener:
SERVICE_TOPIC_PARAM = "/speech/service_topic"
KEYWORDS_PARAM = "/speech/keywords"
COMMAND_TYPE = "/speech/command_type"
LEAVE_COMMAND = "/speech/leave_command"

def __init__(self, commandBuffSize=10, init_node=True):

Expand All @@ -75,6 +76,7 @@ def __init__(self, commandBuffSize=10, init_node=True):
self.yaml_files = rospy.get_param("~yaml_list", default_yaml_files)
self.service_topic = rospy.get_param(SpeechListener.SERVICE_TOPIC_PARAM, default_service_topic)
self.msg_type = eval(rospy.get_param(SpeechListener.COMMAND_TYPE, 'StampedString')) # True if message is only str, false includes header
self.leave_command_flag = rospy.get_param(SpeechListener.LEAVE_COMMAND, False) #do we care if we the last command is old

rospy.Subscriber(self.recog_topic, self.msg_type, self.callback)

Expand All @@ -93,6 +95,7 @@ def __init__(self, commandBuffSize=10, init_node=True):
# Flags for starting/stopping the node
self.spinning = False
self.last_command_fresh = False
self.last_command = None
self.last_ts = None
self.last_string = None

Expand Down Expand Up @@ -123,9 +126,13 @@ def _map_keyword_to_command(self, data):

# This is now made a service call
def get_last_command(self, req=None):
# returns a service request error
if not self.last_command_fresh:
return None

# Check if we care how "recent" the command was
if not self.leave_command_flag:

# returns a service request error
if not self.last_command_fresh:
return None

# The command hasn't been ask for before
self.last_command_fresh = False
Expand Down

0 comments on commit 08555ae

Please sign in to comment.