pynrp.rosbridge_handler module

An interface to handle rosbridge communication

exception RosBridgeConnectError[source]

Bases: Exception

Type of error risen when there are connection issues

class RosBridgeHandler[source]

Bases: object

Provides a convenient interface to connect to RosBridge and handle properly connection error, disconnections, etc

close()[source]

Closes the RosBridge connection. After this the handler can not be initialized again. Furthermore, it is not recommended to initialized any other client in the same process. Use class RosBridgeHandlerProcess if you need to do that.

initialize(host, port=None)[source]

Initializes the handler if it is not initialized yet and it was not initialized before. Creates a RosBridge client and connects it to the server. Raises RosBridgeConnectError in case of connection errors.

Parameters
  • host – string representing the ip of the RosBridge server

  • port – (optional) integer corresponding to the RosBridge server port. None by default.

property is_init

Returns True if the handler has been initialized

subscribe_topic(name, ros_type, callback)[source]

Subscribes a callback to a Ros topic

Parameters
  • name – string corresponding to the topic address

  • ros_type – string corresponding to the topic type

  • callback – function object to be called upon new message

unsubscribe_topic(name)[source]

Unsubscribes a callback to a Ros topic

Parameters

name – string corresponding to the topic address

class RosBridgeHandlerProcess[source]

Bases: pynrp.rosbridge_handler.RosBridgeHandler

Extension of RosBridgeHandler that runs the RosBridge client in a separate process. This is convenient when starting more than one client from the same process is required. RosBridgeHandler can give problems in this case due to limitations in roslibpy / twisted for handling re-connections and multiple connections.

close()[source]

Closes the RosBridge connection. After this the handler can not be initialized again. Furthermore, it is not recommended to initialized any other client in the same process. Use class RosBridgeHandlerProcess if you need to do that.

initialize(host, port=None)[source]

Initializes the handler if it is not initialized yet and it was not initialized before. Creates a RosBridge client and connects it to the server. Raises RosBridgeConnectError in case of connection errors.

Parameters
  • host – string representing the ip of the RosBridge server

  • port – (optional) integer corresponding to the RosBridge server port. None by default.

subscribe_topic(name, ros_type, callback)[source]

Subscribes a callback to a Ros topic

Parameters
  • name – string corresponding to the topic address

  • ros_type – string corresponding to the topic type

  • callback – function object to be called upon new message

unsubscribe_topic(name)[source]

Unsubscribes a callback to a Ros topic

Parameters

name – string corresponding to the topic address