rosbridge_library.internal.subscribers module

class rosbridge_library.internal.subscribers.MultiSubscriber(topic, client_id, callback, node_handle, msg_type=None, raw=False)

Bases: object

Handles multiple clients for a single subscriber.

Converts msgs to JSON before handing them to callbacks. Due to subscriber callbacks being called in separate threads, must lock whenever modifying or accessing the subscribed clients.

callback(msg, callbacks=None)

Handle incoming messages on the rclpy subscription.

Passes the message to registered subscriber callbacks.

Parameters:
  • msg – The ROS message coming from the subscriber

  • callbacks – Subscriber callbacks to invoke

has_subscribers()

Return true if there are subscribers.

subscribe(client_id, callback)

Subscribe the specified client to this subscriber.

Parameters:
  • client_id – The ID of the client subscribing

  • callback – This client’s callback, that will be called for incoming messages

unregister()
unsubscribe(client_id)

Unsubscribe the specified client from this subscriber.

Parameters:

client_id – The ID of the client to unsubscribe

verify_type(msg_type)

Verify that the subscriber subscribes to messages of this type.

Parameters:

msg_type – The type to check this subscriber 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.subscribers.SubscriberManager

Bases: object

Keeps track of client subscriptions.

subscribe(client_id, topic, callback, node_handle, msg_type=None, raw=False)

Subscribe to a topic.

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

  • topic – The name of the topic to subscribe to

  • callback – The callback to call for incoming messages on the topic

  • msg_type – (optional) The type of the topic

unsubscribe(client_id, topic)

Unsubscribe from a topic.

Parameters:
  • client_id – The ID of the client to unsubscribe

  • topic – The topic to unsubscribe from