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
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
Make sure to call
spinOnce
inside thewhile
loop. Please see an example below: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. ThespinOnce
call should be enough.Asked by ravijoshi on 2022-10-07 22:41:03 UTC