NodeHandler in multiple threads
In my case, I'm having multiple threads to subscribe to different topics. I'm not able to receive the data from any. I'm assuming its because I'm using the same node handler for all threads. But I did read and learn that each node can have only one handler, can I get some clarification on this ?
I am using boost threads. A code snippet explaining would be of great help as well.
Edit: Thank you. I had followed this link. Below is my code snippet.
void chatterCallback(const std_msgs::String::ConstPtr& msg)
{
ROS_INFO("I heard: [%s]", msg->data.c_str());
}
void thread1(ros::NodeHandle &n)
{
ros::Subscriber sub1 = n.subscribe("msg1", 1000, chatterCallback);
}
void thread2(ros::NodeHandle &n)
{
ros::Subscriber sub2 = n.subscribe("msg2", 1000, chatterCallback);
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "example");
ros::NodeHandle n;
boost::thread get_speedData_thread(&thread1, n);
boost::thread get_encoderData_thread(&thread2, n);
ros::MultiThreadedSpinner spinner(2);
spinner.spin();
get_speedData_thread.join();
get_encoderData_thread.join();
return 0;
}
I'm publishing msg1 and msg2 from other nodes. And I'm using Multithreaded spinner. My callback function is just a display function. Can anyone tell me where is the error. Message is not getting displayed.
Thanks in advance.