Package roslib :: Module message
[frames] | no frames]

Module message

source code

Support library for Python autogenerated message files. This defines the Message base class used by genmsg_py as well as support libraries for type checking and retrieving message classes by type name.

Classes
  ROSMessageException
Exception type for errors in roslib.message routines
  Message
Base class of Message data classes auto-generated from msg files.
  ServiceDefinition
Base class of Service classes auto-generated from srv files
  DeserializationError
Message deserialization error
  SerializationError
Message serialization error
Functions
Message class
get_message_class(message_type, reload_on_error=False)
Get the message class.
source code
Service class
get_service_class(service_type, reload_on_error=False)
Get the service class.
source code
str
strify_message(val, indent='', time_offset=None, current_time=None, field_filter=None)
Convert value to string representation
source code
 
check_type(field_name, field_type, field_val)
Dynamic type checker that maps ROS .msg types to python types and verifies the python value.
source code
str
get_printable_message_args(msg, buff=None, prefix='')
Get string representation of msg arguments
source code
 
fill_message_args(msg, msg_args, keys={})
Populate message with specified args.
source code
Variables
  struct_I = struct.Struct('<I')
  __package__ = 'roslib'
Function Details

get_message_class(message_type, reload_on_error=False)

source code 

Get the message class. NOTE: this function maintains a local cache of results to improve performance.

Parameters:
  • message_type (str) - type name of message
  • reload_on_error - (optional). Attempt to reload the Python module if unable to load message the first time. Defaults to False. This is necessary if messages are built after the first load.
Returns: Message class
Message class for message/service type
Raises:
  • ValueError - if message_type is invalidly specified

get_service_class(service_type, reload_on_error=False)

source code 

Get the service class. NOTE: this function maintains a local cache of results to improve performance.

Parameters:
  • service_type (str) - type name of service
  • reload_on_error - (optional). Attempt to reload the Python module if unable to load message the first time. Defaults to False. This is necessary if messages are built after the first load.
Returns: Service class
Service class for service type
Raises:
  • Exception - if service_type is invalidly specified

strify_message(val, indent='', time_offset=None, current_time=None, field_filter=None)

source code 

Convert value to string representation

Parameters:
  • val (Value) - to convert to string representation. Most likely a Message.
  • indent (str) - indentation. If indent is set, then the return value will have a leading
  • time_offset (Time) - if not None, time fields will be displayed as deltas from time_offset
  • current_time (Time) - currently not used. Only provided for API compatibility. current_time passes in the current time with respect to the message.
  • field_filter (fn(Message)->iter(str)) - filter the fields that are strified for Messages.
Returns: str
string (YAML) representation of message

check_type(field_name, field_type, field_val)

source code 

Dynamic type checker that maps ROS .msg types to python types and verifies the python value. check_type() is not designed to be fast and is targeted at error diagnosis. This type checker is not designed to run fast and is meant only for error diagnosis.

Parameters:
  • field_name (str) - ROS .msg field name
  • field_type (str) - ROS .msg field type
  • field_val (Any) - field value
Raises:

get_printable_message_args(msg, buff=None, prefix='')

source code 

Get string representation of msg arguments

Parameters:
  • msg (Message) - msg message to fill
  • prefix (str) - field name prefix (for verbose printing)
Returns: str
printable representation of msg args

fill_message_args(msg, msg_args, keys={})

source code 

Populate message with specified args. Args are assumed to be a list of arguments from a command-line YAML parser. See http://www.ros.org/wiki/ROS/YAMLCommandLine for specification on how messages are filled.

fill_message_args also takes in an optional 'keys' dictionary which contain substitute values for message and time types. These values must be of the correct instance type, i.e. a Message, Time, or Duration. In a string key is encountered with these types, the value from the keys dictionary will be used instead. This is mainly used to provide values for the 'now' timestamp.

Parameters:
  • msg (Message) - message to fill
  • msg_args ([args]) - list of arguments to set fields to, or If None, msg_args will be made an empty list.
  • keys (dict) - keys to use as substitute values for messages and timestamps.
Raises: