[ros-users] callback function on one topic with different me…

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Ugo Cupcic
Date:  
To: ros-users
Subject: [ros-users] callback function on one topic with different message types
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 | 
Software Engineer      251 Liverpool Road
need a Hand?           London  N1 1LX       | +44 20 7700 2487
http://www.shadowrobot.com/hand/              @shadowrobot