The function IncludeLaunchDescription in ROS Humble run launch file twice!

asked 2022-06-16 21:47:06 -0600

BlueBird gravatar image

updated 2022-06-17 03:34:05 -0600

ljaniec gravatar image

Required Info:

  • Operating System:
    • 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.
edit retag flag offensive close merge delete

Comments

My process reminds me that the following codes seem run only once.

import os from launch import LaunchDescription import launch

test2.launch.py --> ``` 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

```

We have the following results. Results

That is true, but why does the print function run twice?

BlueBird gravatar image BlueBird  ( 2022-06-18 09:01:59 -0600 )edit