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

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

asked 2016-02-20 02:58:07 -0600

aids293 gravatar image

updated 2016-02-20 03:58:25 -0600

gvdhoorn gravatar image

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

edit retag flag offensive close merge delete

Comments

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

NEngelhard gravatar image NEngelhard  ( 2016-02-20 04:40:06 -0600 )edit

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

aids293 gravatar image aids293  ( 2016-02-20 05:23:19 -0600 )edit

2 Answers

Sort by » oldest newest most voted
0

answered 2016-02-20 12:22:21 -0600

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.

edit flag offensive delete link more

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.

aids293 gravatar image aids293  ( 2016-02-20 21:12:34 -0600 )edit
0

answered 2016-02-21 05:22:10 -0600

NEngelhard gravatar image

What you need is a message synchronizer: http://wiki.ros.org/message_filters/A... ( 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.

edit flag offensive delete link more

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<cons<ht, tt=""> > impl; what happen?Thanks

aids293 gravatar image aids293  ( 2016-02-21 19:15:01 -0600 )edit

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

NEngelhard gravatar image NEngelhard  ( 2016-02-22 01:38:49 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-02-20 02:58:07 -0600

Seen: 420 times

Last updated: Feb 21 '16