Skip to content

Commit 6f822bf

Browse files
committed
feat: working command parser sm
1 parent 8740673 commit 6f822bf

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed

tasks/gpsr/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ include_directories(
155155
## in contrast to setup.py, you can choose the destination
156156
catkin_install_python(PROGRAMS
157157
scripts/parse_gpsr_xmls.py
158+
scripts/main.py
158159
nodes/commands/question_answer
159160
nodes/command_parser
160161
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}

tasks/gpsr/scripts/main.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python3
2+
import smach
3+
import rospy
4+
import sys
5+
from typing import Dict
6+
from gpsr.load_known_data import GPSRDataLoader
7+
from gpsr.regex_command_parser import Configuration
8+
from gpsr.states import CommandParserStateMachine
9+
10+
11+
def load_gpsr_configuration() -> Configuration:
12+
gpsr_data_dir = sys.argv[1]
13+
"""Loads the configuration for the GPSR command parser"""
14+
data_loader = GPSRDataLoader(data_dir=gpsr_data_dir)
15+
gpsr_known_data: Dict = data_loader.load_data()
16+
config = Configuration(
17+
{
18+
"person_names": gpsr_known_data["names"],
19+
"location_names": gpsr_known_data["non_placeable_locations"],
20+
"placement_location_names": gpsr_known_data["placeable_locations"],
21+
"room_names": gpsr_known_data["rooms"],
22+
"object_names": gpsr_known_data["objects"],
23+
"object_categories_plural": gpsr_known_data["categories_plural"],
24+
"object_categories_singular": gpsr_known_data["categories_singular"],
25+
}
26+
)
27+
return config
28+
29+
30+
def main():
31+
config = load_gpsr_configuration()
32+
command_parser_sm = CommandParserStateMachine(data_config=config)
33+
command_parser_sm.execute()
34+
parsed_command: Dict = command_parser_sm.userdata.parsed_command
35+
rospy.loginfo(f"Parsed command: {parsed_command}")
36+
37+
38+
if __name__ == "__main__":
39+
rospy.init_node("gpsr_main")
40+
main()
41+
rospy.spin()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from .talk import Talk
2-
from .command_parser import ParseCommand, CommandParserStateMachine
32
from .command_similarity_matcher import CommandSimilarityMatcher
3+
from .command_parser import ParseCommand, CommandParserStateMachine

tasks/gpsr/src/gpsr/states/command_parser.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
#!/usr/bin/env python3
2-
import argparse
32
import smach
43
import rospy
54

6-
from gpsr.load_known_data import GPSRDataLoader
75
from gpsr.regex_command_parser import Configuration, gpsr_compile_and_parse
86
from gpsr.states import CommandSimilarityMatcher
9-
from lasr_skills import AskAndListen, Say
7+
from lasr_skills import AskAndListen
108

119

1210
class ParseCommand(smach.State):
@@ -29,7 +27,7 @@ def execute(self, userdata):
2927
rospy.loginfo(f"Received command : {userdata.raw_command.lower()}")
3028
try:
3129
userdata.parsed_command = gpsr_compile_and_parse(
32-
self.data_config, userdata.transcribed_speech.lower()
30+
self.data_config, userdata.raw_command.lower()
3331
)
3432
except Exception as e:
3533
rospy.logerr(e)
@@ -58,7 +56,7 @@ def __init__(
5856
with self:
5957
smach.StateMachine.add(
6058
"ASK_FOR_COMMAND",
61-
AskAndListen(),
59+
AskAndListen(tts_phrase="Hello, please tell me your command."),
6260
transitions={"succeeded": "PARSE_COMMAND", "failed": "failed"},
6361
remapping={"transcribed_speech": "raw_command"},
6462
)
@@ -78,7 +76,7 @@ def __init__(
7876
CommandSimilarityMatcher([n_vecs_per_txt_file] * total_txt_files),
7977
transitions={"succeeded": "PARSE_COMMAND", "failed": "failed"},
8078
remapping={
81-
"command": "parsed_command",
82-
"matched_command": "matched_command",
79+
"command": "raw_command",
80+
"matched_command": "raw_command",
8381
},
8482
)

0 commit comments

Comments
 (0)