Robotics StackExchange | Archived questions

how to deal with two topics' messages we subscribed in a code in ros ?

I created a node in a code,it subscribes two different topics,how can i do?For example,i want to subscribe the robot's pose and local map to make path planning,this two topics publish different frequencies,how can i do in a code?

ros::Subscriber getodomdata = local_planner_handle_getdata_.subscribe("vehiclePose",1000,getodomdatacallback);


ros::Subscriber getmapdata = local_planner_handle_getdata_.subscribe("local_map", 1000, OccupancyGridCallback);

How can i do the two callback functions? Thanks a lot

Asked by aids293 on 2016-02-20 03:58:07 UTC

Comments

Your code looks ok, but you also show only a very small part of it. What happens?

Asked by NEngelhard on 2016-02-20 05:40:06 UTC

yes,thank you,i just want to ask how to handle these two topics' messages because they are published in different frequencies,thank you

Asked by aids293 on 2016-02-20 06:23:19 UTC

Answers

I'm not entirely sure what your question is. You should have declared two functions 'getodomdatacallback' and 'OccupancyGridCallback' with the right message type parameter.

The subscriber code you've shown above will correctly set these up to receive the messages when they arrive. The final piece of code you'll need is a ros::spin(); line to get the ros node to continually check for messages and call your message handler functions when they arrive.

You can then put whatever code you need in each of the message handler functions.

Hope this helps? If not if you can paste your whole code we can have bit more of a look at it.

Asked by PeteBlackerThe3rd on 2016-02-20 13:22:21 UTC

Comments

thank you a lot,i just need combine the message of topic "vehiclePose" with the message of topic "local_map".But as you know,this two topics publish in different frequencies,how should i handle this,by the messages' time stamp?thank you.

Asked by aids293 on 2016-02-20 22:12:34 UTC

What you need is a message synchronizer: http://wiki.ros.org/message_filters/ApproximateTime (http://wiki.ros.org/message_filters Point 4.2)

You can give your two subscribers to the synchronizer and you will have a callback function that contains both messages.

Asked by NEngelhard on 2016-02-21 06:22:10 UTC

Comments

thanks a lot .that's a good solution.But when i catkin_make my package,boost may be occur error just like /usr/include/boost/tuple/detail/tuple_basic.hpp:227:28: error: ‘impl’ in ‘struct boost::tuples::detail::drop_front<100>’ does not name a type apply > impl; what happen?Thanks

Asked by aids293 on 2016-02-21 20:15:01 UTC

It's a tiny bit easier to debug the code if you show the code...

Asked by NEngelhard on 2016-02-22 02:38:49 UTC