robocup_knowledge
rwc2019/challenge_cleanup.py
Go to the documentation of this file.
1 # CLEAN UP KNOWLEDGE FILE ROBOTICS_TESTLABS
2 
3 from __future__ import print_function
4 
5 from robocup_knowledge import knowledge_loader
6 common = knowledge_loader.load_knowledge("common")
7 
8 """
9 Local knowledge info needed:
10 The room to search has to have enough (way)points to cover the complete area.
11 This means waypoints on the floor, and known (furniture) object points.
12 Exact coordinates of the locations are in ed_object_models.
13 """
14 
15 # TODO: check
16 starting_point = "initial_pose"
17 waiting_point = "cleanup_initial" # ToDo; CHANGE
18 
19 cleaning_locations = [
20  {'name': 'bedroom_chest', 'room': 'bedroom', 'navigation_area': 'in_front_of', 'segment_areas': ['on_top_of']},
21  {'name': 'bed', 'room': 'bedroom', 'navigation_area': 'in_front_of', 'segment_areas': ['on_top_of']},
22  {'name': 'sidetable', 'room': 'bedroom', 'navigation_area': 'in_front_of', 'segment_areas': ['on_top_of']},
23  {'name': 'shelf', 'room': 'bedroom', 'navigation_area': 'in_front_of', 'segment_areas': ['shelf2','shelf3','shelf4','shelf5']},
24 
25 # {'name': 'trash_bin', 'room': 'kitchen', 'navigation_area': 'in_front_of', 'segment_areas': ['on_top_of']},
26  {'name': 'kitchen_cabinet', 'room': 'kitchen', 'navigation_area': 'in_front_of', 'segment_areas': ['shelf1','shelf2','shelf3']},
27  {'name': 'kitchen_table', 'room': 'kitchen', 'navigation_area': 'in_front_of', 'segment_areas': ['on_top_of']},
28  {'name': 'island', 'room': 'kitchen', 'navigation_area': 'in_front_of', 'segment_areas': ['on_top_of']},
29  {'name': 'sink', 'room': 'kitchen', 'navigation_area': 'in_front_of', 'segment_areas': ['on_top_of']},
30  {'name': 'dishwasher', 'room': 'kitchen', 'navigation_area': 'in_front_of', 'segment_areas': ['on_top_of']},
31  {'name': 'fridge', 'room': 'kitchen', 'navigation_area': 'in_front_of', 'segment_areas': ['on_top_of']},
32 
33  {'name': 'shoe_rack', 'room': 'office', 'navigation_area': 'in_front_of', 'segment_areas': ['on_top_of']},
34  {'name': 'safe', 'room': 'office', 'navigation_area': 'in_front_of', 'segment_areas': ['on_top_of']},
35  {'name': 'desk', 'room': 'office', 'navigation_area': 'in_front_of', 'segment_areas': ['on_top_of']},
36  # {'name': 'coat_hanger', 'room': 'office', 'navigation_area': 'in_front_of', 'segment_areas': ['on_top_of']},
37 
38  {'name': 'coffee_table', 'room': 'living_room', 'navigation_area': 'in_front_of', 'segment_areas': ['on_top_of']},
39  {'name': 'couch', 'room': 'living_room', 'navigation_area': 'in_front_of', 'segment_areas': ['on_top_of']},
40  {'name': 'armchair', 'room': 'living_room', 'navigation_area': 'in_front_of', 'segment_areas': ['on_top_of']},
41  {'name': 'display_cabinet', 'room': 'living_room', 'navigation_area': 'in_front_of', 'segment_areas': ['on_top_of']},
42 # {'name': 'trash_bin1', 'room': 'living_room', 'navigation_area': 'in_front_of', 'segment_areas': ['on_top_of']},
43  {'name': 'sideboard', 'room': 'living_room', 'navigation_area': 'in_front_of', 'segment_areas': ['on_top_of']}
44 ]
45 
46 trashbin_id = "trash_bin"
47 
48 grammar_target = "T"
49 
50 grammar = ""
51 for room in common.location_rooms:
52  grammar += "\nT[{0}] -> {0}".format(room)
53 
54 category_grammar = """
55 T[P] -> CATEGORY[P] | it is a CATEGORY[P] | the category is CATEGORY[P]
56 """
57 for l in common.category_locations:
58  category_grammar += "\nCATEGORY[{}] -> {}".format(l, l.replace('_', ' '))
59 
60 category_grammar += "\nCATEGORY[{}] -> {}".format("trash", "trash".replace('_', ' '))
61 
62 
63 if __name__ == "__main__":
64  print("Clean-up Grammar:\n\n{}\n\n".format(category_grammar))
65 
66  from grammar_parser.cfgparser import CFGParser
67 
68  import sys
69  grammar_parser = CFGParser.fromstring(category_grammar)
70 
71  if len(sys.argv) > 2:
72  sentence = " ".join(sys.argv[2:])
73  else:
74  sentence = grammar_parser.get_random_sentence("T")
75 
76  print("Parsing sentence:\n\n{}\n\n".format(sentence))
77 
78  result = grammar_parser.parse("T", sentence)
79 
80  print("Result:\n\n{}".format(result))