SMACC2
bringup_launch.py
Go to the documentation of this file.
1# Copyright (c) 2018 Intel Corporation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import os
16
17from ament_index_python.packages import get_package_share_directory
18
19from launch import LaunchDescription
20from launch.actions import (
21 DeclareLaunchArgument,
22 GroupAction,
23 IncludeLaunchDescription,
24 SetEnvironmentVariable,
25)
26
27# from launch.conditions import IfCondition
28from launch.launch_description_sources import PythonLaunchDescriptionSource
29
30from launch.substitutions import LaunchConfiguration
31
32# from launch_ros.actions import PushRosNamespace
33
34
36 # Get the launch directory
37 sm_husky_barrel_search_1 = get_package_share_directory("sm_husky_barrel_search_1")
38 launch_dir = os.path.join(sm_husky_barrel_search_1, "launch")
39
40 # Create the launch configuration variables
41 namespace = LaunchConfiguration("namespace")
42 # use_namespace = LaunchConfiguration("use_namespace")
43 # slam = LaunchConfiguration("slam")
44 # map_yaml_file = LaunchConfiguration("map")
45 use_sim_time = LaunchConfiguration("use_sim_time")
46 params_file = LaunchConfiguration("params_file")
47 default_nav_to_pose_bt_xml = LaunchConfiguration("default_nav_to_pose_bt_xml")
48 autostart = LaunchConfiguration("autostart")
49
50 stdout_linebuf_envvar = SetEnvironmentVariable("RCUTILS_LOGGING_BUFFERED_STREAM", "1")
51
52 declare_namespace_cmd = DeclareLaunchArgument(
53 "namespace", default_value="", description="Top-level namespace"
54 )
55
56 declare_use_namespace_cmd = DeclareLaunchArgument(
57 "use_namespace",
58 default_value="false",
59 description="Whether to apply a namespace to the navigation stack",
60 )
61
62 declare_slam_cmd = DeclareLaunchArgument(
63 "slam", default_value="False", description="Whether run a SLAM"
64 )
65
66 declare_map_yaml_cmd = DeclareLaunchArgument(
67 "map", description="Full path to map yaml file to load"
68 )
69
70 declare_use_sim_time_cmd = DeclareLaunchArgument(
71 "use_sim_time", default_value="false", description="Use simulation (Gazebo) clock if true"
72 )
73
74 declare_params_file_cmd = DeclareLaunchArgument(
75 "params_file",
76 default_value=os.path.join(
77 sm_husky_barrel_search_1, "params", "nav2z_client", "nav2_params.yaml"
78 ),
79 description="Full path to the ROS2 parameters file to use for all launched nodes",
80 )
81
82 declare_bt_xml_cmd = DeclareLaunchArgument(
83 "default_nav_to_pose_bt_xml",
84 default_value=os.path.join(
85 sm_husky_barrel_search_1, "params", "nav2z_client", "navigation_tree.xml"
86 ),
87 description="Full path to the behavior tree xml file to use",
88 )
89
90 declare_autostart_cmd = DeclareLaunchArgument(
91 "autostart", default_value="true", description="Automatically startup the nav2 stack"
92 )
93
94 # Specify the actions
95 bringup_cmd_group = GroupAction(
96 [
97 IncludeLaunchDescription(
98 PythonLaunchDescriptionSource(os.path.join(launch_dir, "navigation_launch.py")),
99 launch_arguments={
100 "namespace": namespace,
101 "use_sim_time": use_sim_time,
102 "autostart": autostart,
103 "params_file": params_file,
104 "default_nav_to_pose_bt_xml": default_nav_to_pose_bt_xml,
105 "use_lifecycle_mgr": "false",
106 "map_subscribe_transient_local": "true",
107 }.items(),
108 ),
109 ]
110 )
111
112 # Create the launch description and populate
113 ld = LaunchDescription()
114
115 # Set environment variables
116 ld.add_action(stdout_linebuf_envvar)
117
118 # Declare the launch options
119 ld.add_action(declare_namespace_cmd)
120 ld.add_action(declare_use_namespace_cmd)
121 ld.add_action(declare_slam_cmd)
122 ld.add_action(declare_map_yaml_cmd)
123 ld.add_action(declare_use_sim_time_cmd)
124 ld.add_action(declare_params_file_cmd)
125 ld.add_action(declare_autostart_cmd)
126 ld.add_action(declare_bt_xml_cmd)
127
128 # Add the actions to launch all of the navigation nodes
129 ld.add_action(bringup_cmd_group)
130
131 return ld
def generate_launch_description()