Exemplo n.º 1
0
    def __init__(self):
        '''
        Retrieve the specifications for the available interfaces and providers from the capability server

        @raise IOError: Exception is raised when retrieving the capability data from the capability server returned
                        errors or when waiting for the capability server's service times out.
        '''
        try:
            rospy.wait_for_service('capability_server/start_capability', 1.0)
        except rospy.ROSException as exc:
            raise IOError(
                "Couldn't get specification index. Service timeout: " +
                str(exc))

        self._spec_index, errors = service_discovery.spec_index_from_service(
            "capability_server")
        if errors:
            raise IOError("Couldn't get specification index. Error: " +
                          str(errors))

        self._available_interfaces = []
        self._available_semantic_interfaces = []
        self._providers = dict()
        for interface in self._spec_index.interfaces:
            if self._spec_index.specs[interface].default_provider:
                self._available_interfaces.append(interface)
                self._providers[interface] = self._spec_index.specs[
                    self._spec_index.specs[interface].default_provider]
        for interface in self._spec_index.semantic_interfaces:
            if self._spec_index.specs[interface].default_provider:
                self._available_semantic_interfaces.append(interface)
                self._providers[interface] = self._spec_index.specs[
                    self._spec_index.specs[interface].default_provider]
Exemplo n.º 2
0
    def __init__(self):
        '''
        Sets up a client for the capability server, including a bond.
        Also, retrieves the specifications for the available interfaces and providers from the capability server

        :raises NotFoundException: Exception is raised when retrieving the capability data
                                   from the capability server returned errors
                                   or when waiting for the capability server's services times out
                                   or when failing to retrieve the capability server's nodelet manager name
        '''

        self._default_timeout = 3.0
        capability_server_name = rospy.get_param("~capability_server_name", "capability_server")

        # look for fully resolved name of the capability server
        self._cap_server_name = str()
        try:
            self._cap_server_name = rocon_python_comms.find_node(capability_server_name, unique=True)[0]
        except rocon_python_comms.NotFoundException as e:
            raise NotFoundException("Couldn't find capability server node. Error: " + str(e))

        # set up client
        self._caps_client = client.CapabilitiesClient(self._cap_server_name)
        if not self._caps_client.wait_for_services(self._default_timeout):
            raise NotFoundException("Timed out when waiting for the capability server (" + self._cap_server_name + ").")
        # establish_bond
        self._caps_client.establish_bond(self._default_timeout)

        # get the name of the capability server's nodelet manager
        service_name = self._cap_server_name + '/get_nodelet_manager_name'
        cap_server_nodelet_manager_srv = rospy.ServiceProxy(service_name, capabilities_srvs.GetNodeletManagerName)
        try:
            resp = cap_server_nodelet_manager_srv()
        except rospy.ServiceException as exc:
            raise NotFoundException("Couldn't not get capability server's nodelet manager name: " + str(exc))
        self.nodelet_manager_name = resp.nodelet_manager_name

        # get spec index
        try:
            self._spec_index, errors = service_discovery.spec_index_from_service(self._cap_server_name,
                                                                                 self._default_timeout)
        except rospy.exceptions.ROSException as e:
            raise NotFoundException("Couldn't get specification index. Error: " + str(e))

        if errors:
            raise NotFoundException("Couldn't get specification index. Error: " + str(errors))

        self._available_interfaces = []
        self._available_semantic_interfaces = []
        self._providers = dict()
        for interface in self._spec_index.interfaces:
            if self._spec_index.specs[interface].default_provider:
                self._available_interfaces.append(interface)
                self._providers[interface] = self._spec_index.specs[self._spec_index.specs[interface].default_provider]
        for interface in self._spec_index.semantic_interfaces:
            if self._spec_index.specs[interface].default_provider:
                self._available_semantic_interfaces.append(interface)
                self._providers[interface] = self._spec_index.specs[self._spec_index.specs[interface].default_provider]
Exemplo n.º 3
0
 def test_service_discovery(self):
     # get spec index via a service call (This tests the handling in the server)
     si, errors = spec_index_from_service()
     assert not errors
     assert 'minimal_pkg/Minimal' in si.interfaces
     resp = call_service('/capability_server/get_capability_spec', 'minimal_pkg/Minimal')
     assert resp.capability_spec.package == 'minimal_pkg', resp.capability_spec.package
     assert 'name: Minimal' in resp.capability_spec.content, resp.capability_spec.content
     with assert_raises(ServiceException):
         resp = call_service('/capability_server/get_capability_spec', 'minimal_pkg/DoesNotExist')
Exemplo n.º 4
0
 def test_service_discovery(self):
     # get spec index via a service call (This tests the handling in the server)
     si, errors = spec_index_from_service()
     assert not errors
     assert 'minimal_pkg/Minimal' in si.interfaces
     resp = call_service('/capability_server/get_capability_spec',
                         'minimal_pkg/Minimal')
     assert resp.capability_spec.package == 'minimal_pkg', resp.capability_spec.package
     assert 'name: Minimal' in resp.capability_spec.content, resp.capability_spec.content
     with assert_raises(ServiceException):
         resp = call_service('/capability_server/get_capability_spec',
                             'minimal_pkg/DoesNotExist')
Exemplo n.º 5
0
def generate_dotcode_from_capability_info():
    spec_index, errors = spec_index_from_service()
    assert not errors
    dotcode_factory = PydotFactory()
    dotgraph = dotcode_factory.get_graph(rankdir="BT")
    for name in spec_index.interfaces:
        dotcode_factory.add_node_to_graph(dotgraph, nodename=str(name), shape="box")
    for name in spec_index.semantic_interfaces:
        dotcode_factory.add_node_to_graph(dotgraph, nodename=str(name), shape="box")
    for name, provider in spec_index.providers.items():
        dotcode_factory.add_node_to_graph(dotgraph, nodename=str(name), shape="ellipse")
        dotcode_factory.add_edge_to_graph(dotgraph, str(name), str(provider.implements), label="provides")
        for dep in provider.dependencies:
            dotcode_factory.add_edge_to_graph(dotgraph, str(name), str(dep), label="requires")
    return dotcode_factory.create_dot(dotgraph)
 def test_spec_index_from_service(self):
     si, errors = spec_index_from_service()
     assert not errors
     assert 'minimal_pkg/Minimal' in si.interfaces
     assert 'minimal_pkg/SpecificMinimal' in si.semantic_interfaces
     assert 'minimal_pkg/SlowToDie' not in si.interfaces
 def test_spec_index_from_service(self):
     si, errors = spec_index_from_service()
     assert not errors
     assert "minimal_pkg/Minimal" in si.interfaces
Exemplo n.º 8
0
 def __get_specs(self):
     self.__spec_index, errors = spec_index_from_service()
     assert not errors
 def __get_specs(self):
     self.__spec_index, errors = spec_index_from_service()
     assert not errors
 def test_spec_index_from_service(self):
     si, errors = spec_index_from_service()
     assert not errors
     assert 'minimal_pkg/Minimal' in si.interfaces
Exemplo n.º 11
0
 def test_spec_index_from_service(self):
     si, errors = spec_index_from_service()
     assert not errors
     assert 'minimal_pkg/Minimal' in si.interfaces
     assert 'minimal_pkg/SpecificMinimal' in si.semantic_interfaces
     assert 'minimal_pkg/SlowToDie' not in si.interfaces