Пример #1
0
 def test_pipe(self):
     data = (3, 1, 1, 1, 1, 0.1, 0.1, 1000)
     expected = [1.0, 1.0, 0.7, 0.4]
     tester = self.numeric_evaluator(expected)
     coroutines = [co.sliding_window(3),
                   co.transformer(np.mean),
                   co.filterer(lambda x: 0 <= x <= 1),
                   tester]
     pipe_tester = co.pipe(coroutines)
     for d in data:
         pipe_tester.send(d)
Пример #2
0
 def test_pipe(self):
     data = (3, 1, 1, 1, 1, 0.1, 0.1, 1000)
     expected = [1.0, 1.0, 0.7, 0.4]
     tester = self.numeric_evaluator(expected)
     coroutines = [
         co.sliding_window(3),
         co.transformer(np.mean),
         co.filterer(lambda x: 0 <= x <= 1), tester
     ]
     pipe_tester = co.pipe(coroutines)
     for d in data:
         pipe_tester.send(d)
# disponible en <URL a la LASR_UC3Mv1.0>.
"""
Node that translates EventHandler Messages to AtomMsgs.

:author: Victor Gonzalez Pacheco
:maintainer: Victor Gonzalez Pacheco
"""

import roslib
roslib.load_manifest('ocular_interaction')
import rospy
from rospy_utils import coroutines as co

from ocular_interaction import ocular_atom_translators as tr

from dialog_manager_msgs.msg import AtomMsg
from ocular.msg import EventHandler

if __name__ == '__main__':
    try:
        rospy.init_node('ocular_event_handler_translator')
        rospy.loginfo("Initializing {} Node".format(rospy.get_name()))
        pipe = co.pipe([
            co.transformer(tr.event_handler_to_atom),
            co.publisher('im_atom', AtomMsg)
        ])
        co.PipedSubscriber('event_low_rate', EventHandler, pipe)
        rospy.spin()
    except rospy.ROSInterruptException:
        pass
Пример #4
0
import roslib
roslib.load_manifest('ocular_interaction')
import rospy
from rospy_utils import coroutines as co

from ocular_interaction import ocular_atom_translators as tr
from ocular_interaction import utils

from std_msgs.msg import String
from dialog_manager_msgs.msg import AtomMsg


def _log_atom(atom_msg):
    """Log an atom message."""
    utils.log_atom(atom_msg, logger=rospy.logdebug)


if __name__ == '__main__':
    try:
        rospy.init_node('ocular_event_handler_translator')
        rospy.loginfo("Initializing {} Node".format(rospy.get_name()))
        pipe = co.pipe([
            co.transformer(tr.object_name_to_atom),
            co.do(_log_atom),
            co.publisher('im_atom', AtomMsg)
        ])
        co.PipedSubscriber('object_name', String, pipe)
        rospy.spin()
    except rospy.ROSInterruptException:
        pass
Пример #5
0
"""
import roslib
roslib.load_manifest('ocular_interaction')

from functools import partial

import rospy
from rospy_utils import coroutines as co

from ocular_interaction import ocular_action_translators as tr
from dialog_manager_msgs.msg import ActionMsg
from etts_msgs.msg import Utterance

is_action_valid = partial(tr.should_process_action,
                          actor_name="etts",
                          action_name="say_text")

if __name__ == '__main__':
    try:
        rospy.init_node('ocular_etts_translator')
        rospy.loginfo("Initializing {} Node".format(rospy.get_name()))
        pipe = co.pipe([
            co.filterer(is_action_valid),
            co.transformer(tr.action_to_etts),
            co.publisher('etts', Utterance)
        ])
        co.PipedSubscriber('im_action', ActionMsg, pipe)
        rospy.spin()
    except rospy.ROSInterruptException:
        pass
Пример #6
0
    """
    msg_package, msg_name = msg_typename.split('/')
    msg_full_typename = '.'.join([msg_package, 'msg', msg_name])
    return rpyu.load_class(msg_full_typename)


if __name__ == '__main__':
    # TODO: This is highly replicable for filter_node, accumulator, etc.
    #       At some point I will separate all the repeteable parts to a class

    my_args = rospy.myargv(sys.argv)[1:]
    f, in_topic, in_typename, out_topic, out_typename = parse_arguments(
        my_args)
    func = rpyu.load_class(f)
    in_type = get_msg_type(in_typename)
    out_type = get_msg_type(out_typename)

    try:
        rospy.init_node('topic_mapper')
        pipe = co.pipe(
            [co.transformer(func),
             co.publisher(out_topic, out_type)])
        subscriber = co.PipedSubscriber(in_topic, in_type, pipe)
        rospy.loginfo("Node {} successfully started\nIt will map: {}\n"
                      "From: {} ({}) --> To: {} ({})".format(
                          rospy.get_name(), f, in_topic, in_typename,
                          out_topic, out_typename))
        rospy.spin()
    except rospy.ROSInterruptException:
        pass
"""
Node that translates ObjectDescriptor Messages to AtomMsgs.

:author: Victor Gonzalez Pacheco
:maintainer: Victor Gonzalez Pacheco
"""

import roslib
roslib.load_manifest('ocular_interaction')
import rospy
from rospy_utils import coroutines as co

from ocular_interaction import ocular_atom_translators as tr

from dialog_manager_msgs.msg import AtomMsg
from ocular_msgs.msg import ObjectDescriptor

# from ocular_interaction import utils

if __name__ == '__main__':
    try:
        rospy.init_node('ocular_object_learned_translator')
        rospy.loginfo("Initializing {} Node".format(rospy.get_name()))
        pipe = co.pipe([co.transformer(tr.learned_object_to_atom),
                        # co.do(utils.log_atom),
                        co.publisher('im_atom', AtomMsg)])
        co.PipedSubscriber('learned_object', ObjectDescriptor, pipe)
        rospy.spin()
    except rospy.ROSInterruptException:
        pass
Пример #8
0
"""
Node that translates ASR Messages to AtomMsgs.

:author: Victor Gonzalez Pacheco
:maintainer: Victor Gonzalez Pacheco
"""

import roslib
roslib.load_manifest('ocular_interaction')
import rospy
from rospy_utils import coroutines as co

from ocular_interaction import ocular_atom_translators as tr
from ocular_interaction import utils

from dialog_manager_msgs.msg import AtomMsg
from asr_msgs.msg import open_grammar_recog_results as ASRMsg


if __name__ == '__main__':
    try:
        rospy.init_node('ocular_asr_translator')
        rospy.loginfo("Initializing {} Node".format(rospy.get_name()))
        pipe = co.pipe([co.transformer(tr.asr_msg_to_atom),
                        co.do(utils.log_atom),
                        co.publisher('im_atom', AtomMsg)])
        co.PipedSubscriber('open_grammar_results', ASRMsg, pipe)
        rospy.spin()
    except rospy.ROSInterruptException:
        pass
from functools import partial
from nltk.stem import SnowballStemmer as Stemmer

import rospy
from rospy_utils import coroutines as co

from asr_msgs.msg import open_grammar_recog_results as ASRmsg
from std_msgs.msg import String
from dialog_manager_msgs.msg import AtomMsg
from ocular_interaction import ocular_atom_translators as tr
from ocular_interaction import utils

atom_logger = partial(utils.log_atom, logger=rospy.loginfo)

translator_pipe = co.pipe([
    co.transformer(tr.asr_first_noun_to_atom),
    co.do(atom_logger),
    co.publisher('im_atom', AtomMsg)
])

splitter = co.splitter(co.publisher('nouns_from_asr', String), translator_pipe)


def get_asr_content(asr_msg):
    """
    Return the content of an ASR Msg.

    Example:

    >>> asrmsg = ASRmsg(content='Hello World', confidence=100.0, languageID=0)
    >>> get_asr_content(asrmsg)
Пример #10
0
    >>> msg(data='Hello World!')
    data: Hello World!
    """
    msg_package, msg_name = msg_typename.split('/')
    msg_full_typename = '.'.join([msg_package, 'msg', msg_name])
    return rpyu.load_class(msg_full_typename)

if __name__ == '__main__':
    # TODO: This is highly replicable for filter_node, accumulator, etc.
    #       At some point I will separate all the repeteable parts to a class

    my_args = rospy.myargv(sys.argv)[1:]
    f, in_topic, in_typename, out_topic, out_typename = parse_arguments(my_args)
    func = rpyu.load_class(f)
    in_type = get_msg_type(in_typename)
    out_type = get_msg_type(out_typename)

    try:
        rospy.init_node('topic_mapper')
        pipe = co.pipe([co.transformer(func),
                        co.publisher(out_topic, out_type)])
        subscriber = co.PipedSubscriber(in_topic, in_type, pipe)
        rospy.loginfo("Node {} successfully started\nIt will map: {}\n"
                      "From: {} ({}) --> To: {} ({})"
                      .format(rospy.get_name(),
                              f, in_topic, in_typename,
                              out_topic, out_typename))
        rospy.spin()
    except rospy.ROSInterruptException:
        pass
Пример #11
0
 def test_transformer_curried(self):
     expected, tester = self.__set_up_transformer()
     test_transformer = co.transformer(inc)
     test_transformer.send(tester)
     for i in self.data:
         test_transformer.send(i)
Пример #12
0
                          actor_name="object_name_translator",
                          action_name="object_name")


def __get_object_name(string_msg):
    """Get the object name from a std_msgs/String."""
    return String(data=utils.get_first_noun(string_msg.data))


def __log_object_name(string_msg):
    """Log to screen the object name."""
    object_name = utils.normalize_word(string_msg.data)
    rospy.logwarn("Object Name is: {}".format(object_name))


if __name__ == '__main__':
    try:
        rospy.init_node('ocular_object_name_translator')
        rospy.loginfo("Initializing {} Node".format(rospy.get_name()))
        pipe = co.pipe([
            co.filterer(is_action_valid),
            co.transformer(tr.action_to_object_name),
            co.transformer(__get_object_name),
            co.do(__log_object_name),
            co.publisher('object_name', String)
        ])
        co.PipedSubscriber('im_action', ActionMsg, pipe)
        rospy.spin()
    except rospy.ROSInterruptException:
        pass
Пример #13
0
 def test_transformer_curried(self):
     expected, tester = self.__set_up_transformer()
     test_transformer = co.transformer(inc)
     test_transformer.send(tester)
     for i in self.data:
         test_transformer.send(i)
roslib.load_manifest('ocular_interaction')
from functools import partial
from itertools import ifilter
import rospy
from rospy_utils import coroutines as co
from rospy_utils import param_utils as pu
from asr_msgs.msg import open_grammar_recog_results as ASRmsg
from std_msgs.msg import String
from dialog_manager_msgs.msg import AtomMsg
from ocular_interaction import ocular_atom_translators as tr
from ocular_interaction import utils

atom_logger = partial(utils.log_atom, logger=rospy.loginfo)

translator_pipe = co.pipe([
    co.transformer(tr.user_command_to_atom),
    co.do(atom_logger),
    co.publisher('im_atom', AtomMsg)
])

splitter = co.splitter(co.publisher('asr_command', String), translator_pipe)


def get_command(word, commands):
    """Check wether word is a command from the commands dictionary."""
    try:
        return commands.get(utils.to_infinitive(word), None)
    except UnicodeDecodeError:
        rospy.logwarn(
            "UnicodeDecodeError while stemming word: {}".format(word))