|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# |
| 3 | +# Copyright 2023 6-robot. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | +# Authors: Zhang Wanjie |
| 18 | + |
| 19 | +import os |
| 20 | +from ament_index_python.packages import get_package_share_directory |
| 21 | +from launch import LaunchDescription |
| 22 | +from launch.actions import IncludeLaunchDescription |
| 23 | +from launch.launch_description_sources import PythonLaunchDescriptionSource |
| 24 | +from launch.substitutions import LaunchConfiguration |
| 25 | +from launch_ros.actions import Node |
| 26 | + |
| 27 | + |
| 28 | +def generate_launch_description(): |
| 29 | + launch_file_dir = os.path.join(get_package_share_directory('wpr_simulation2'), 'launch') |
| 30 | + pkg_gazebo_ros = get_package_share_directory('gazebo_ros') |
| 31 | + |
| 32 | + use_sim_time = LaunchConfiguration('use_sim_time', default='true') |
| 33 | + |
| 34 | + world = os.path.join( |
| 35 | + get_package_share_directory('wpr_simulation2'), |
| 36 | + 'worlds', |
| 37 | + 'robocup_home.world' |
| 38 | + ) |
| 39 | + |
| 40 | + behavior_tree = os.path.join( |
| 41 | + get_package_share_directory('wpr_simulation2'), |
| 42 | + 'config', |
| 43 | + 'behavior_tree.xml' |
| 44 | + ) |
| 45 | + |
| 46 | + map_dir = os.path.join( |
| 47 | + get_package_share_directory('wpr_simulation2'), |
| 48 | + 'map', |
| 49 | + 'map.yaml' |
| 50 | + ) |
| 51 | + |
| 52 | + nav_param_dir = os.path.join( |
| 53 | + get_package_share_directory('wpr_simulation2'), |
| 54 | + 'config', |
| 55 | + 'nav2_params.yaml' |
| 56 | + ) |
| 57 | + |
| 58 | + nav2_launch_file_dir = os.path.join( |
| 59 | + get_package_share_directory('nav2_bringup'), |
| 60 | + 'launch' |
| 61 | + ) |
| 62 | + |
| 63 | + gzserver_cmd = IncludeLaunchDescription( |
| 64 | + PythonLaunchDescriptionSource( |
| 65 | + os.path.join(pkg_gazebo_ros, 'launch', 'gzserver.launch.py') |
| 66 | + ), |
| 67 | + launch_arguments={'world': world}.items() |
| 68 | + ) |
| 69 | + |
| 70 | + gzclient_cmd = IncludeLaunchDescription( |
| 71 | + PythonLaunchDescriptionSource( |
| 72 | + os.path.join(pkg_gazebo_ros, 'launch', 'gzclient.launch.py') |
| 73 | + ) |
| 74 | + ) |
| 75 | + |
| 76 | + spawn_robot_cmd = IncludeLaunchDescription( |
| 77 | + PythonLaunchDescriptionSource( |
| 78 | + os.path.join(launch_file_dir, 'spawn_wpb.launch.py') |
| 79 | + ) |
| 80 | + ) |
| 81 | + |
| 82 | + navigation_cmd = IncludeLaunchDescription( |
| 83 | + PythonLaunchDescriptionSource([nav2_launch_file_dir, '/bringup_launch.py']), |
| 84 | + launch_arguments={ |
| 85 | + 'map': map_dir, |
| 86 | + 'use_sim_time': use_sim_time, |
| 87 | + 'params_file': nav_param_dir}.items(), |
| 88 | + ) |
| 89 | + |
| 90 | + # Define the parameters for the navigation stack |
| 91 | + |
| 92 | + |
| 93 | + rviz_cmd = Node( |
| 94 | + package='rviz2', |
| 95 | + namespace='', |
| 96 | + executable='rviz2', |
| 97 | + name='rviz2', |
| 98 | + arguments=['-d', [os.path.join(get_package_share_directory('wp_map_tools'), 'rviz', 'navi.rviz')]] |
| 99 | + ) |
| 100 | + |
| 101 | + ld = LaunchDescription() |
| 102 | + |
| 103 | + # Add the commands to the launch description |
| 104 | + ld.add_action(gzserver_cmd) |
| 105 | + ld.add_action(gzclient_cmd) |
| 106 | + ld.add_action(spawn_robot_cmd) |
| 107 | + ld.add_action(navigation_cmd) |
| 108 | + ld.add_action(rviz_cmd) |
| 109 | + |
| 110 | + return ld |
0 commit comments