I am doing some robotic simulations in ROS/Gazebo and wondering what is the best way (programming-wise since I don't have a CS background) to implement a robot's motion controller.

Here are the questions:

  1. Where should I call my Controller function (In a callback? which callback if I have multiple callbacks running simultaneously)?
  2. How to sync data coming from different nodes i.e. callbacks?
  3. What if my sensor nodes are running faster than my controller loop, then how should I implement the controller?
  4. Is there any way to subscribe to different topics with a single callback?
  5. Should I process the data in a callback or process it in the controller function?
  6. What is the exact use of buffers in ROS subscribers?

Sorry for a long list of inquiries but these questions have been bothering me for some time and I would like to make my code more efficient and aesthetically pleasant at the same time if possible.

P.S: I am using C++ in ROS.


1 Answer 1


That is a long list of broad questions. Some of the answers depend heavily on application and personal preference. Assuming you're not using ROS2, then you might consider looking at the ros_control package. Not necessarily to use - just read through their architecture and tutorials for now. It will at least help give you an idea of where to start.

As for the specifics:

  1. In general your control loop should be running at a fixed rate (e.g. 50 Hz), so your control function should be running independently of your sensor callbacks.
  2. It depends, what is your sensor data and where is it coming from? In your control node, you sensor subscribers could just provide your control loop with the most up to date data possible.
  3. This also depends on the application. Obviously if your sensor data is coming in at 10 Hz you probably don't need a 2000 Hz control loop.
  4. Maybe look at the message_filters package. It sounds like it'll answer some of your questions, too.
  5. Depends on your data. But you probably want your controller function to handle combining all of your sensor input and processing it at the controller's loop rate.
  6. Do you mean the queue sizes? It gives flexibility into the timing of processing published messages. For your sensor data your probably only care about the latest available reading, and your callback should probably never fall behind on processing messages from the queue. But say you had a sensor that produce a huge burst of information in a short amount of time, then with a sufficient queue size all of those messages could be published and processed without losing any of the data.

Hope that helps. I think the ros_control stuff might be a good place for you start.

  • $\begingroup$ Thank you @doggie_breath I will check the ros_control package and see where it leads me. $\endgroup$
    – Franky
    Commented Feb 5, 2020 at 1:26

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.