From 2786dbf36036001813eeab26ff17574ea0e6e70e Mon Sep 17 00:00:00 2001 From: Christoph Froehlich Date: Tue, 16 Apr 2024 09:55:08 +0000 Subject: [PATCH] Copy info over from wiki.ros.org --- doc/index.rst | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/doc/index.rst b/doc/index.rst index 58007d08..d0ac70bc 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -5,6 +5,47 @@ Contains a set of tools that can be used from a hard realtime thread, without br For more information of the ros2_control framework see `control.ros.org `__. +Realtime Publisher +------------------ +The ``realtime_tools::RealtimePublisher`` allows users that write C++ ros2_controllers to publish messages on a ROS topic from a hard realtime loop. The normal ROS publisher is not realtime safe, and should not be used from within the update loop of a realtime controller. The realtime publisher is a wrapper around the ROS publisher; the wrapper creates an extra non-realtime thread that publishes messages on a ROS topic. The example below shows a typical usage of the realtime publisher in the ``on_configure()`` and ``update()`` methods of a realtime controller: + +.. code-block:: cpp + + #include + + class MyController : public controller_interface::ControllerInterface + { + ... + private: + std::shared_ptr> state_publisher_; + std::shared_ptr> s_publisher_; + } + + controller_interface::CallbackReturn MyController::on_configure( + const rclcpp_lifecycle::State & /*previous_state*/) + { + ... + s_publisher_ = get_node()->create_publisher( + "~/status", rclcpp::SystemDefaultsQoS()); + state_publisher_ = + std::make_unique>(s_publisher_); + ... + } + + controller_interface::return_type MyController::update( + const rclcpp::Time & /*time*/, const rclcpp::Duration & /*period*/) + { + ... + // Publish controller state + state_publisher_->lock(); + state_publisher_->msg_ = some_msg; + state_publisher_->unlockAndPublish(); + } + + +API documentation +------------------ + .. toctree:: :maxdepth: 2