0
$\begingroup$

Rosanswers logo

I want to use information received from the different nodes in one callback function. I am not sure. For example my callback function

void follow(const geometry_msgs::PoseStamped::ConstPtr& fmsg, const geometry_msgs::PoseStamped::ConstPtr& gmsg ){ #and do something with than info}

Subscribers

ros::Subscriber pos_sub_uav1 = nh_uav1.subscribe<geometry_mgs::PoseStamped>
        ("uav1/mavros/local_position/pose", 10, follow);

ros::Subscriber pos_sub_uav2 = nh_uav2.subscribe<geometry_mgs::PoseStamped>
        ("uav2/mavros/local_position/pose", 10, follow);

One way I think of is to make separate callback functions for each subscriber node and then receive messages from corresponding nodes, store info in some global variable and the use other function for manipulation of those variables or there is a better way to do this.


Originally posted by Nebula on ROS Answers with karma: 98 on 2018-04-20

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

You could do something like this:

ros::Subscriber pos_sub_uav1 = nh.subscribe<geometry_mgs::PoseStamped>("uav1/mavros/local_position/pose", 10, boost::bind(&follow, _1, "uav1"));
ros::Subscriber pos_sub_uav2 = nh.subscribe<geometry_mgs::PoseStamped>("uav2/mavros/local_position/pose", 10, boost::bind(&follow, _1, "uav2"));
...
void follow(const geometry_msgs::PoseStamped::ConstPtr& msg, const std::string &uav) { }

You might also want to just use a time sychronizer.


Originally posted by Tom Moore with karma: 13689 on 2018-04-20

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by Nebula on 2018-04-21:
can I get messages in callback function from both(or many) subscribers simultaneously?

Comment by Tom Moore on 2018-04-21:
If you use the time synchronizer, yes.

$\endgroup$

Your Answer

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