waitForMessage in thread always time-out [closed]

asked 2018-07-12 08:44:09 -0600

anonymous user

Anonymous

I'm implementing a node that is managing multiple controllers for my robot so I want to have the following behavior:

  • the controllerManager node publish on a "control/manager/tick" topic.
  • On reception of this message: the controller1 and controller2 nodes calculate a commands and each publish back to a topic "control/controllerX/command" on which controllerManager is listening.
  • After publishing the tick, controllerManager wait for receiving the commands from both controller1 AND controller2 to continue.

So I used the following implementation:

void controllerManager::someMethod(){
     // some stuff
     ............

     // create threads that will run until a message is published on some topic or time-out
     std::vector(boost::thread) threads;
     for(auto& ctrler : all_ctrlers){         // all_ctrlers contains an object for controller1 and controller2
              std::string controllerTopic = ctrler.getTopic();
              ros::Duration timeOut(1);
              threads.push_back( boost::bind(
                       ros::topic::waitForMessage<MyMsg>,
                       controllerTopic,
                       timeOut));
     }

     // publish the tick to the controllers
     tickPublisher.publish(tickMsg);
     // On reception of this msg, the controllers node will publish a response 

     // wait for all controller to have published their command in response to the tick
     for(auto& thread : threads){
              thread.join()
     }

     // some more stuff
     ......
}

The issue I'm facing here is that ros::topic::waitForMessage always time-out. I did try:

  • to use the different versions of waitForMessage functions with different types of NodeHandle,
  • to replace this function by its implementation to dig a bit deeper,

but no matter what I try, this is always timing out.

Am I missing some important thing with ROS communication and threading?

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by tfoote
close date 2023-01-10 16:16:01.949007