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_warehouse_2_dir = get_package_share_directory("sm_dance_bot_warehouse_2")
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_warehouse_2_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 # xtermprefix = "xterm -xrm 'XTerm*scrollBar: true' -xrm 'xterm*rightScrollBar: true' " \
76 # "-hold -geometry 1000x600 -sl 10000 -e"
77
78 # start_lifecycle_manager_cmd = Node(
79 # package="nav2_lifecycle_manager",
80 # executable="lifecycle_manager",
81 # name="lifecycle_manager_slam",
82 # output="screen",
83 # parameters=[
84 # {"use_sim_time": use_sim_time},
85 # {"autostart": autostart},
86 # {"node_names": lifecycle_nodes},
87 # ],
88 # prefix=xtermprefix,
89 # )
90
91 # If the provided param file doesn't have slam_toolbox params, we must remove the 'params_file'
92 # LaunchConfiguration, or it will be passed automatically to slam_toolbox and will not load
93 # the default file
94
95 start_slam_toolbox_cmd = IncludeLaunchDescription(
96 PythonLaunchDescriptionSource(slam_launch_file),
97 launch_arguments={"use_sim_time": use_sim_time}.items(),
98 )
99
100 # Pop (or load) previous LaunchConfiguration, resetting the state of params_file
101 # pop_launch_config = PopLaunchConfigurations(
102 # condition=UnlessCondition(has_slam_toolbox_params))
103
104 ld = LaunchDescription()
105
106 # Declare the launch options
107 ld.add_action(declare_namespace_cmd)
108 # ld.add_action(declare_params_file_cmd)
109 ld.add_action(declare_use_sim_time_cmd)
110 ld.add_action(declare_autostart_cmd)
111
112 # Running Map Saver Server
113 # ld.add_action(start_map_saver_server_cmd)
114 # ld.add_action(start_lifecycle_manager_cmd)
115
116 # Running SLAM Toolbox
117 # ld.add_action(push_launch_config)
118 # ld.add_action(remove_params_file)
119 ld.add_action(start_slam_toolbox_cmd)
120 # ld.add_action(pop_launch_config)
121
122 return ld
def generate_launch_description()
Definition: slam_launch.py:28