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

Callback functions are type-specific. If you try to pass an incorrect message type to a callback function, it will error out. Maybe it would help if you included some more information as to what you're trying to accomplish, but as a general rule, you need a separate callback for each message type.

Callback functions are type-specific. If you try to pass an incorrect message type to a callback function, it will error out. Maybe it would help if you included some more information as to what you're trying to accomplish, but as a general rule, you need a separate callback for each message type.

If you wanted to, you could try something like this:

void velocityCallback(const geometry_msgs::Twist::ConstPtr& msg)
{
   genericFunction();
}

void wheelOdomCallback(const nav_msgs::Odometry::ConstPtr& msg)
{
   genericFunction();
}

Callback functions are type-specific. If you try to pass an incorrect message type to a callback function, it will error out. Maybe it would help if you included some more information as to what you're trying to accomplish, but as a general rule, you need a separate callback for each message type.

If you wanted to, you could try something like this:

void velocityCallback(const geometry_msgs::Twist::ConstPtr& msg)
{
   previous_velocity_msg_ = *msg;
   velocity_updated_ = true;

   if(velocity_updated_ && wheel_odom_updated_)
       genericFunction();
}

void wheelOdomCallback(const nav_msgs::Odometry::ConstPtr& msg)
{
   previous_wheel_odom_ = *msg;
   wheel_odom_updated_ = true;

   if(velocity_updated_ && wheel_odom_updated_)
       genericFunction();
}

EDIT: If you need to access data from both message types in a node, you should use class variables to store the previous messages. See the above code. If you stored them as such, genericFunction() could access the value like a global variable.