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

Subscribe to 2 topics

asked 2019-07-03 05:35:24 -0500

loguna gravatar image

updated 2019-07-03 05:38:28 -0500

Hi,

If lets say i have a program to subscribe both topic A and B. Topic A give me an integer of 5 and B give me an integer of 10. Now i want to add them up to give me 15.

My problem is i do not know how link both values such that they can be added since the values are in their own callback functions.

  • side note: i am using python language. appreciate if someone can write a simple program as reference or guiding me.
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-07-03 05:54:25 -0500

knxa gravatar image

You will probably want to have your callbacks as members of a class. When a callback is called, you will then store the data from the callback as data in the class. This way all methods of the class has access to that data. Please notice that you need to guard data from threading issues since the rospy callbacks can happen concurrently.

Walk through the basic tutorials related to rospy if you have not already. It is time well spent.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2019-07-03 05:35:24 -0500

Seen: 460 times

Last updated: Jul 03 '19