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

catkin use msg error: no matching function for call to ros::NodeHandle::subscribe

asked 2014-08-06 04:15:54 -0600

updated 2014-08-06 07:31:58 -0600

Hi, I want to use a msg defined in a rosbuild package in catkin.

I include the .h file of this msg from the rosbuild package directly, and I can create the object successfully. i.e. tld_msgs::BoundingBox newMsg; but when I want to subscribe to a topic that publish this msg I got a compile error

 error: no matching function for call to ‘ros::NodeHandle::subscribe(const char [20], int, int (&)(const BoundingBox&))’

I create the subscriber like this:

ros::Subscriber sub = n.subscribe("/tld_tracked_object", 20, callback);

and the callback function:

int callback(const tld_msgs::BoundingBox &data) { }

Can anyone figure out my mistake?

Thanks

===============================

I copied the msg file into the catkin workspace with the same package name and compiled successfully.

But I got the same error here.

error: no matching function for call to ‘ros::NodeHandle::subscribe(const char [20], int, int (&)(const BoundingBox&))’

I think it should be the problem in my callback function. and I need to modify this:

ros::Subscriber sub = n.subscribe("/tld_tracked_object", 20, callback);

I googled and find I need to modify it like:

ros::Subscriber sub = n.subscribe("/tld_tracked_object", 20, tld_msgs::BoundingBox callback);

but it says error: ‘callback’ is not a member of ‘tld_msgs’

since there is only a msg folder in my tld_msgs folder, I have no idea how to add this in my msg file...

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted
0

answered 2014-08-07 08:12:17 -0600

updated 2014-08-07 08:13:11 -0600

Thanks for everyone's help.

I finally found where the problem is.

It is possible in catakin workspace to use the msg defined in rosbuild package, just include the header file generated by the original msg file is okay.

And the error occurred because I want the function return an int value.

I checked some working package and found I should not do that, the callback function should be a void function.

Then it compiles with no error after I change it to

void callback(const tld_msgs::BoundingBox &data) { }
edit flag offensive delete link more

Comments

1

You can also use `void callback(tld_msgs::BoundingBox::ConstPtr &data) { }` which is a more ROSy way of doing this.

Chrissi gravatar image Chrissi  ( 2014-08-07 08:38:11 -0600 )edit

thanks for the suggestion. I will try to be more ROSy :)

lanyusea gravatar image lanyusea  ( 2014-08-07 08:41:03 -0600 )edit
2

answered 2014-08-06 04:18:53 -0600

ahendrix gravatar image

Depending on rosbuild packages from catkin packages is not possible.

You can either catkinize your message package or use rosbuild for the package you're trying to build.

edit flag offensive delete link more

Comments

hi @ahendrix, I updated my question. Could you help me with the new problem? thanks

lanyusea gravatar image lanyusea  ( 2014-08-06 05:06:51 -0600 )edit
1

I think @Christian Dondrup's answer is correct, you need to drop the `&`. However @ahendrix is also correct that depending on a rosbuild package with catkin is not supported.

William gravatar image William  ( 2014-08-06 15:43:35 -0600 )edit
1

answered 2014-08-06 10:05:34 -0600

Chrissi gravatar image

The compile error should just result from a missing & infront of callback to make it a function pointer.

Try

ros::Subscriber sub = n.subscribe("/tld_tracked_object", 20, &callback);

No garuentee that the whole programme will work afterwards but it should at least compile.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-08-06 04:15:54 -0600

Seen: 11,380 times

Last updated: Aug 07 '14