Robotics StackExchange | Archived questions

How to disconnect (nh) on arduino

I've used while (nh.connected()) so my arduino car starts when ROSMASTER is running .

My problem is that i can't disconnect nodeHandle when i close the ROSMASTER , which is importan for my task . Any suggestions ???

Asked by Kostas Tzias on 2022-10-07 10:45:27 UTC

Comments

Make sure to call spinOnce inside the while loop. Please see an example below:

// wait until you are actually connected
while (!nh.connected() ){
    nh.spinOnce();
}

Note that the above snippet is for waiting before publishing or doing ROS-related task. This is why ! operator is used. However, in your case, it is not required. The spinOnce call should be enough.

Asked by ravijoshi on 2022-10-07 22:41:03 UTC

Answers

So guys for those who still wondering i solved it with the addition of this code :

while(nh.connected()){
        // run your code routine
   }
  while(!(nh.connected())){
      spinOnce();
     //i am using spinOnce  so i can automatically reconnect when the ROSMASTER is running
     // Then i kill the actions of motors sensors etc.   
    }

Asked by Kostas Tzias on 2022-10-29 13:37:34 UTC

Comments