@811877507 launch文件:

#!/usr/bin/env python3 # # Copyright 2019 ROBOTIS CO., LTD. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # Authors: Darby Lim, Ryan Shim import os from ament_index_python.packages import get_package_share_directory from launch import LaunchDescription from launch.actions import IncludeLaunchDescription from launch.launch_description_sources import PythonLaunchDescriptionSource from launch.substitutions import LaunchConfiguration from launch.actions import ExecuteProcess, IncludeLaunchDescription, RegisterEventHandler from launch.event_handlers import OnProcessExit from launch.launch_description_sources import PythonLaunchDescriptionSource from launch_ros.actions import Node import xacro TURTLEBOT3_MODEL = os.environ['TURTLEBOT3_MODEL'] def generate_launch_description(): gazebo = IncludeLaunchDescription( PythonLaunchDescriptionSource([os.path.join( get_package_share_directory('gazebo_ros'), 'launch'), '/gazebo.launch.py']), ) use_sim_time = LaunchConfiguration('use_sim_time', default='true') world_file_name = 'turtlebot3_houses/' + TURTLEBOT3_MODEL + '.model' world = os.path.join(get_package_share_directory('turtlebot3_gazebo'), 'worlds', world_file_name) world = '/opt/ros/foxy/share/turtlebot3_gazebo/worlds/turtlebot3_houses/waffle.model' launch_file_dir = os.path.join(get_package_share_directory('turtlebot3_gazebo'), 'launch') pkg_gazebo_ros = get_package_share_directory('gazebo_ros') gazebo = IncludeLaunchDescription( PythonLaunchDescriptionSource([os.path.join( get_package_share_directory('gazebo_ros'), 'launch'), '/gazebo.launch.py']), ) turtlebot3_description_path = os.path.join( get_package_share_directory('turtlebot3_description')) xacro_file = os.path.join(turtlebot3_description_path, 'urdf', 'turtlebot3_waffle.xacro.urdf') doc = xacro.parse(open(xacro_file)) xacro.process_doc(doc) params = {'robot_description': doc.toxml()} node_robot_state_publisher = Node( package='robot_state_publisher', executable='robot_state_publisher', output='screen', parameters=[params] ) spawn_entity = Node(package='gazebo_ros', executable='spawn_entity.py', arguments=[#'-topic', 'robot_description', '-database', 'turtlebot3_waffle', '-entity', 'turtlebot3_waffle'], output='screen') load_joint_state_controller = ExecuteProcess( cmd=['ros2', 'control', 'load_controller', '--set-state', 'start', 'joint_state_broadcaster'], output='screen' ) load_position_controllers = ExecuteProcess( cmd=['ros2', 'control', 'load_controller', '--set-state', 'start', 'lidar_joint_position_controller'], output='screen' ) return LaunchDescription([ RegisterEventHandler( event_handler=OnProcessExit( target_action=spawn_entity, on_exit=[load_joint_state_controller], ) ), RegisterEventHandler( event_handler=OnProcessExit( target_action=load_joint_state_controller, on_exit=[load_position_controllers], ) ), gazebo, # IncludeLaunchDescription( # PythonLaunchDescriptionSource( # os.path.join(pkg_gazebo_ros, 'launch', 'gzserver.launch.py') # ), # launch_arguments={'world': world}.items(), # ), # IncludeLaunchDescription( # PythonLaunchDescriptionSource( # os.path.join(pkg_gazebo_ros, 'launch', 'gzclient.launch.py') # ), # ), spawn_entity, node_robot_state_publisher, ])