Is it somehow possible to change the master URI and recall ros init? [closed]
I want to programm a node which is running and trying to find the ros master. It has an external non ROS interface to change the masters address and should if the master address is changed deregister and shutdown all connections, set the new master URI and connect again.
Is that possible somehow?
I tried to run ros::init multiple times with calling putenv("ROS_MASTER_URI=...") before but it does not seem to change the master uri when checking it with ros::master::getURI. Unfortunately this doesn't work. It seems to keep the first master URI.
test++;
std::string hostname="localhost";
std::stringstream ss;
ss<<"ROS_MASTER_URI="<<"http://"<<hostname<<test<<":11311";
putenv(strdup(ss.str().c_str()));
ros::init(argc, argv, "node");
ROS_INFO_STREAM("Master: "<<ros::master::getURI());
if(ros::master::check()) master_up();
->in a while loop always returns Master: http://localhost1:11311
Can I reset the master uri on runtime somehow?