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

Nodes with same name in different packages

asked 2017-03-03 16:02:10 -0600

vacky11 gravatar image

Hello,

I am new to ROS and I have a question regarding ROS nodes. Is it possible to create two nodes with same name in different packages?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2017-03-03 23:06:04 -0600

ahendrix gravatar image

updated 2017-03-03 23:06:32 -0600

You can create multiple nodes with the same name in different packages, but there are two things to watch out for if you really want to do this:

  • ROS requires each node to have a unique name at runtime, so you'll need to give each node a different name="" in your launch files, use anonymous names, or use the __name:= parameter to change the node name when starting it from the command line
  • Since a catkin workspace is a single cmake project, each target name needs to be unique across the entire workspace. To get around this, you'll need to use a unique name for each target, and then set the executable name afterwards with set_target_properties:

Package A cmakelists.txt:

add_executable(packageA-node node.cpp)
set_target_properties(packageA-node OUTPUT_NAME node)

Package B cmakelists.txt

add_executable(packageB-node node.cpp)
set_target_properties(packageB-node OUTPUT_NAME node)
edit flag offensive delete link more

Comments

Thanks for answering

vacky11 gravatar image vacky11  ( 2017-03-04 15:55:26 -0600 )edit

It should be set_target_properties(packageB-node PROPERTIES OUTPUT_NAME node) instead of set_target_properties(getpose_grade OUTPUT_NAME getpose)

andrestoga gravatar image andrestoga  ( 2018-03-10 22:35:22 -0600 )edit
1

answered 2018-02-19 06:14:08 -0600

CJuette gravatar image

Just to add to this, since I stumpled upon it today:

AFAIK it is also possible to have multiple nodes with the same name in different packages if you are not building with catkin_make, but instead with catkin_make_isolated or catkin_tools, since with these tools every package has it's own build space. That way you will also not have to apply the workaround @ahendrix suggested.

edit flag offensive delete link more

Comments

Keep in mind that that the workarounds I've suggested apply at both build and runtime. Even if you use catkin_make_isolated or catkin_tools to build binaries with the same name, you'll still have to deal with duplicate node names at runtime.

ahendrix gravatar image ahendrix  ( 2018-02-19 21:46:56 -0600 )edit

Question Tools

3 followers

Stats

Asked: 2017-03-03 16:02:10 -0600

Seen: 2,447 times

Last updated: Feb 19 '18