Skip to content

Commit

Permalink
fix: working new question answer state machine
Browse files Browse the repository at this point in the history
  • Loading branch information
m-barker committed Mar 11, 2024
1 parent e41b4dd commit d7a9b22
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 14 deletions.
4 changes: 3 additions & 1 deletion skills/src/lasr_skills/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
from .look_to_point import LookToPoint
from .look_to_point import LookToPoint
from .go_to_location import GoToLocation
from .go_to_semantic_location import GoToSemanticLocation
from .go_to_semantic_location import GoToSemanticLocation
from .listen import Listen
from .say import Say
20 changes: 14 additions & 6 deletions skills/src/lasr_skills/ask_and_listen.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import smach
from listen import Listen
from skills.src.lasr_skills.say import Say
from lasr_skills import Listen
from lasr_skills import Say


class AskAndListen(smach.StateMachine):
Expand All @@ -15,12 +15,20 @@ def __init__(self):
smach.StateMachine.add(
"SAY",
Say(),
transitions={"succeeded": "LISTEN", "failed": "failed"},
remapping={"tts_phrase": "text"},
transitions={
"succeeded": "LISTEN",
"aborted": "failed",
"preempted": "failed",
},
remapping={"text": "tts_phrase"},
)
smach.StateMachine.add(
"LISTEN",
Listen(),
transitions={"succeeded": "succeeded", "failed": "failed"},
remapping={"transcribed_speech": "transcribed_speech"},
transitions={
"succeeded": "succeeded",
"aborted": "failed",
"preempted": "failed",
},
remapping={"sequence": "transcribed_speech"},
)
2 changes: 1 addition & 1 deletion skills/src/lasr_skills/xml_question_answer.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(self, index_path: str, txt_path: str, xml_path: str, k: int = 1):

def execute(self, userdata):
rospy.wait_for_service("/lasr_faiss/txt_query")
q_a_dict: dict = parse_question_xml(userdata.xml_path)
q_a_dict: dict = parse_question_xml(self.xml_path)
try:
request = TxtQueryRequest(
self.txt_path,
Expand Down
2 changes: 1 addition & 1 deletion tasks/gpsr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ include_directories(
## in contrast to setup.py, you can choose the destination
catkin_install_python(PROGRAMS
scripts/parse_gpsr_xmls.py
nodes/question_answer
nodes/commands/question_answer
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

Expand Down
2 changes: 1 addition & 1 deletion tasks/gpsr/launch/commands/question_answer.launch
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
type="transcribe_microphone_server"
name="transcribe_speech"
output="screen"
args="--mic_device 5"
args="--mic_device 9"
/>

</launch>
12 changes: 8 additions & 4 deletions tasks/gpsr/nodes/commands/question_answer
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class QuestionAnswerStateMachine(smach.StateMachine):
transitions={"succeeded": "XML_QUESTION_ANSWER", "failed": "failed"},
remapping={
"tts_phrase:": "tts_phrase",
"transcribed_speech": "query_sentence",
"transcribed_speech": "transcribed_speech",
},
)
smach.StateMachine.add(
Expand All @@ -33,16 +33,20 @@ class QuestionAnswerStateMachine(smach.StateMachine):
input_data["xml_path"],
input_data["k"],
),
transitions={"succeeded": "succeeded", "failed": "failed"},
transitions={"succeeded": "SAY_ANSWER", "failed": "failed"},
remapping={
"query_sentence": "query_sentence",
"query_sentence": "transcribed_speech",
"closest_answers": "closest_answers",
},
)
smach.StateMachine.add(
"SAY_ANSWER",
Say(format_str="The answer to your question is: {}"),
transitions={"succeeded": "succeeded", "failed": "failed"},
transitions={
"succeeded": "succeeded",
"aborted": "failed",
"preempted": "failed",
},
remapping={"placeholders": "closest_answers"},
)

Expand Down

0 comments on commit d7a9b22

Please sign in to comment.