Robotics StackExchange | Archived questions

ROS2 share launch code

Hi,

I have two packages that share some launch file logic (like how to find proper .urdf file and some set of shared launch files) that I could store in third package that is a myproject_lib package holding shared codebase.

How to ideally share such a code designed for launch files between packages? can I expect that I can import myproject_lib in the launch files? or is there some different way?

Thanks

Asked by veverak on 2021-08-17 09:14:44 UTC

Comments

Answers

It depends on if the launch file of your third package is Python, XML, or YAML. Either way, how to do it is covered here: https://docs.ros.org/en/galactic/Guides/Launch-file-different-formats.html

I'll copy pasta here:

Python:

    # include another launch file
launch_include = IncludeLaunchDescription(
    PythonLaunchDescriptionSource(
        os.path.join(
            get_package_share_directory('demo_nodes_cpp'),
            'launch/topics/talker_listener.launch.py'))
)

XML:

  <!-- include another launch file -->
  <include file="$(find-pkg-share demo_nodes_cpp)/launch/topics/talker_listener.launch.py"/>

YAML:

# include another launch file
- include:
    file: "$(find-pkg-share demo_nodes_cpp)/launch/topics/talker_listener.launch.py"

Asked by Airuno2L on 2021-08-17 09:39:32 UTC

Comments

That is not what I want, this includes another launch file as a "another launchfile" I want to use specific code from shared package in the launch files. Literally import the functions from different module: from mymodule import myfunc;

Asked by veverak on 2021-08-17 14:13:48 UTC