ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How to disconnect (nh) on arduino

asked 2022-10-07 10:45:27 -0500

Kostas Tzias gravatar image

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 ???

edit retag flag offensive close merge delete

Comments

2

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.

ravijoshi gravatar image ravijoshi  ( 2022-10-07 22:41:03 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-10-29 13:37:34 -0500

Kostas Tzias gravatar image

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.   
    }
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2022-10-07 10:45:27 -0500

Seen: 180 times

Last updated: Oct 29 '22