Package rospy :: Module topics :: Class Subscriber

Class Subscriber

source code

object --+    
         |    
     Topic --+
             |
            Subscriber

Class for registering as a subscriber to a specified topic, where the messages are of a given type.

Instance Methods
 
__init__(self, name, data_class, callback=None, callback_args=None, queue_size=None, buff_size=65536, tcp_nodelay=False)
Constructor.
source code
 
unregister(self)
unpublish/unsubscribe from topic.
source code
int
get_num_connections(self)
get the number of connections to other ROS nodes for this topic. (Inherited from rospy.topics.Topic)
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties

Inherited from object: __class__

Method Details

__init__(self, name, data_class, callback=None, callback_args=None, queue_size=None, buff_size=65536, tcp_nodelay=False)
(Constructor)

source code 

Constructor.

NOTE: for the queue_size and buff_size parameters, rospy does not attempt to do intelligent merging between multiple Subscriber instances for the same topic. As they share the same underlying transport, multiple Subscribers to the same topic can conflict with one another if they set these parameters differently.

Parameters:
  • name (str) - graph resource name of topic, e.g. 'laser'.
  • data_class (Message class) - data type class to use for messages, e.g. std_msgs.msg.String
  • callback (fn(msg, cb_args)) - function to call ( fn(data)) when data is received. If callback_args is set, the function must accept the callback_args as a second argument, i.e. fn(data, callback_args). NOTE: Additional callbacks can be added using add_callback().
  • callback_args (any) - additional arguments to pass to the callback. This is useful when you wish to reuse the same callback for multiple subscriptions.
  • queue_size (int) - maximum number of messages to receive at a time. This will generally be 1 or None (infinite, default). buff_size should be increased if this parameter is set as incoming data still needs to sit in the incoming buffer before being discarded. Setting queue_size buff_size to a non-default value affects all subscribers to this topic in this process.
  • buff_size (int) - incoming message buffer size in bytes. If queue_size is set, this should be set to a number greater than the queue_size times the average message size. Setting buff_size to a non-default value affects all subscribers to this topic in this process.
  • tcp_nodelay (bool) - if True, request TCP_NODELAY from publisher. Use of this option is not generally recommended in most cases as it is better to rely on timestamps in message data. Setting tcp_nodelay to True enables TCP_NODELAY for all subscribers in the same python process.
Raises:
Overrides: object.__init__

unregister(self)

source code 

unpublish/unsubscribe from topic. Topic instance is no longer valid after this call. Additional calls to unregister() have no effect.

Overrides: Topic.unregister