Beispiel #1
0
 def _ros_service_get_interaction(self, request):
     '''
       Handle incoming requests for a single app.
     '''
     response = interaction_srvs.GetInteractionResponse()
     interaction = self._interactions_table.find(request.hash)
     if interaction is None:
         response.interaction = interaction_msgs.Interaction()
         response.result = False
     else:
         response.interaction = interaction.msg
         response.result = True
     return response
Beispiel #2
0
def load_msgs_from_yaml_file(file_path):
    """
      Load interactions from a yaml resource.

      :param str file_path: file path of a yaml formatted interactions file (ext=.interactions).

      :returns: a list of ros msg interaction specifications
      :rtype: rocon_interaction_msgs.Interaction_ []

      :raises: :exc:`.YamlResourceNotFoundException` if yaml is not found.
      :raises: :exc:`.MalformedInteractionsYaml` if yaml is malformed.

      .. include:: weblinks.rst
    """
    interactions = []
    try:
        yaml_filename = file_path
        if not os.path.isfile(yaml_filename):
            raise YamlResourceNotFoundException(str(e))
    except rospkg.ResourceNotFound as e:  # resource not found.
        raise YamlResourceNotFoundException(str(e))
    with open(yaml_filename) as f:
        # load the interactions from yaml into a python object
        interaction_yaml_objects = yaml.load(f)
        # now drop it into message format
        for interaction_yaml_object in interaction_yaml_objects:
            # convert the parameters from a freeform yaml variable to a yaml string suitable for
            # shipping off in ros msgs (where parameters is a string variable)
            if 'parameters' in interaction_yaml_object:  # it's an optional key
                # chomp trailing newlines
                interaction_yaml_object['parameters'] = yaml.dump(
                    interaction_yaml_object['parameters']).rstrip()
            interaction = interaction_msgs.Interaction()
            try:
                genpy.message.fill_message_args(interaction,
                                                interaction_yaml_object)
            except genpy.MessageException as e:
                raise MalformedInteractionsYaml(
                    "malformed yaml preventing converting of yaml to interaction msg type [%s]"
                    % str(e))
            interactions.append(interaction)
    return interactions
Beispiel #3
0
def load_msgs_from_yaml_resource(resource_name):
    """
      Load interactions from a yaml resource.

      :param resource_name: pkg/filename of a yaml formatted interactions file (ext=.interactions).
      :type resource_name: str

      :returns: a list of ros msg interaction specifications
      :rtype: concert_msgs.Interaction[]

      :raises: :exc:`rocon_interactions.YamlResourceNotFoundException,` if yaml is not found.
      :raises: :exc:`rocon_interactions.MalformedInteractionsYaml,` if yaml is malformed.
    """
    interactions = []
    try:
        yaml_filename = rocon_python_utils.ros.find_resource_from_string(
            resource_name, extension='interactions')
    except rospkg.ResourceNotFound as e:  # resource not found.
        raise YamlResourceNotFoundException(str(e))
    with open(yaml_filename) as f:
        # load the interactions from yaml into a python object
        interaction_yaml_objects = yaml.load(f)
        # now drop it into message format
        for interaction_yaml_object in interaction_yaml_objects:
            # convert the parameters from a freeform yaml variable to a yaml string suitable for
            # shipping off in ros msgs (where parameters is a string variable)
            if 'parameters' in interaction_yaml_object:  # it's an optional key
                # chomp trailing newlines
                interaction_yaml_object['parameters'] = yaml.dump(
                    interaction_yaml_object['parameters']).rstrip()
            interaction = interaction_msgs.Interaction()
            try:
                genpy.message.fill_message_args(interaction,
                                                interaction_yaml_object)
            except genpy.MessageException as e:
                raise MalformedInteractionsYaml(
                    "malformed yaml preventing converting of yaml to interaction msg type [%s]"
                    % str(e))
            interactions.append(interaction)
    return interactions
Beispiel #4
0
def load_msgs_from_yaml_file(file_path):
    """
      Load interactions from a yaml resource.

      :param str file_path: file path of a yaml formatted interactions file (ext=.interactions).

      :returns: a list of ros msg pairing-interaction specifications
      :rtype: (rocon_interaction_msgs.Pairing[], rocon_interaction_msgs.Interaction [])

      :raises: :exc:`.YamlResourceNotFoundException` if yaml is not found.
      :raises: :exc:`.MalformedInteractionsYaml` if yaml is malformed.

      .. include:: weblinks.rst
    """
    pairings = []
    interactions = []
    try:
        yaml_filename = file_path
        if not os.path.isfile(yaml_filename):
            raise YamlResourceNotFoundException(
                str(yaml_filename) + " NOT FOUND")
    except rospkg.ResourceNotFound as e:  # resource not found.
        raise YamlResourceNotFoundException(str(e))
    with open(yaml_filename) as f:
        # load the interactions from yaml into a python object
        yaml_objects = yaml.load(f)
        try:
            pairing_yaml_objects = yaml_objects['pairings']
            for pairing_yaml_object in pairing_yaml_objects:
                pairing = interaction_msgs.Pairing()
                try:
                    genpy.message.fill_message_args(pairing,
                                                    pairing_yaml_object)
                except genpy.MessageException as e:
                    raise MalformedInteractionsYaml(
                        "malformed yaml preventing converting of yaml to pairing msg [%s]"
                        % str(e))
                pairings.append(pairing)
        except KeyError:
            # probably just interactions in this yaml file - not an error, so just continue
            pass
        try:
            interaction_yaml_objects = yaml_objects['interactions']
            if interaction_yaml_objects is not None:
                # now drop it into message format
                for interaction_yaml_object in interaction_yaml_objects:
                    # convert the parameters from a freeform yaml variable to a yaml string suitable for
                    # shipping off in ros msgs (where parameters is a string variable)
                    if 'parameters' in interaction_yaml_object:  # it's an optional key
                        # chomp trailing newlines
                        interaction_yaml_object['parameters'] = yaml.dump(
                            interaction_yaml_object['parameters']).rstrip()
                    interaction = interaction_msgs.Interaction()
                    try:
                        genpy.message.fill_message_args(
                            interaction, interaction_yaml_object)
                    except genpy.MessageException as e:
                        raise MalformedInteractionsYaml(
                            "malformed yaml preventing converting of yaml to interaction msg [%s]"
                            % str(e))
                    interactions.append(interaction)
        except KeyError:
            # probably just pairings in this yaml file - not an error, so just continue
            pass
    return (pairings, interactions)