I'm trying to figure out how to use realtime_tools (mainly realtime_publisher&realtime_buffer), but there are to few information about it. I can only find this:

#include <realtime_tools/realtime_publisher.h>

bool MyController::init(pr2_mechanism_model::RobotState *robot,
                        ros::NodeHandle &n)
  realtime_pub = new 
    realtime_tools::RealtimePublisher<mgs_type>(n, "topic", 4);
  return true;

void MyController::update()
  if (realtime_pub->trylock()){
    realtime_pub->msg_.a_field = "hallo";
    realtime_pub->msg_.header.stamp = ros::Time::now();

Hope someone can give me more detailed help.

Thanks a lot.

  • $\begingroup$ Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. $\endgroup$
    – Community Bot
    Oct 22, 2023 at 12:03

1 Answer 1


Welcome at RSE.

ros-control is based on a realtime-loop (update methods of the controllers and read/write methods of the hardware components, sharing data with a shared-memory layer). realtime_tools provide mechanisms to use non-realtime-safe code in this loop: E.g., publishers, or buffers exchanging data between the realtime-loop and subscriber callbacks.

It seems that you are working with ROS 1. Both, the buffer and publisher are used in several places of the ros_controllers, or in a simpler form in the control_toolbox's PID implementation

  • $\begingroup$ Thanks for the link. I kinda figure out how to use it. what i'm curious about now is why we use it. $\endgroup$
    – joe qiu
    Oct 23, 2023 at 2:11
  • $\begingroup$ I updated the answer, maybe this helps. $\endgroup$ Oct 23, 2023 at 6:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.