rosbridge_library.internal.publishers module

class rosbridge_library.internal.publishers.MultiPublisher(topic, node_handle, msg_type=None, latched_client_id=None, queue_size=100)

Bases: object

Keeps track of the clients that are using a particular publisher.

Provides an API to publish messages and register clients that are using this publisher.

has_clients()

Return true if there are clients to this publisher.

publish(msg)

Publish a message using this publisher.

Parameters:

msg – The dict (json) message to publish

Raises:

Exception – Propagates exceptions from message conversion if the provided msg does not properly conform to the message type of this publisher

register_client(client_id)

Register the specified client as a client of this publisher.

Parameters:

client_id – The ID of the client using the publisher

unregister()

Unregister the publisher and clear the clients.

unregister_client(client_id)

Unregister the specified client from this publisher.

If the specified client_id is not a client of this publisher, nothing happens.

Parameters:

client_id – The ID of the client to remove

verify_type(msg_type)

Verify that the publisher publishes messages of the specified type.

Parameters:

msg_type – The type to check this publisher against

Raises:
  • Exception – If ros_loader cannot load the specified msg type

  • TypeConflictException – If the msg_type is different than the type of this publisher

class rosbridge_library.internal.publishers.PublisherManager

Bases: object

The PublisherManager keeps track of ROS publishers.

It maintains a MultiPublisher instance for each registered topic.

When unregistering a client, if there are no more clients for a publisher, then that publisher is unregistered from the ROS Master.

publish(client_id, topic, msg, node_handle, latch=False, queue_size=100)

Publish a message on the given topic.

Tries to create a publisher on the topic if one does not already exist.

Parameters:
  • client_id – The ID of the client making this request

  • topic – The topic to publish the message on

  • msg – A JSON-like dict of fields and values

  • node_handle – Handle to a rclpy node to create the publisher

  • latch – (optional) Whether to make this publisher latched

  • queue_size – (optional) Publisher queue_size to use

Raises:

Exception – A variety of exceptions are propagated. They can be thrown if there is a problem setting up or getting the publisher, or if the provided msg does not map to the msg class of the publisher.

register(client_id, topic, node_handle, msg_type=None, latch=False, queue_size=100)

Register a publisher on the specified topic.

Publishers are shared between clients, so a single MultiPublisher instance is created per topic, even if multiple clients register.

Parameters:
  • client_id – The ID of the client making this request

  • topic – The name of the topic to publish on

  • node_handle – Handle to a rclpy node to create the publisher

  • msg_type – (optional) The type to publish

  • latch – (optional) Whether to make this publisher latched

  • queue_size – (optional) Publisher queue_size to use

Raises:

Exception – exceptions are propagated from the MultiPublisher if there is a problem loading the specified msg class or establishing the publisher

unregister(client_id, topic)

Unregister a client from the publisher for the given topic.

Will wait some time before actually unregistering, it is done in _unregister_impl/

If there are no clients remaining for that publisher, then the publisher is unregistered from the ROS Master.

Parameters:
  • client_id – The ID of the client making this request

  • topic – The topic to unregister the publisher for

unregister_all(client_id)

Unregister a client from all publishers that they are registered to.

Parameters:

client_id – The ID of the client making this request