Ask Your Question
0

subscribing to 2 topics

asked 2015-03-23 06:50:13 -0600

End-Effector gravatar image

Hello,

I want to subscribe to 2 topics in one node and then do some kind of calculations and them publish a TF.

The subscribers that I saw in the tutorials only subscribe to a single topic, do calculations and them publish. How can I make them subscribe to more then one?

For example I need to subscribe to the /odom position of my robot and to the /camera. Different topics, them I want to compute the trajectories but for that I need info from odom and camera.

I also don't understand how I store the information that I get from the callback function, can I use some global variable to store some info and them use that in the other callback function? How do you return info from a callback function?

thx so much.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-03-23 06:55:19 -0600

BennyRe gravatar image

You have to create two Subscriber objects, one for '/camera' and one for '/odom'. For both you write an own callback function.

You can't return data from a callback function. In your callback function you can store data to a global variable or to a member variable, which is the preferred way. Then in your main loop process this data.

edit flag offensive delete link more

Comments

Thx man.

By the way how do you define a global variable. I'm trying to define a nav_msgs/Odometry global variable and I just get millions of errors.

End-Effector gravatar imageEnd-Effector ( 2015-03-23 07:31:18 -0600 )edit
1

Just declare a variable outside a function or a class. But using global variables is not a good coding style.

BennyRe gravatar imageBennyRe ( 2015-03-23 08:04:06 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-03-23 06:50:13 -0600

Seen: 947 times

Last updated: Mar 23 '15