Multiple subscriptions via subscriber pool
I had a look at the overview of subscribing but nothing is mentioned about short cutting via having a subscriber pool. Then initialize the subscribers inside one for-loop
, which makes the code for multiple subscriptions shorter.
So instead of the conventional way:
ros::NodeHandle nh_;
ros::Subscriber sub_acc = nh_.subscribe(strings[1], 300, callbFloat64);
ros::Subscriber sub_mag = nh_.subscribe(strings[2], 300, callbFloat64);
ros::Subscriber sub_gyro = nh_.subscribe(strings[4], 300, callbFloat64);
ros::Subscriber sub_prox = nh_.subscribe(strings[8], 300, callbFloat64);
I thought of declaring a pool which gets initializied inside one loop. And it does sound good :)