From d04df4625ef31b2342078500ff1910ee386c517e Mon Sep 17 00:00:00 2001 From: Devon Friend <69879126+DFriend01@users.noreply.github.com> Date: Sat, 29 Jul 2023 18:23:48 -0700 Subject: [PATCH] Change launch file to follow new convention (#31) --- launch/example.py | 13 -------- launch/main_launch.py | 75 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 13 deletions(-) delete mode 100644 launch/example.py create mode 100644 launch/main_launch.py diff --git a/launch/example.py b/launch/example.py deleted file mode 100644 index c43889b..0000000 --- a/launch/example.py +++ /dev/null @@ -1,13 +0,0 @@ -from launch import LaunchDescription -from launch_ros.actions import Node - - -def generate_launch_description(): - return LaunchDescription([ - Node( - package='network_systems', - node_namespace='example', - node_executable='example', - node_name='cached_fib' - ) - ]) diff --git a/launch/main_launch.py b/launch/main_launch.py new file mode 100644 index 0000000..fc4a3db --- /dev/null +++ b/launch/main_launch.py @@ -0,0 +1,75 @@ +import importlib +import os +from types import ModuleType +from typing import List + +from launch_ros.actions import Node + +from launch import LaunchDescription +from launch.substitutions import LaunchConfiguration + + +def get_global_main_launch_module() -> ModuleType: + """Execute and return the main launch file of the `global_launch` package. + + Returns: + ModuleType: The executed module. + """ + global_main_launch = os.path.join( + os.getenv("ROS_WORKSPACE"), "src", "global_launch", "main_launch.py" + ) + spec = importlib.util.spec_from_file_location("global_launch", global_main_launch) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +GLOBAL_LAUNCH = get_global_main_launch_module() + + +def generate_launch_description() -> LaunchDescription: + """Generate the launch description for the `local_pathfinding` package. + + Returns: + LaunchDescription: The launch description. + """ + # get_nodes() arguments for the package launch + common_parameters = [GLOBAL_LAUNCH.GLOBAL_CONFIG] + common_ros_arguments = [*GLOBAL_LAUNCH.get_log_ros_arguments()] + mode = LaunchConfiguration("mode") + + return LaunchDescription( + [ + *GLOBAL_LAUNCH.GLOBAL_LAUNCH_ARGUMENTS, + *get_nodes(common_parameters, common_ros_arguments, mode), + ] + ) + + +def get_nodes(common_parameters: List, common_ros_arguments: List, mode: str) -> List[Node]: + """Get the nodes to be launched depending on an indicated mode. + + Args: + common_parameters (List): Parameters that are common to all nodes. + common_ros_arguments (List): ROS arguments that are common to all nodes. + mode (str): The system mode. + + Returns: + List[Node]: The nodes to be launched. + """ + # cached_fib parameters and ROS arguments + cached_fib_parameters = [*common_parameters] + cached_fib_ros_arguments = [*common_ros_arguments] + + nodes = [ + Node( + package="network_systems", + namespace="example", + executable="example", + name="cached_fib", + parameters=cached_fib_parameters, + ros_arguments=cached_fib_ros_arguments, + ), + ] + + return nodes