Controller algorithm implementation in ROS/Gazebo
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:
- Where should I call my Controller function (In a callback? which callback if I have multiple callbacks running simultaneously)?
- How to sync data coming from different nodes i.e. callbacks? or Is there any way to subscribe to different topics with a single callback?
- What if my sensor nodes are running faster than my controller loop, then how should I implement the controller function?
- Should I process the data in a callback or process it in the controller function?
- 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 Melodic in Ubuntu.