[ros-users] callback function on one topic with different message types

Ugo Cupcic ugo at shadowrobot.com
Tue Mar 23 10:30:42 UTC 2010


Hi all,

I was wondering how I can achieve to have different callback functions 
on the same topic depending on the message types.

Here is a small code that's not working :

//msg type 1
void myCallback(const shadowhand::msg1ConstPtr& msg)
{
   ROS_INFO("lapin1");
}

// msg type 2
void myCallback(const shadowhand::msg2ConstPtr& msg)
{
   ROS_INFO("lapin2");
}

int main(int argc, char** argv)
{
   ros::init(argc, argv, "shadowhand_listener");
   ros::NodeHandle n;
   //subscribe to shadowhand_commands topic
   ros::Subscriber chatter_sub = n.subscribe("shadowhand_commands", 
100, 	                                             myCallback);
   ros::spin();
}



When I compile this code, I get the error:
error: no matching function for call to 
‘ros::NodeHandle::subscribe(const char [20], int, <unresolved overloaded 
function type>)’

(If I comment the second callback, then it compiles fine).

What am I doing wrong ?

Cheers,


Ugo

-- 
Ugo Cupcic         |  Shadow Robot Company | ugo at shadowrobot.com
Software Engineer      251 Liverpool Road
need a Hand?           London  N1 1LX       | +44 20 7700 2487
http://www.shadowrobot.com/hand/              @shadowrobot




More information about the ros-users mailing list