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

ROS2: Remap node name in launch file without affecting other nodes that are part of the process

asked 2022-03-24 18:22:32 -0600

ros_locks gravatar image

I have a package named foo with a python executable named foo.py that looks like this

import rclpy
from rclpy.node import Node
from rclpy.executors import MultiThreadedExecutor

def main(args=None):
    rclpy.init(args=args)
    ham = Node('ham')
    executor = MultiThreadedExecutor(num_threads=2)
    executor.add_node(ham)
    executor.add_node(ham.spam) # ham.spam is another Node that is initialized in ham
    try:
        while rclpy.ok():
            executor.spin_once()
    finally:
        executor.shutdown()
        ham.destroy_node()
    rclpy.spin(node)
    rclpy.shutdown()

if __name__ == '__main__':
    main()

My foo_launch.py looks like the snippet below

from launch import LaunchDescription
from launch_ros.actions import Node

new_name = 'hamper'

def generate_launch_description():
    return launchDescription([
           Node(
                    package='foo',
                    executable='foo',
                    name=new_name,
                    output='screen'
           )
      ])

I would like to change the name of only the ham Node without changing the name of ham.spam node as well. When I build the code below and execute ros2 node list, I get a list of two nodes both named /hamper.

Any ideas how to remap the name of one node without affecting other nodes in the same process?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-03-24 19:09:35 -0600

ros_locks gravatar image

I solved it. Had to specify use_global_arguments=False in the instantiation of ham.spam Node.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2022-03-24 13:27:19 -0600

Seen: 719 times

Last updated: Mar 24 '22