ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version
  1. Using a class is a convenient way of encapsulating the code and of having persistent storage across callback invocations. Generally, subscriptions are set up in the constructor for the class. The callbacks are triggered by incoming messages, so no explicit calls to them have to be made.
  2. ros::spin() gives control over to ROS, and waits until the node shuts down.
  3. Callbacks are one of the main design elements of ROS code. This is the only way to respond to messages coming in on topics.
  4. Yes, although you will need to subscribe to a topic for each of the callbacks you want to be active.