SMACC2
slam_launch.py
Go to the documentation of this file.
1# Copyright (c) 2020 Samsung Research Russia
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 DeclareLaunchArgument, IncludeLaunchDescription
21from launch.launch_description_sources import PythonLaunchDescriptionSource
22from launch.substitutions import LaunchConfiguration
23
24# from launch_ros.actions import Node
25# from nav2_common.launch import RewrittenYaml
26
27
29 # Input parameters declaration
30 # namespace = LaunchConfiguration("namespace")
31 # params_file = LaunchConfiguration("params_file")
32 use_sim_time = LaunchConfiguration("use_sim_time")
33 # autostart = LaunchConfiguration("autostart")
34 # sm_dance_bot_strikes_back_dir = get_package_share_directory("sm_dance_bot_strikes_back")
35
36 # Variables
37 # lifecycle_nodes = ["slam_toolbox"]
38
39 # Getting directories and launch-files
40 # bringup_dir = get_package_share_directory("nav2_bringup")
41 slam_toolbox_dir = get_package_share_directory("slam_toolbox")
42 # slam_launch_file = os.path.join(sm_dance_bot_strikes_back_dir, 'launch', 'online_sync_launch.py')
43 slam_launch_file = os.path.join(slam_toolbox_dir, "launch", "online_sync_launch.py")
44
45 # Create our own temporary YAML files that include substitutions
46 # param_substitutions = {"use_sim_time": use_sim_time}
47
48 # configured_params = RewrittenYaml(
49 # source_file=params_file,
50 # root_key=namespace,
51 # param_rewrites=param_substitutions,
52 # convert_types=True,
53 # )
54
55 # Declare the launch arguments
56 declare_namespace_cmd = DeclareLaunchArgument(
57 "namespace", default_value="", description="Top-level namespace"
58 )
59
60 # declare_params_file_cmd = DeclareLaunchArgument(
61 # 'params_file',
62 # default_value=os.path.join(bringup_dir, 'params', 'nav2_params.yaml'),
63 # description='Full path to the ROS2 parameters file to use for all launched nodes')
64
65 declare_use_sim_time_cmd = DeclareLaunchArgument(
66 "use_sim_time", default_value="True", description="Use simulation (Gazebo) clock if true"
67 )
68
69 declare_autostart_cmd = DeclareLaunchArgument(
70 "autostart", default_value="True", description="Automatically startup the nav2 stack"
71 )
72
73 # Nodes launching commands
74
75 # start_map_saver_server_cmd = Node(
76 # package='nav2_map_server',
77 # executable='map_saver_server',
78 # output='screen',
79 # parameters=[configured_params])
80
81 # xtermprefix = "xterm -xrm 'XTerm*scrollBar: true' -xrm 'xterm*rightScrollBar: true' " \
82 # "-hold -geometry 1000x600 -sl 10000 -e"
83
84 # start_lifecycle_manager_cmd = Node(
85 # package="nav2_lifecycle_manager",
86 # executable="lifecycle_manager",
87 # name="lifecycle_manager_slam",
88 # output="screen",
89 # parameters=[
90 # {"use_sim_time": use_sim_time},
91 # {"autostart": autostart},
92 # {"node_names": lifecycle_nodes},
93 # ],
94 # prefix=xtermprefix,
95 # )
96
97 # If the provided param file doesn't have slam_toolbox params, we must remove the 'params_file'
98 # LaunchConfiguration, or it will be passed automatically to slam_toolbox and will not load
99 # the default file
100
101 start_slam_toolbox_cmd = IncludeLaunchDescription(
102 PythonLaunchDescriptionSource(slam_launch_file),
103 launch_arguments={"use_sim_time": use_sim_time}.items(),
104 )
105
106 # Pop (or load) previous LaunchConfiguration, resetting the state of params_file
107 # pop_launch_config = PopLaunchConfigurations(
108 # condition=UnlessCondition(has_slam_toolbox_params))
109
110 ld = LaunchDescription()
111
112 # Declare the launch options
113 ld.add_action(declare_namespace_cmd)
114 # ld.add_action(declare_params_file_cmd)
115 ld.add_action(declare_use_sim_time_cmd)
116 ld.add_action(declare_autostart_cmd)
117
118 # Running Map Saver Server
119 # ld.add_action(start_map_saver_server_cmd)
120 # ld.add_action(start_lifecycle_manager_cmd)
121
122 # Running SLAM Toolbox
123 # ld.add_action(push_launch_config)
124 # ld.add_action(remove_params_file)
125 ld.add_action(start_slam_toolbox_cmd)
126 # ld.add_action(pop_launch_config)
127
128 return ld
def generate_launch_description()
Definition: slam_launch.py:28