Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import print_function

from robocup_knowledge import knowledge_loader
common = knowledge_loader.load_knowledge("common")
from robocup_knowledge import knowledge_functions

not_understood_sentences = [
"I'm so sorry! Can you please speak louder and slower? And wait for the ping!",
Expand Down Expand Up @@ -38,19 +36,21 @@
MANIPULATION_AREA_DESCRIPTION -> on top of | at | in | on | from
"""

for loc in common.get_locations():
grammar += '\nLOCATION[%s] -> %s' % (loc, loc)
# object_names = knowledge_functions.get_object_names()

# for loc in knowledge_functions.get_locations():
# grammar += '\nLOCATION[%s] -> %s' % (loc, loc)

for obj in common.object_names:
grammar += '\nNAMED_OBJECT[%s] -> %s' % (obj, obj)
# for obj in object_names:
# grammar += '\nNAMED_OBJECT[%s] -> %s' % (obj, obj)

for loc in common.get_locations(pick_location=True, place_location=True):
grammar += '\nMANIPULATION_AREA_LOCATION[%s] -> MANIPULATION_AREA_DESCRIPTION the %s' % (loc, loc)
# for loc in knowledge_functions.get_locations(pick_location=True, place_location=True):
# grammar += '\nMANIPULATION_AREA_LOCATION[%s] -> MANIPULATION_AREA_DESCRIPTION the %s' % (loc, loc)

for cat in common.object_categories:
for cat in knowledge_functions.object_categories:
grammar += '\nOBJECT_CATEGORY[%s] -> %s' % (cat, cat)

for name in common.names:
for name in knowledge_functions.names:
grammar += '\nNAMED_PERSON[%s] -> %s' % (name, name)

###############################################################################
Expand Down Expand Up @@ -151,7 +151,7 @@
VP["action": "bring", "source-location": {"id": X}, "target-location": {"type": "person", "id": Y}, "object": {"type": Z}] -> V_BRING BRING_NAME[Y] OBJECT_TO_BE_BROUGHT[Z] from the LOCATION[X]
"""

for name in common.names:
for name in knowledge_functions.names:
grammar += '\nBRING_PERSON[%s] -> %s' % (name, name)

##############################################################################
Expand Down Expand Up @@ -193,11 +193,15 @@
from grammar_parser.cfgparser import CFGParser

import sys
if sys.argv[1] == "object":
grammar_parser = CFGParser.fromstring(obj_grammar)
elif sys.argv[1] == "location":
grammar_parser = CFGParser.fromstring(loc_grammar)
elif sys.argv[1] == "full":
if len(sys.argv) > 1:
if sys.argv[1] == "object":
grammar_parser = CFGParser.fromstring(obj_grammar)
elif sys.argv[1] == "location":
grammar_parser = CFGParser.fromstring(loc_grammar)
elif sys.argv[1] == "full":
grammar_parser = CFGParser.fromstring(grammar)

else:
grammar_parser = CFGParser.fromstring(grammar)

if len(sys.argv) > 2:
Expand Down
104 changes: 0 additions & 104 deletions robocup_knowledge/src/robocup_knowledge/environments/demo/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,107 +72,3 @@ def printWarning(sentence):
print(prefix + bcolors.WARNING + sentence + bcolors.ENDC)

return printOk, printError, printWarning


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


def is_location(location):
for loc in locations:
if loc["name"] == location:
return True
return False


def get_room(location):
if location in location_rooms:
return location
for loc in locations:
if loc["name"] == location:
return loc["room"]
return None


def get_inspect_areas(location):
if location in inspect_areas:
return inspect_areas[location]
else:
return ["on_top_of"]


def get_inspect_position(location, area=""):
if location in inspect_positions and area in inspect_positions[location]:
return inspect_positions[location][area]
else:
return "in_front_of"


def is_pick_location(location):
for loc in locations:
if loc["name"] == location and loc["manipulation"] == "yes":
return True
return False


def is_place_location(location):
for loc in locations:
if loc["name"] == location and (loc["manipulation"] == "yes" or loc["manipulation"] == "only_putting"):
return True
return False


def get_locations(room=None, pick_location=None, place_location=None):
return [loc["name"] for loc in locations
if (room == None or loc["room"] == room) and \
(pick_location == None or pick_location == is_pick_location(loc["name"])) and \
(place_location == None or place_location == is_place_location(loc["name"]))]


def get_objects(category=None):
return [obj["name"] for obj in objects
if category == None or category == obj["category"]]


def get_object_category(obj):
for o in objects:
if o["name"] == obj:
return o["category"]
return None


def get_object_category_location(obj_cat):
# Returns (location, area_name)
location, area_name = next(iter(category_locations[obj_cat].items()))
return location, area_name


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


if __name__ == "__main__":
print("\n-----------------------------------------------------------------------------")
for obj in get_objects():
cat = get_object_category(obj)
(location, area_name) = get_object_category_location(cat)
print("object '{}'".format(obj))
print(" category: '{}'".format(cat))
print(" found '{} {}'".format(area_name, location))

print("\n-----------------------------------------------------------------------------")
for loc in get_locations():
print("location '{}', room: '{}'".format(loc, get_room(loc)))

print("\n-----------------------------------------------------------------------------")
print("Pick locations:")
for loc in get_locations(pick_location=True):
print(" {}".format(loc))

print("\n-----------------------------------------------------------------------------")
print("Place locations:")
for loc in get_locations(place_location=True):
print(" {}".format(loc))

print("\n-----------------------------------------------------------------------------")
print("None-manipulation locations:")
for loc in get_locations(pick_location=False, place_location=False):
print(" {}".format(loc))
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from robocup_knowledge import knowledge_loader
common = knowledge_loader.load_knowledge("common")
from robocup_knowledge import knowledge_functions

starting_point = "starting_pose"
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import print_function
from robocup_knowledge.knowledge_functions import KnowledgeFunctions

from robocup_knowledge import knowledge_loader
common = knowledge_loader.load_knowledge("common")
kf = KnowledgeFunctions()

not_understood_sentences = [
"I'm so sorry! Can you please speak louder and slower? And wait for the ping!",
Expand Down Expand Up @@ -35,19 +35,19 @@
MANIPULATION_AREA_DESCRIPTION -> on top of | at | in | on | from
"""

for loc in common.get_locations():
for loc in kf.get_locations():
grammar += '\nLOCATION[%s] -> %s' % (loc, loc)

for obj in common.object_names:
for obj in kf.object_names:
grammar += '\nNAMED_OBJECT[%s] -> %s' % (obj, obj)

for loc in common.get_locations(pick_location=True, place_location=True):
for loc in kf.get_locations(pick_location=True, place_location=True):
grammar += '\nMANIPULATION_AREA_LOCATION[%s] -> MANIPULATION_AREA_DESCRIPTION the %s' % (loc, loc)

for cat in common.object_categories:
for cat in kf.object_categories:
grammar += '\nOBJECT_CATEGORY[%s] -> %s' % (cat, cat)

for name in common.names:
for name in kf.names:
grammar += '\nNAMED_PERSON[%s] -> %s' % (name, name)

###############################################################################
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from robocup_knowledge import knowledge_functions

starting_point = "initial_pose"

room = "dining_room"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import print_function

from robocup_knowledge import knowledge_loader
common = knowledge_loader.load_knowledge("common")
from robocup_knowledge import knowledge_functions

not_understood_sentences = [
"I'm so sorry! Can you please speak louder and slower? And wait for the ping!",
Expand Down Expand Up @@ -48,26 +46,26 @@
MANIPULATION_PP -> on
"""

for room in common.location_rooms:
for room in knowledge_functions.location_rooms:
grammar += "\nROOM[{'type': 'room', 'id': '%s'}] -> %s" % (room, room)

for loc in common.get_locations():
for loc in knowledge_functions.get_locations():
grammar += '\nLOCATION[{"id": "%s"}] -> %s' % (loc, loc)

grammar += '\n ROOM_OR_LOCATION[X] -> ROOM[X] | LOCATION[X]'

for obj in common.object_names:
for obj in knowledge_functions.object_names:
grammar += "\nNAMED_OBJECT[{'type': '%s'}] -> %s" % (obj, obj)

for loc in common.get_locations(pick_location=True, place_location=True):
for loc in knowledge_functions.get_locations(pick_location=True, place_location=True):
grammar += '\nMANIPULATION_AREA_LOCATION[{"id": "%s"}] -> MANIPULATION_PP the %s' % (loc, loc)

for cat in common.object_categories:
for cat in knowledge_functions.object_categories:
grammar += "\nOBJECT_CATEGORY[{'category': '%s'}] -> %s" % (cat, cat)

for name in common.names:
for name in knowledge_functions.names:
grammar += "\nNAMED_PERSON[{'type': 'person', 'id': '%s'}] -> %s" % (name, name)
for loc in common.get_locations():
for loc in knowledge_functions.get_locations():
grammar += "\nPERSON_AT_LOCATION[{'type': 'person', 'id': '%s', 'location': {'id': %s}}] -> %s at the %s" % (name, loc, name, loc)

grammar += '\nLOCATION[{"id": "gpsr_exit_door_1", "type": "waypoint"}] -> exit'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from robocup_knowledge import knowledge_functions

starting_point = "initial_pose"
home_location = "rips_point_1"
room = "dining_room"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from robocup_knowledge import knowledge_loader
common = knowledge_loader.load_knowledge("common")
from robocup_knowledge import knowledge_functions

operator_name = "john"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# TU/e Robotics
from robocup_knowledge import knowledge_loader
from robocup_knowledge import knowledge_functions

# Common knowledge
common = knowledge_loader.load_knowledge("common")

order_grammar = """
O[P] -> ORDER[P] | can i have a ORDER[P] | i would like ORDER[P] | can i get ORDER[P] | could i have ORDER[P] | may i get ORDER[P] | bring me ORDER[P]
Expand All @@ -20,7 +18,7 @@
# BEVERAGE[{"beverage": B}] -> DET BEV[B]

# Add drinks
for d in common.objects:
for d in knowledge_functions.objects:
if d["category"] == "drink":
order_grammar += "\nBEV['{}'] -> {}[B]".format(d["name"], d["name"].replace('_', ' '))
elif d["category"] == "food":
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from robocup_knowledge import knowledge_functions

starting_point = "initial_pose"

intermediate_1 = "rips_point_1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# TU/e Robotics
from robocup_knowledge import knowledge_loader

# Common knowledge
common = knowledge_loader.load_knowledge("common")
from robocup_knowledge import knowledge_functions

# General
starting_point = "initial_pose"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# TU/e Robotics
from robocup_knowledge import knowledge_loader

# Common knowledge
common = knowledge_loader.load_knowledge("common")
from robocup_knowledge import knowledge_functions

# General
starting_point = 'initial_pose'
Expand All @@ -12,8 +9,8 @@
default_area = "shelf4"
inspect_area = "in_front_of"
object_shelves = ["shelf3", "shelf4", "shelf5"] # TODO unused variable?
object_types = [obj["name"] for obj in common.objects] # TODO unused variable?
object_types = [obj["name"] for obj in knowledge_functions.objects] # TODO unused variable?

# Grasping
table = "dinner_table"
room = common.get_room(table)
room = knowledge_functions.get_room(table)
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# TAKE OUT THE GARBAGE KNOWLEDGE FILE IMPULS
# TU/e Robotics
from robocup_knowledge import knowledge_loader

# Common knowledge
common = knowledge_loader.load_knowledge("common")
from robocup_knowledge import knowledge_functions

starting_point = "initial_pose"
trashbin_id = "trashbin"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from collections import namedtuple

# TU/e Robotics
from robocup_knowledge import knowledge_loader
from robocup_knowledge import knowledge_functions

BackupScenario = namedtuple("BackupScenario", ["entity_id", "sentence"])

Expand All @@ -19,16 +19,15 @@
information_point_id = "where_is_this_information_point"
initial_pose_id = "initial_pose"

# Common knowledge
common = knowledge_loader.load_knowledge("common")


grammar_target = "T"

starting_point_grammar = """
T[A] -> LOCATION[A]
"""

for loc in common.location_names:
for loc in knowledge_functions.location_names:
starting_point_grammar += '\nLOCATION[%s] -> %s' % (loc, loc)

location_grammar = """
Expand All @@ -37,18 +36,18 @@
COURTESY_PREFIX -> robot please | could you | could you please | please
"""

for loc in common.location_rooms:
for loc in knowledge_functions.location_rooms:
location_grammar += '\nLOCATION[%s] -> %s' % (loc, loc)

for loc in common.location_names:
for loc in knowledge_functions.location_names:
location_grammar += '\nLOCATION[%s] -> %s' % (loc, loc)

for loc in common.object_names:
category = common.get_object_category(loc)
if category not in common.category_locations:
for loc in knowledge_functions.object_names:
category = knowledge_functions.get_object_category(loc)
if category not in knowledge_functions.category_locations:
continue

entity_id = common.get_object_category_location(category)[0]
entity_id = knowledge_functions.get_object_category_location(category)[0]

location_grammar += '\nLOCATION[%s] -> %s' % (entity_id, loc)

Expand Down
Loading