roslua: ROS client library for Lua

Module roslua.subscriber

Topic subscriber. This module contains the Subscriber class to subscribe to a ROS topic. The class is used to connect to all publishers for a certain topic and receive messages published by and of these.

During spinning the messages are received and registered listeners are called to process the messages.

Copyright© Tim Niemueller, Carnegie Mellon University, Intel Research Pittsburgh

Release: Released under BSD license

Functions

Subscriber:add_listener (listener) Add a listener to this subscriber.
Subscriber:connect () Connect to all available publishers to which no connection has yet been established.
Subscriber:finalize () Finalize instance.
Subscriber:get_stats () Get statistics about this subscriber.
Subscriber:new (topic, type) Constructor.
Subscriber:remove_listener (listener) remove the given listener.
Subscriber:reset_messages () Reset messages.
Subscriber:spin () Spin all connections to subscribers and dispatch incoming messages.
Subscriber:update_publishers (publishers, connect_now) Update the publishers.


Functions

Subscriber:add_listener (listener)
Add a listener to this subscriber.

Parameters

  • listener: A listener is either a function or a class which provides a message_received() method. The function or method is called for any successively received message. Note that your listener blocks all other listeners from receiving any further messages. For lengthy task you might consider storing the message and interleaving processing and node spinning.
Subscriber:connect ()
Connect to all available publishers to which no connection has yet been established.
Subscriber:finalize ()
Finalize instance.
Subscriber:get_stats ()
Get statistics about this subscriber.

Return value:

an array containing the topic name as the first entry, and another array as the second entry. This array contains itself tables with five fields each: the remote caller ID of the connection, the number of bytes received, number of messages received, the drop estimate (always -1) and connection aliveness (always true). Suitable for getBusStats of slave API.
Subscriber:new (topic, type)
Constructor. Create a new subscriber instance.

Parameters

  • topic: topic to subscribe to
  • type: type of the topic
Subscriber:remove_listener (listener)
remove the given listener. The listener will no longer be notified of incoming messages.

Parameters

  • listener: listener to remove
Subscriber:reset_messages ()
Reset messages. You can use this for a latching subscriber to erase the messages at a certain point manually.
Subscriber:spin ()
Spin all connections to subscribers and dispatch incoming messages. Connections which are found dead are removed.
Subscriber:update_publishers (publishers, connect_now)
Update the publishers. This method is called by the slave API handler when the publisherUpdate() XML-RPC method is called. The subscriber instance will connect to any new publishers that it had not connected to before (during the next call to spin() and will (immediately) disconnect from any publishers that are no longer available.

Parameters

  • publishers: an array of currently available and slave URIs that were registered at the core
  • connect_now: if set to true will immediately try to connect to unconnected publishers instead of only marking enqueuing a try for the next spin

Valid XHTML 1.0!