The regular ros::spin()
can handle multiple ROS topic subscribers. Just set up four subscribers in your main
function and call ros::spin()
:
ros::Subscriber sub1 = nh.subscribe("topic1", 1, callback1);
ros::Subscriber sub2 = nh.subscribe("topic2", 1, callback2);
ros::Subscriber sub3 = nh.subscribe("topic3", 1, callback3);
ros::Subscriber sub4 = nh.subscribe("topic4", 1, callback4);
ros::spin();
Just make sure your callback functions don't block or take a long time to finish, or your other callbacks won't get scheduled properly.
Originally posted by robustify with karma: 956 on 2019-04-30
This answer was ACCEPTED on the original site
Post score: 0
Original comments
Comment by EdwardNur on 2019-05-01:
@robustify If I have 4 wheels, wouldn't it make my wheels to start async? Meaning that I can get a bit different trajectory because some wheels start considerably quicker than others?
Comment by gvdhoorn on 2019-05-01:
If the callbacks don't take too long (and they shouldn't) there should be at most a few milliseconds between the callbacks. That sort of delay typically "drowns" in delays introduced by motion controllers, velocity ramp-up profiles and general sluggishness due to inertia, etc.