robocup_knowledge
rgo2017/challenge_gpsr.py
Go to the documentation of this file.
1 from __future__ import print_function
2 
3 from robocup_knowledge import knowledge_loader
4 common = knowledge_loader.load_knowledge("common")
5 
6 not_understood_sentences = [
7  "I'm so sorry! Can you please speak louder and slower? And wait for the ping!",
8  "I am deeply sorry. Please try again, but wait for the ping!",
9  "You and I have communication issues. Speak up!",
10  "All this noise is messing with my audio. Try again"
11  ]
12 
13 initial_pose = ["initial_pose",
14  "initial_pose_2"] # initial pose
15 starting_pose = ["gpsr_meeting_point_1",
16  "gpsr_meeting_point_2"] # Designated pose to wait for commands
17 exit_waypoint = ["gpsr_exit_door_1",
18  "gpsr_exit_door_2"] # Door through which to exit the arena
19 
20 
21 grammar_target = "T"
22 
23 
28 
29 grammar = """
30 T[{actions : <A1>}] -> C[A1]
31 T[{actions : <A1, A2>}] -> C[A1] and C[A2]
32 T[{actions : <A1, A2, A3>}] -> C[A1] C[A2] and C[A3]
33 
34 C[{A}] -> VP[A]
35 """
36 
37 
42 
43 grammar += """
44 V_GUIDE -> guide | escort | take | lead | accompany
45 
46 DET -> the | a | an | some
47 MANIPULATION_AREA_DESCRIPTIONS -> on top of | at | in | on
48 """
49 
50 for room in common.location_rooms:
51  grammar += '\nROOMS[%s] -> %s' % (room, room)
52 for loc in common.get_locations():
53  grammar += '\nLOCATIONS[%s] -> %s' % (loc, loc)
54 grammar += '\n ROOMS_AND_LOCATIONS[X] -> ROOMS[X] | LOCATIONS[X]'
55 for obj in common.object_names:
56  grammar += '\nOBJECT_NAMES[%s] -> %s' % (obj, obj)
57 for loc in common.get_locations(pick_location=True, place_location=True):
58  grammar += '\nMANIPULATION_AREA_LOCATIONS[%s] -> MANIPULATION_AREA_DESCRIPTIONS the %s' % (loc, loc)
59 for cat in common.object_categories:
60  grammar += '\nOBJECT_NAMES[%s] -> %s' % (cat, cat)
61 
62 
67 
68 grammar += """
69 V_FIND -> find | locate | look for | meet
70 
71 VP["action": "find", "object": {"type": X}, "location": {"id": Y}] -> V_FIND DET OBJECT_NAMES[X] in the ROOMS[Y]
72 VP["action": "find", "object": {"type": "person"}, "location": {"id": Y}] -> V_FIND FIND_PERSONS in the ROOMS[Y]
73 VP["action": "find", "object": {"type": "person"}, "location": {"id": Y}] -> V_FIND FIND_PERSONS near the LOCATIONS[Y]
74 VP["action": "find", "object": {"type": X}, "location": {"id": Y}] -> V_FIND DET OBJECT_NAMES[X] MANIPULATION_AREA_LOCATIONS[Y]
75 """
76 
77 grammar += '\nFIND_PERSONS -> DET person'
78 grammar += '\nFIND_PERSONS -> DET women'
79 grammar += '\nFIND_PERSONS -> DET man'
80 for name in common.names:
81  grammar += '\nFIND_PERSONS -> %s' % name
82 
83 
88 
89 grammar += """
90 V_GOPL -> go to | navigate to
91 V_GOR -> V_GOPL | enter
92 
93 VP["action": "navigate-to", "object": {"id": X}] -> V_GOR the ROOMS[X]
94 VP["action": "navigate-to", "object": {"id": X}] -> V_GOPL the LOCATIONS[X]
95 """
96 
97 
102 
103 grammar += """
104 V_PICKUP -> get | grasp | take | pick up
105 
106 VP["action": "find", "object": {"type": X}, "location": {"id": Y}] -> V_PICKUP DET OBJECT_NAMES[X] MANIPULATION_AREA_LOCATIONS[Y]
107 """
108 
109 
114 
115 grammar += """
116 V_PLACE -> put | place
117 
118 VP["action": "place", "object": {"type": X}, "location": {"id": Y}] -> V_PLACE DET OBJECT_NAMES[X] MANIPULATION_AREA_LOCATIONS[Y]
119 """
120 
121 
126 
127 grammar += """
128 V_FOLLOW -> follow | go after | come after | V_GUIDE
129 
130 VP["action": "follow", "location-from": {"id": X}, "location-to": {"id": Y}, "target": {"id": "operator"}] -> V_FOLLOW me from the ROOMS_AND_LOCATIONS[X] to the ROOMS_AND_LOCATIONS[Y]
131 VP["action": "follow", "location-to": {"id": X}, "location-from": {"id": Y}, "target": {"id": "operator"}] -> V_FOLLOW me to the ROOMS_AND_LOCATIONS[X] from the ROOMS_AND_LOCATIONS[Y]
132 
133 VP["action": "follow", "location-to": {"id": X}, "target": {"id": "operator"}] -> V_FOLLOW me to the ROOMS_AND_LOCATIONS[X]
134 VP["action": "follow", "target": {"id": "operator"}] -> V_FOLLOW me
135 
136 VP["action": "follow", "location-from": {"id": X}, "location-to": {"id": Y}, "target": {"id": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z] from the ROOMS_AND_LOCATIONS[X] to the ROOMS_AND_LOCATIONS[Y]
137 VP["action": "follow", "location-to": {"id": X}, "location-from": {"id": Y}, "target": {"id": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z] to the ROOMS_AND_LOCATIONS[X] from the ROOMS_AND_LOCATIONS[Y]
138 
139 VP["action": "follow", "location-from": {"id": X}, "target": {"id": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z] from the ROOMS_AND_LOCATIONS[X]
140 VP["action": "follow", "location-to": {"id": X}, "target": {"id": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z] to the ROOMS_AND_LOCATIONS[X]
141 
142 VP["action": "follow", "target": {"id": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z]
143 """
144 
145 grammar += '\nFOLLOW_PERSONS[the person] -> DET person'
146 grammar += '\nFOLLOW_PERSONS[the woman] -> DET woman'
147 grammar += '\nFOLLOW_PERSONS[the man] -> DET man'
148 for name in common.names:
149  grammar += '\nFOLLOW_PERSONS[%s] -> %s' % (name, name)
150 
151 
156 
157 grammar += """
158 V_BRING -> bring | deliver | take | carry | transport
159 V_BRING_PERSON -> V_BRING | give | hand | hand over
160 
161 VP["action": "bring", "source-location": {"id": X}, "target-location": {"id": Y}, "object": {"type": Z}] -> V_BRING DET OBJECT_NAMES[Z] from the ROOMS_AND_LOCATIONS[X] to the ROOMS_AND_LOCATIONS[Y] | V_BRING OBJECT_NAMES[Z] from the ROOMS_AND_LOCATIONS[X] to the ROOMS_AND_LOCATIONS[Y]
162 VP["action": "bring", "target-location": {"id": X}, "source-location": {"id": Y}, "object": {"type": Z}] -> V_BRING DET OBJECT_NAMES[Z] to the ROOMS_AND_LOCATIONS[X] from the ROOMS_AND_LOCATIONS[Y] | V_BRING OBJECT_NAMES[Z] to the ROOMS_AND_LOCATIONS[X] from the ROOMS_AND_LOCATIONS[Y]
163 
164 VP["action": "bring", "source-location": {"id": X}, "target-location": {"type": "person"}, "object": {"type": Z}] -> V_BRING DET OBJECT_NAMES[Z] from the ROOMS_AND_LOCATIONS[X] to BRING_PERSONS | V_BRING DET OBJECT_NAMES[Z] to BRING_PERSONS from the ROOMS_AND_LOCATIONS[X] | V_BRING OBJECT_NAMES[Z] from the ROOMS_AND_LOCATIONS[X] to BRING_PERSONS | V_BRING OBJECT_NAMES[Z] to BRING_PERSONS from the ROOMS_AND_LOCATIONS[X]
165 VP["action": "bring", "target-location": {"type": "person"}, "object": {"type": Z}] -> V_BRING DET OBJECT_NAMES[Z] to BRING_PERSONS | V_BRING OBJECT_NAMES[Z] to BRING_PERSONS
166 
167 VP["action": "bring", "source-location": {"id": X}, "target-location": {"type": "person", "id": "operator"}, "object": {"type": Z}] -> V_BRING DET OBJECT_NAMES[Z] from the ROOMS_AND_LOCATIONS[X] to me | V_BRING me DET OBJECT_NAMES[Z] from the ROOMS_AND_LOCATIONS[X] | V_BRING OBJECT_NAMES[Z] from the ROOMS_AND_LOCATIONS[X] to me | V_BRING me OBJECT_NAMES[Z] from the ROOMS_AND_LOCATIONS[X]
168 VP["action": "bring", "target-location": {"type": "person", "id": "operator"}, "object": {"type": Z}] -> V_BRING DET OBJECT_NAMES[Z] to me | V_BRING me DET OBJECT_NAMES[Z] | V_BRING OBJECT_NAMES[Z] to me | V_BRING me OBJECT_NAMES[Z]
169 VP["action": "bring", "object": {"type": Z}] -> V_BRING DET OBJECT_NAMES[Z] | V_BRING OBJECT_NAMES[Z]
170 """
171 
172 for name in common.names:
173  grammar += '\nBRING_PERSONS -> %s' % name
174 
175 
180 
181 grammar += """
182 V_SAY -> tell | say | speak
183 
184 VP["action": "say", "sentence": X] -> V_SAY SAY_SENTENCE[X]
185 """
186 
187 grammar += '\nSAY_SENTENCE["ROBOT_NAME"] -> your name'
188 grammar += '\nSAY_SENTENCE["TIME"] -> the time | what time it is | what time is it'
189 grammar += '\nSAY_SENTENCE["my team is tech united"] -> the name of your team'
190 grammar += '\nSAY_SENTENCE["DAY_OF_MONTH"] -> the day of the month'
191 grammar += '\nSAY_SENTENCE["DAY_OF_WEEK"] -> the day of the week'
192 grammar += '\nSAY_SENTENCE["TODAY"] -> what day is today | me what day it is | the date'
193 grammar += '\nSAY_SENTENCE["TOMORROW"] -> what day is tomorrow'
194 
195 
196 follow_acton = "follow", {"location-from": {""}, "location-to": {}, "target": {}}
197 
198 
203 
204 grammar += """
205 
206 HIM_HER -> him | her
207 
208 VP["action": "find", "object": {"type": "person"}, "target": {"id": Z}] -> V_FIND MEET_PERSON[Z]
209 VP["action": "navigate-to"] -> V_GUIDE HIM_HER
210 """
211 
212 grammar += '\nMEET_PERSON[the person] -> DET person'
213 grammar += '\nMEET_PERSON[the woman] -> DET woman'
214 grammar += '\nMEET_PERSON[the man] -> DET man'
215 for name in common.names:
216  grammar += '\nMEET_PERSON[%s] -> %s' % (name, name)
217 
218 # FOLLOW PERSON : (PERSON is at the BEACON)
219 # BRING me (a | some) CATEGORY : (which object of this category)
220 # DELIVER CATEGORY to PERSON : (which object of this category) && (PERSON is at the BEACON)
221 # meet PERSON(M) and GUIDE him : (PERSON is at the BEACON) && (guide him to BEACON)
222 # meet PERSON(F) and GUIDE her : (PERSON is at the BEACON) && (guide her to BEACON)
223 # NAVIGATE-TO BEACON, meet PERSON(M), and GUIDE him : (guide him to BEACON) && (keep him not lost)
224 # NAVIGATE-TO BEACON, meet PERSON(F), and GUIDE her : (guide her to BEACON) && (keep him not lost)
225 
226 loc_grammar = """
227 
228 HE_SHE -> he | she | it | him | her
229 
230 VP["object": {"id": X}] -> HE_SHE is in the ROOMS_AND_LOCATIONS[X] | in the ROOMS_AND_LOCATIONS[X] | you could find HE_SHE in the ROOMS_AND_LOCATIONS[X]
231 """
232 
233 obj_grammar = """
234 
235 VP["object": {"id": Y}] -> the OBJECT_NAMES[Z] is DET OBJECT_NAMES[Y] | the OBJECT_NAMES[Z] is OBJECT_NAMES[Y] | OBJECT_NAMES[Y] | DET OBJECT_NAMES[Y]
236 """
237 
238 if __name__ == "__main__":
239  print("GPSR Grammar:\n\n{}\n\n".format(grammar))
240 
241  from grammar_parser.cfgparser import CFGParser
242 
243  import sys
244  if sys.argv[1] == "object":
245  grammar_parser = CFGParser.fromstring(obj_grammar)
246  elif sys.argv[1] == "location":
247  grammar_parser = CFGParser.fromstring(loc_grammar)
248  elif sys.argv[1] == "full":
249  grammar_parser = CFGParser.fromstring(grammar)
250 
251  if len(sys.argv) > 2:
252  sentence = " ".join(sys.argv[2:])
253  else:
254  sentence = grammar_parser.get_random_sentence("T")
255 
256  print("Parsing sentence:\n\n{}\n\n".format(sentence))
257 
258  result = grammar_parser.parse("T", sentence)
259 
260  print("Result:\n\n{}".format(result))
261 
common.get_locations
def get_locations(room=None, manipulation_location=None)
Definition: rwc2023/common.py:156