Package rospy :: Module topics :: Class Publisher

Class Publisher

source code

object --+    
         |    
     Topic --+
             |
            Publisher

Class for registering as a publisher of a ROS topic.

Instance Methods
 
__init__(self, name, data_class, subscriber_listener=None, tcp_nodelay=False, latch=False, headers=None, queue_size=None)
Constructor
source code
 
publish(self, *args, **kwds)
Publish message data object to this 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
 
unregister(self)
unpublish/unsubscribe from 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, subscriber_listener=None, tcp_nodelay=False, latch=False, headers=None, queue_size=None)
(Constructor)

source code 

Constructor

Parameters:
  • name (str) - resource name of topic, e.g. 'laser'.
  • data_class (Message class) - message class for serialization
  • subscriber_listener (SubscribeListener) - listener for subscription events. May be None.
  • tcp_nodelay (bool) - If True, sets TCP_NODELAY on publisher's socket (disables Nagle algorithm). This results in lower latency publishing at the cost of efficiency.
  • latch (bool) - If True, the last message published is 'latched', meaning that any future subscribers will be sent that message immediately upon connection.
  • headers (dict) - If not None, a dictionary with additional header key-values being used for future connections.
  • queue_size (int) - The queue size used for asynchronously publishing messages from different threads. A size of zero means an infinite queue, which can be dangerous. When the keyword is not being used or when None is passed all publishing will happen synchronously and a warning message will be printed.
Raises:
Overrides: object.__init__

publish(self, *args, **kwds)

source code 

Publish message data object to this topic. Publish can either be called with the message instance to publish or with the constructor args for a new Message instance, i.e.:

 pub.publish(message_instance)
 pub.publish(message_field_1, message_field_2...)            
 pub.publish(message_field_1='foo', message_field_2='bar')
Parameters:
  • args - Message instance, message arguments, or no args if keyword arguments are used
  • kwds - Message keyword arguments. If kwds are used, args must be unset
Raises: