giskardpy.middleware.ros2.feedback_publisher
============================================

.. py:module:: giskardpy.middleware.ros2.feedback_publisher


Classes
-------

.. autoapisummary::

   giskardpy.middleware.ros2.feedback_publisher.MotionStatechartPayloadKey
   giskardpy.middleware.ros2.feedback_publisher.ActionFeedbackPublisher


Module Contents
---------------

.. py:class:: MotionStatechartPayloadKey

   Bases: :py:obj:`enum.StrEnum`


   The keys of the motion statechart feedback sent to the action client on top of the
   :class:`~cramph.data_types.StatechartPayloadKey`.


   .. py:attribute:: WAITING_FOR_CHILD
      :value: 'waiting_for_child'


      The nodes waiting for the client to choose their child, by index, each with the
      number of children it already holds.



   .. py:attribute:: PUBLISHED_POSITION
      :value: 'published_position'


      The position Giskard's world published its changes up to while the goal ran, which
      the client's world has to contain before the client reads it; left out if the goal
      published nothing.



.. py:class:: ActionFeedbackPublisher

   Reports the state of the running motion statechart to the action client.


   .. py:attribute:: executor
      :type:  cramph.executor.StatechartExecutor

      The executor holding the motion statechart that is reported on.



   .. py:attribute:: action_server
      :type:  giskardpy.middleware.ros2.action_server.ActionServerHandler

      The action server the feedback is sent through.



   .. py:attribute:: outgoing_world_updates
      :type:  giskardpy.middleware.ros2.world_updates.OutgoingWorldUpdates

      Tells which changes of Giskard's world the running goal published.



   .. py:attribute:: child_request_repeat_period
      :type:  float
      :value: 0.1


      Seconds after which the feedback is sent again while a node waits for a child, so
      that a client that could not choose yet is asked again.



   .. py:attribute:: last_history_length
      :type:  int
      :value: -1


      Length of the statechart history at the most recent feedback, used to detect state
      changes.



   .. py:attribute:: sent_node_count
      :type:  int
      :value: 0


      How many nodes of the statechart the feedback sent the structure of so far.



   .. py:method:: publish_structure() -> None

      Send the state of the motion statechart together with its structure.

      Serializing the structure is expensive, so it is sent once while the goal is
      compiled instead of from inside a control cycle.



   .. py:method:: publish_if_changed() -> None

      Send feedback when the state of the motion statechart changed, and every
      :attr:`child_request_repeat_period` while a node waits for a child.



   .. py:method:: publish() -> None

      Send feedback regardless of whether anything changed, with the structure of the
      nodes that joined the statechart since the structure was sent last.



   .. py:method:: create_states() -> dict[str, Any]

      Collect the life cycle, observation and last observation state of the motion
      statechart, the tick they were taken at, the nodes waiting for a child, and how
      far the changes of the goal were published.



   .. py:method:: has_state_changed() -> bool

      Whether the statechart history grew since the last feedback.



   .. py:method:: send(data: dict[str, Any]) -> None

      Publish the given data as action feedback.



