Skip to content

Commit

Permalink
Merge pull request #95 from tue-robotics/rgo2018
Browse files Browse the repository at this point in the history
RGO2018
  • Loading branch information
rokusottervanger authored Jun 16, 2018
2 parents 3d09ab5 + 2c5fba4 commit de3e2fd
Show file tree
Hide file tree
Showing 19 changed files with 820 additions and 581 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ before_install:
script:
- 'for PACKAGE in $PACKAGES;
do
bash install-package.sh --package=$PACKAGE --branch=$TRAVIS_BRANCH --commit=$TRAVIS_COMMIT --pullrequest=$TRAVIS_PULL_REQUEST &&
bash install-package.sh --package=$PACKAGE --branch=${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH} --commit=$TRAVIS_COMMIT --pullrequest=$TRAVIS_PULL_REQUEST &&
bash build-package.sh --package=$PACKAGE;
done'
11 changes: 6 additions & 5 deletions action_server/src/action_server/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

from answer_question import AnswerQuestion
from arm_goal import ArmGoal
from bring import Bring
from demo_presentation import DemoPresentation
from find import Find
from follow import Follow
from guide import Guide
from gripper_goal import GripperGoal
from hand_over import HandOver
from inspect import Inspect
from look_at import LookAt
from navigate_to import NavigateTo
from pick_up import PickUp
from place import Place
from reset_wm import ResetWM
from find import Find
from say import Say
from follow import Follow
from guide import Guide
from demo_presentation import DemoPresentation
from send_picture import SendPicture
from turn_toward_sound import TurnTowardSound
42 changes: 23 additions & 19 deletions action_server/src/action_server/actions/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,40 @@ class ConfigurationData(object):
"""
The ConfigurationData class defines the input data structure for configuration of an action.
"""
def __init__(self, semantics, knowledge=None):
def __init__(self, semantics, context=None):
"""
:param semantics: Dictionary of the following structure: {'action': <action-name>, 'param1': <param-value>}.
:param knowledge: Dictionary of parameter names to knowledge provided by previous actions.
:param context: Dictionary of parameter names to context provided by previous actions.
"""
self.semantics = semantics
if knowledge:
self.knowledge = knowledge
if context:
self.context = context
else:
self.knowledge = {}
self.context = {}

def __repr__(self):
return "ConfigurationData(semantics=%s, knowledge=%s)" % (self.semantics, self.knowledge)
return "ConfigurationData(semantics={}, context={})".format(self.semantics, self.context)


class ConfigurationResult(object):
"""
The ConfigurationResult class defines the data structure that is returned by the configure() methods of actions
"""
def __init__(self, succeeded=False, resulting_knowledge=None):
if resulting_knowledge is None:
resulting_knowledge = {}
def __init__(self, succeeded=False, context=None):
if context is None:
context = {}

self.succeeded = succeeded
self.resulting_knowledge = resulting_knowledge
self.context = context
self.required_context = None
self.missing_field = ""
self.missing_skill = None
self.message = ""

def __repr__(self):
return "ConfigurationResult(succeeded=%s, resulting_knowledge=%s, missing_field=%s, missing_skill=%s, " \
"message=%s)" % (self.succeeded, self.resulting_knowledge, self.missing_field, self.missing_skill,
self.message)
return "ConfigurationResult(succeeded={}, context={}, required_context={}, missing_field={}, " \
"missing_skill={}, message={})".format(self.succeeded, self.context, self.required_context,
self.missing_field, self.missing_skill, self.message)


class ActionResult(object):
Expand Down Expand Up @@ -76,8 +77,8 @@ def _check_parameters(self, config):
return False

for k, v in self._required_passed_knowledge.items():
if k not in config.knowledge:
rospy.logerr("Missing required knowledge {}".format(k))
if k not in config.context:
rospy.logerr("Missing required context {}".format(k))
self._config_result.missing_field = k
self._config_result.message = v
return False
Expand All @@ -97,18 +98,21 @@ def configure(self, robot, config):
Configure the action with a robot and configuration data
:param robot: The robot to use for this action
:type robot: Robot
:param config: The configuration data. Contains semantics from input and implied knowledge from previous tasks.
:param config: The configuration data. Contains semantics from input and implied context from previous tasks.
:type config: ConfigurationData
:return: The result of configuration
:rtype: ConfigurationResult
"""
rospy.loginfo("Configuring action {} with semantics {} and knowledge {}.".
format(self.get_name(), config.semantics, config.knowledge))
self._config_result = ConfigurationResult()

if not isinstance(config, ConfigurationData):
rospy.logerr("Action: the specified config should be ConfigurationData! I received: %s" % str(config))
self._config_result.message = " Something's wrong with my wiring. I'm so sorry, but I cannot do this. "
return self._config_result

rospy.loginfo("Configuring action {} with semantics {} and context {}.".
format(self.get_name(), config.semantics, config.context))

if not isinstance(robot, Robot):
rospy.logerr("Action: the specified robot should be a Robot! I received: %s" % str(robot))
self._config_result.message = " I don't know what to say. I'm having an identity crisis. I'm so sorry. "
Expand All @@ -117,7 +121,7 @@ def configure(self, robot, config):
if self._check_parameters(config) and self._check_skills(robot):
self._configure(robot, config)

rospy.loginfo("Resulting knowledge = {}".format(self._config_result.resulting_knowledge))
rospy.loginfo("Resulting context = {}".format(self._config_result.context))

return self._config_result

Expand Down
25 changes: 15 additions & 10 deletions action_server/src/action_server/actions/answer_question.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import rospy
from robocup_knowledge import load_knowledge
import challenge_spr
import hmi


Expand All @@ -21,7 +22,7 @@ def __init__(self):
def _configure(self, robot, config):
self._robot = robot

self._speech_data = load_knowledge('challenge_gpsr')
self._speech_data = load_knowledge('challenge_spr')
if not self._speech_data:
rospy.logerr("Failed to load speech data for 'AnswerQuestion' action")
return
Expand Down Expand Up @@ -60,23 +61,27 @@ def _start(self):
while tries < 3:
try:
res = self._robot.hmi.query(description="",
grammar=self._speech_data.question_grammar,
target=self._speech_data.question_grammar_target)
grammar=self._speech_data.grammar,
target=self._speech_data.grammar_target)
except hmi.TimeoutException:
self._robot.speech.speak("My ears are not working properly, sorry!")
self._execute_result.message = " I was unable to hear anything when listening for a question, so I " \
"could not answer it. "
tries += 1
continue

print res.semantics

if res.semantics and "actions" in res.semantics:
rospy.loginfo("Question was: '%s'?" % res.sentence)
self._robot.speech.speak("The answer is %s" % res.semantics['actions'][0]['solution'])
self._execute_result.message = " I answered the question {}".format(res.sentence)
self._execute_result.succeeded = True
return
try:
# TODO: remove this from challenge states, because apparently, this is more generic.
challenge_spr.riddle_game.answer(self._robot, res, None)
self._execute_result.message = " I answered the question {}".format(res.sentence)
self._execute_result.succeeded = True
return
except ValueError:
self._robot.speech.speak("I don't know these people you are talking about. ")
self._execute_result.message = " I couldn't answer the question about the crowd."
tries += 1
continue
else:
if tries < 2:
self._robot.speech.speak("Sorry, I did not understand your question, try another one.")
Expand Down
Loading

0 comments on commit de3e2fd

Please sign in to comment.