Calling ros::spin from a new Thread
Hi there,
i have a strange problem with ROS. I am trying to subscribe to a ros topic in my application. Since the spin-method blocks the application i just started a new thread and tried to subscribe to the topic within this new thread. Here is my code:
void MatlabDevice::startROSCommunication() {
boost::thread t(&MatlabDevice::startROSThread, this);
}
void MatlabDevice::startROSThread() {
ros::NodeHandle nodeH;
nodeH.subscribe("chatter", 1000, &MatlabDevice::callbackBodyMessage, this);
ros::spin();
}
void MatlabDevice::callbackBodyMessage(const biorob_msgs::BioBipedBody::ConstPtr &msg) {
// Further code here
}
The strange thing is that this worked some time ago. Now i get the following error:
[ERROR] [1352133007.566663012]: SingleThreadedSpinner: You've attempted to call spin from multiple threads. Use a MultiThreadedSpinner instead.
I tried to remove the spin() call and used the MultiThreadedSpinner but this gives me:
[ERROR] [1352133281.107900251]: MultiThreadeSpinner: You've attempted to call ros::spin from multiple threads... but this spinner is already multithreaded.
Can someone tell me whats wrong with my code?
Greetings, Simon.