The function IncludeLaunchDescription in ROS Humble run launch file twice!

Required Info:

  • Operating System:
    • Ubuntu Ubuntu 22.04 LTS
    • Ros2 Humble
  • Installation type:
    • binaries
  • Client library (if applicable):
    • IncludeLaunchDescription of launch.actions

Steps to reproduce issue

test.launch.py

import os 

from ament_index_python.packages import get_package_share_directory 

from launch import LaunchDescription

from launch.actions import IncludeLaunchDescription 

from launch.launch_description_sources import PythonLaunchDescriptionSource

def generate_launch_description():
    
    ld = LaunchDescription()

    default_launch_file_path = os.path.join(get_package_share_directory('robot_bringup'), 'launch')

    start_test2_cmd = IncludeLaunchDescription(
        PythonLaunchDescriptionSource(
            os.path.join(default_launch_file_path, 'test2.launch.py')
        )
    )
    ld.add_action(start_test2_cmd)

    return ld

test2.launch.py

import os

from launch import LaunchDescription

def generate_launch_description():
    
    ld = LaunchDescription()

    print("I only need to run once.")

    return ld

Expected behavior

bluebird@bluebird-Jammy:~/Documents/InClassProjects/turtle_bot_ws$ ros2 launch robot_bringup test.launch.py 

[INFO] [launch]: All log files can be found below /home/bluebird/.ros/log/2022-06-17-10-17-38-337096-bluebird-Jammy-22777

[INFO] [launch]: Default logging verbosity is set to INFO


I only need to run once.

Actual behavior

bluebird@bluebird-Jammy:~/Documents/InClassProjects/turtle_bot_ws$ ros2 launch robot_bringup test.launch.py 

[INFO] [launch]: All log files can be found below /home/bluebird/.ros/log/2022-06-17-10-17-38-337096-bluebird-Jammy-22777

[INFO] [launch]: Default logging verbosity is set to INFO

I only need to run once.

I only need to run once.

Hello @bluebird ,

Instead of using a print command, use an ExecuteProcess function, like this:

import os
from launch import LaunchDescription
import launch


def generate_launch_description():

    ld = LaunchDescription()

    print_cmd = launch.actions.ExecuteProcess(
        cmd=['echo', 'I only need to run once.'], output='screen', shell=True)

    ld.add_action(print_cmd)

    return ld

Yes, it only prints one line of the word. It really reassured me.
I was worrying that all the ROS nodes are doubled in the background of the system. I even tried to find these nodes with RQT.

But, why does function Print been executed twice?

This topic was automatically closed after 6 days. New replies are no longer allowed.