This repository has been archived by the owner on Mar 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update launch file to support global launch file (#32)
* Rename example.py and fixed invalid Node name-value parameters * Add TODO for global config * Rename launch file to main_launch.py * Support global launch file * Overhaul launch file with new global launch file format * Resolve merge conflict... again * Load in global launch arguments rather than store them in file * Add environment variable to color ROS logs * Ignore python binary files * Update global_launch dir path * Create variable for node name * Rework env vars * Move global_launch dir back to src * Remove local enviornment variables --------- Co-authored-by: Patrick Creighton <[email protected]>
- Loading branch information
1 parent
d04df46
commit f4aec56
Showing
2 changed files
with
64 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# autogenerated files | ||
lib/cmn_hdrs/ros_info.h | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,96 @@ | ||
"""Launch file that runs all nodes for the network systems ROS package.""" | ||
|
||
import importlib | ||
import os | ||
from types import ModuleType | ||
from typing import List | ||
|
||
from launch_ros.actions import Node | ||
|
||
from launch import LaunchDescription | ||
from launch import LaunchDescription, LaunchDescriptionEntity | ||
from launch.actions import OpaqueFunction | ||
from launch.launch_context import LaunchContext | ||
from launch.substitutions import LaunchConfiguration | ||
|
||
# Local launch arguments and constants | ||
PACKAGE_NAME = "network_systems" | ||
|
||
# Add args with DeclareLaunchArguments object(s) and utilize in setup_launch() | ||
LOCAL_LAUNCH_ARGUMENTS = [] | ||
|
||
def get_global_main_launch_module() -> ModuleType: | ||
"""Execute and return the main launch file of the `global_launch` package. | ||
|
||
def generate_launch_description() -> LaunchDescription: | ||
"""The launch file entry point. Generates the launch description for the `network_systems` | ||
package. | ||
Returns: | ||
ModuleType: The executed module. | ||
LaunchDescription: The launch description. | ||
""" | ||
global_launch_arguments, global_environment_vars = get_global_launch_arguments() | ||
return LaunchDescription( | ||
[ | ||
*global_launch_arguments, | ||
*global_environment_vars, | ||
*LOCAL_LAUNCH_ARGUMENTS, | ||
OpaqueFunction(function=setup_launch), | ||
] | ||
) | ||
|
||
|
||
def get_global_launch_arguments() -> List[LaunchDescriptionEntity]: | ||
"""Gets the global launch arguments defined in the global launch file. | ||
Returns: | ||
List[LaunchDescriptionEntity]: List of global launch argument objects. | ||
""" | ||
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_arguments = module.GLOBAL_LAUNCH_ARGUMENTS | ||
global_environment_vars = module.ENVIRONMENT_VARIABLES | ||
return global_launch_arguments, global_environment_vars | ||
|
||
GLOBAL_LAUNCH = get_global_main_launch_module() | ||
|
||
def setup_launch(context: LaunchContext) -> List[LaunchDescriptionEntity]: | ||
"""Collects launch descriptions that describe the system behavior in the `network_systems` | ||
package. | ||
def generate_launch_description() -> LaunchDescription: | ||
"""Generate the launch description for the `local_pathfinding` package. | ||
Args: | ||
context (LaunchContext): The current launch context. | ||
Returns: | ||
LaunchDescription: The launch description. | ||
List[LaunchDescriptionEntity]: Launch descriptions. | ||
""" | ||
# 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), | ||
] | ||
) | ||
launch_description_entities = list() | ||
launch_description_entities.append(get_cached_fib_description(context)) | ||
return launch_description_entities | ||
|
||
|
||
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. | ||
def get_cached_fib_description(context: LaunchContext) -> Node: | ||
"""Gets the launch description for the cached_fib node. | ||
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. | ||
context (LaunchContext): The current launch context. | ||
Returns: | ||
List[Node]: The nodes to be launched. | ||
Node: The node object that launches the cached_fib node. | ||
""" | ||
# 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, | ||
), | ||
node_name = "cached_fib" | ||
ros_parameters = [LaunchConfiguration("config").perform(context)] | ||
ros_arguments = [ | ||
"--log-level", | ||
[f"{node_name}:=", LaunchConfiguration("log_level")], | ||
] | ||
|
||
return nodes | ||
node = Node( | ||
package=PACKAGE_NAME, | ||
namespace="example", | ||
executable="example", | ||
name=node_name, | ||
parameters=ros_parameters, | ||
ros_arguments=ros_arguments, | ||
) | ||
|
||
return node |