# 10.9使用FishBot进行自主导航 1.编写launch文件 ``` ''' 作者: 小鱼 公众号: 鱼香ROS QQ交流群: 2642868461 描述: file content ''' import os from ament_index_python.packages import get_package_share_directory from launch import LaunchDescription from launch.actions import DeclareLaunchArgument from launch.actions import IncludeLaunchDescription from launch.launch_description_sources import PythonLaunchDescriptionSource from launch.substitutions import LaunchConfiguration from launch_ros.actions import Node def generate_launch_description(): fishbot_navigation2_dir = get_package_share_directory('fishbot_navigation2') nav2_bringup_dir = get_package_share_directory('nav2_bringup') use_sim_time = LaunchConfiguration('use_sim_time', default='true') map_yaml_path = LaunchConfiguration('map',default=os.path.join(fishbot_navigation2_dir,'maps','fishbot_map.yaml')) nav2_param_path = LaunchConfiguration('params_file',default=os.path.join(fishbot_navigation2_dir,'param','fishbot.yaml')) rviz_config_dir = os.path.join(nav2_bringup_dir,'rviz','nav2_default_view.rviz') return LaunchDescription([ DeclareLaunchArgument('use_sim_time',default_value=use_sim_time,description='Use simulation (Gazebo) clock if true'), DeclareLaunchArgument('map',default_value=map_yaml_path,description='Full path to map file to load'), DeclareLaunchArgument('params_file',default_value=nav2_param_path,description='Full path to param file to load'), IncludeLaunchDescription( PythonLaunchDescriptionSource([nav2_bringup_dir,'/launch','/bringup_launch.py']), launch_arguments={ 'map': map_yaml_path, 'use_sim_time': use_sim_time, 'params_file': nav2_param_path}.items(), ), Node( package='rviz2', executable='rviz2', name='rviz2', arguments=['-d', rviz_config_dir], parameters=[{'use_sim_time': use_sim_time}], output='screen'), ]) ``` 2.CMakeLists.txt ``` cmake_minimum_required(VERSION 3.5) project(fishbot_navigation2) # Default to C99 if(NOT CMAKE_C_STANDARD) set(CMAKE_C_STANDARD 99) endif() # Default to C++14 if(NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 14) endif() if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic) endif() # find dependencies find_package(ament_cmake REQUIRED) # uncomment the following section in order to fill in # further dependencies manually. # find_package( REQUIRED) if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) # the following line skips the linter which checks for copyrights # uncomment the line when a copyright and license is not present in all source files #set(ament_cmake_copyright_FOUND TRUE) # the following line skips cpplint (only works in a git repo) # uncomment the line when this package is not in a git repo #set(ament_cmake_cpplint_FOUND TRUE) ament_lint_auto_find_test_dependencies() endif() install( DIRECTORY launch config param maps DESTINATION share/${PROJECT_NAME} ) ament_package() ``` 3. -------------- 技术交流&&问题求助: - **微信公众号及交流群:鱼香ROS** - **小鱼微信:AiIotRobot** - **QQ交流群:139707339** - 版权保护:已加入“维权骑士”(rightknights.com)的版权保护计划