Package rosservice

Package rosservice

source code

Command-line utility for querying ROS services, along with library calls for similar functionality. The main benefit of the rosservice Python library over the rospy ServiceProxy library is that rosservice supports type-introspection on ROS Services. This allows for both introspecting information about services, as well as using this introspection to dynamically call services.

Classes
  ROSServiceException
Base class for rosservice-related exceptions
  ROSServiceIOException
rosservice related to network I/O failure
Functions
dict
get_service_headers(service_name, service_uri)
Utility for connecting to a service and retrieving the TCPROS headers.
source code
 
get_service_type(service_name)
Get the type of the specified service_name.
source code
 
get_service_uri(service_name)
Retrieve ROSRPC URI of service.
source code
str
get_service_node(service_name)
Returns: name of node that implements service, or None
source code
[services]
get_service_list(node=None, namespace=None, include_nodes=False)
Get the list of services
source code
[str]
rosservice_find(service_type)
Lookup services by service_type
source code
ServiceDefinition: service class
get_service_class_by_name(service_name)
Get the service class using the name of the service.
source code
Message, Message
call_service(service_name, service_args, service_class=None)
Call the specified service_name
source code
bool
has_service_args(service_name, service_class=None)
Check if service requires arguments
source code
 
get_service_args(service_name)
Implements 'get service args'
source code
 
rosservicemain(argv=['(imported)'])
main entry point for rosservice command-line tool
source code
Variables
  NAME = 'rosservice'
  __package__ = 'rosservice'
Function Details

get_service_headers(service_name, service_uri)

source code 

Utility for connecting to a service and retrieving the TCPROS headers. Services currently do not declare their type with the master, so instead we probe the service for its headers.

Parameters:
  • service_name (str) - name of service
  • service_uri (str) - ROSRPC URI of service
Returns: dict
map of header fields
Raises:

get_service_type(service_name)

source code 

Get the type of the specified service_name. May print errors to stderr.

:param service_name: name of service, ``str`` :returns: type of service or ``None``, ``str`` :raises: :exc:`ROSServiceIOException` If unable to communicate with service

get_service_uri(service_name)

source code 

Retrieve ROSRPC URI of service.

:param service_name: name of service to lookup, ``str`` :returns: ROSRPC URI for service_name, ``str``

get_service_node(service_name)

source code 
Returns: str
name of node that implements service, or None

get_service_list(node=None, namespace=None, include_nodes=False)

source code 

Get the list of services

Parameters:
  • node (str) - Name of node to get services for or None to return all services
  • namespace (str) - Namespace to scope services to or None
  • include_nodes (bool) - If True, return list will be [service_name, [node]]
Returns: [services]
if include_nodes, services is service_name, [node]. Otherwise, it is just the service_name
Raises:

rosservice_find(service_type)

source code 

Lookup services by service_type

Parameters:
  • service_type (str) - type of service to find
Returns: [str]
list of service names that use service_type

get_service_class_by_name(service_name)

source code 

Get the service class using the name of the service. NOTE: this call results in a probe call to the service.

Parameters:
  • service_name (str) - fully-resolved name of service to call
Returns: ServiceDefinition: service class
service class
Raises:

call_service(service_name, service_args, service_class=None)

source code 

Call the specified service_name

Parameters:
  • service_name (str) - fully-resolved name of service to call
  • service_args ([any]) - args to pass to service
  • service_class (Message class) - (optional) service type class. If this argument is provided, it saves a probe call against the service
Returns: Message, Message
service request, service response
Raises:

has_service_args(service_name, service_class=None)

source code 

Check if service requires arguments

Parameters:
  • service_name (str) - name of service being called
  • service_class (Message class) - (optional) service type class. If this argument is provided, it saves a probe call against the service
Returns: bool
True if service_name has request arguments

get_service_args(service_name)

source code 

Implements 'get service args'

Parameters:
  • service_name (str) - name of service to get arguments for
Raises:

rosservicemain(argv=['(imported)'])

source code 

main entry point for rosservice command-line tool

Parameters:
  • argv ([str]) - command-line args