0
$\begingroup$

Rosanswers logo

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.


Originally posted by End-Effector on ROS Answers with karma: 162 on 2015-03-23

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by BennyRe with karma: 2949 on 2015-03-23

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by End-Effector on 2015-03-23:
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.

Comment by BennyRe on 2015-03-23:
Just declare a variable outside a function or a class. But using global variables is not a good coding style.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.