Karana.KUtils.ros
=================

.. py:module:: Karana.KUtils.ros

.. autoapi-nested-parse::

   Contains classes for interacting with ROS.



Classes
-------

.. autoapisummary::

   Karana.KUtils.ros.EasyPubSub


Package Contents
----------------

.. py:class:: EasyPubSub(name)

   Provides a simplified interface for ros pub/sub.

   It creates a node and runs an executor on a background thread.
   Publishers are lazily created the first time a message is published
   on a topic. Subscriptions simply cache their latest value. The
   method, processSubscriptions, can be called as part of the
   simulation loop to sweep through all subscriptions which have new
   messages and invoke their callbacks.



   .. py:attribute:: queue_size
      :value: 10



   .. py:property:: node
      :type: rclpy.node.Node


      Get the ROS node.

      :returns: The ROS node.
      :rtype: Node


   .. py:property:: executor
      :type: rclpy.executors.MultiThreadedExecutor


      Get the executor.

      :returns: The executor.
      :rtype: MultiThreadedExecutor


   .. py:method:: close()

      Shutdown the executor, node, and rclpy context.



   .. py:method:: publish(topic: str, msg: Any)

      Publish a message.

      Note: all messages on the same topic must have the same type

      :param topic: The name of the topic the message will be published to
      :type topic: str
      :param msg: The ROS message to publish
      :type msg: Any



   .. py:method:: subscribe(topic: str, msg_type, callback: collections.abc.Callable) -> str

      Subscribe to a topic.

      Note: there can be multiple subscriptions to the same topic as
      long as they use a consistent message type.

      :param topic: The name of the topic to subscribe to
      :type topic: str
      :param msg_type: The type of ROS message to subscribe to
      :param callback: The user callback to handle an incoming message. This will
                       be called whenever processSubscriptions is called and a new
                       message has arrived since the last time it was called. If
                       multiple messages have arrived, only the most recent one
                       will be used.
      :type callback: Callable

      :returns: A unique string which identifies this subscription
      :rtype: str



   .. py:method:: unsubscribe(uuid: str)

      Remove an existing subscription.

      :param uuid: A unique id previously returned by subscribe
      :type uuid: str



   .. py:method:: processSubscriptions()

      Invoke callbacks for all subscriptions with new values.



