[ros-users] callback function on one topic with different message types
Jeremy Leibs
leibs at willowgarage.com
Tue Mar 23 14:59:46 UTC 2010
http://www.ros.org/wiki/Topics
Ros topics are strongly typed, so in general what you are trying to do
won't work. You must have a separate topic for each type.
The particular error you are seeing is related to the fact that a
subscription call is actually templated and infers the type of the
subscription based on the argument to your callback.
--Jeremy
On Tue, Mar 23, 2010 at 3:30 AM, Ugo Cupcic <ugo at shadowrobot.com> wrote:
> 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
>
> _______________________________________________
> ros-users mailing list
> ros-users at code.ros.org
> https://code.ros.org/mailman/listinfo/ros-users
>
More information about the ros-users
mailing list