Provides a simple Python interface for interacting with the capability server.
Typical usage:
>>> from capabilities.client import Client
>>> client = Client()
>>> # Use the line below if the capability_server has a different name
>>> # client = Client(capability_server_node_name='/capability_server_node_name')
>>> if not client.wait_for_services(3.0): # Wait upto 3.0 seconds for the required ROS services
... import sys
... sys.exit("capability_server, called '{0}', failed to come up.".format(client._name))
>>> client.use_capability('foo_pkg/Foo')
>>> client.use_capability('foo_pkg/Foo')
>>> client.free_capability('foo_pkg/Foo')
>>> client.shutdown()
Single point of entry for interacting with a remote capability server.
Instantiation of this class does not check to see if the underlying services are available, call wait_for_services() if you want to ensure that the services are available before continuing.
Parameters: | capability_server_node_name (str) – name of the remote capability server |
---|
Establishes a bond using the ~establish_bond service call
The bond id which is returned by the service call is stored internally and used implicitly by the use/free capabilities functions.
If establish_bond() had previously been called, then the old bond will be broken, which will result in any capability uses under that bond to be implicitly freed.
This function is called implicitly by use_capability() if no bond exists.
This function will block waiting for the service call to become available and to wait for the bond to be established. In both cases the timeout parameter is used.
None is returned if the timeout occurs while waiting on the service to become available or while waiting for the bond to form.
Parameters: | timeout (float) – time in seconds to wait for the service to be available |
---|---|
Returns: | the bond_id received from the server or None on failure |
Return type: | str |
Free’s a previously used capability.
Calls the ~free_capability service, which effectively decrements the internal reference count for that capability in the remote capability server.
If that results in a reference count of zero, then the capability server will shutdown that capability automatically.
Parameters: | |
---|---|
Returns: | |
Return type: | |
Raises : | CapabilityNotInUseException if the capability has not been previously used |
Raises : | CapabilityNotRunningException if the capability has already been stopped which can be caused by a capability it depends on stopping |
Raises : | ServiceNotAvailableException if the required service is not available after the timeout has expired |
Declares that this capability is being used.
Calls the ~use_capability service, and opens a bond with capability server if none exists. This will cause the capability to be started, if it has not been already, and the internal reference count for that capability in the capability server is incremented.
If the bond fails (i.e. this program crashes) then the reference is decremented automatically. The reference is also decremented if free_capability() is called.
Parameters: | |
---|---|
Returns: | |
Return type: | |
Raises : | ServiceNotAvailableException if the required service is not available after the timeout has expired |
Raise : | CannotEstablishBondException is the bond with the capability_server cannot be established |
Blocks until the requested services are available.
Services are waited on one at a time. Therefore, if a non-None value for timeout is given, and one or more services are being waited on, the full timeout will be given to each wait, meaning that the total run time of this function can exceed the timeout provided.
Parameters: | |
---|---|
Returns: | True is the services are available, False otherwise (timeout) |
Return type: |