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

setNodeName in C++

asked 2012-09-04 15:14:19 -0600

sthunt gravatar image

updated 2012-09-04 15:25:58 -0600


Please pardon me if this is a stupid question. It has been a while since I have used ROS. I have a talker/listener framework setup, but ideally, I would like to have one talker communicate with multiple listeners using the same codebase (by changing the name of the listener node with an argument). When I try to run multiple listeners now, the listener that was active shutdowns because "a new node registered with the same name".

I see here: that it was a similar problem and the answer was to set the name using a node configuration.

I am trying to write this in C++ and I searched through all of my header files, but I do not see that function anywhere. I see that function mentioned in rosjava (

Thank you very much.


edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2012-09-04 22:00:57 -0600

weiin gravatar image

A few ways to do it, one of the better ones is to anonymize the node name as mentioned by Dan in the link you provided. See

You could also hardcode different names for each listener (not good idea since you'll have multiple source code doing essentially the same thing), or remap the node name at runtime. See

edit flag offensive delete link more

answered 2012-09-05 11:37:49 -0600

sthunt gravatar image

It was staring me right in the face. That worked perfectly - thank you very much!

edit flag offensive delete link more



@sthunt Please use the comment feature, not the Answer section for comments. And also please accept the above answer so others know it's solved.

tfoote gravatar image tfoote  ( 2012-09-05 11:51:58 -0600 )edit

Question Tools


Asked: 2012-09-04 15:14:19 -0600

Seen: 151 times

Last updated: Sep 05 '12