感到热泪盈眶了家人们 这个局部路径规划终于可以离线了
就是用这个启动文件就可以 了
/home/acan/ros2_ws/install/nav2_pure_pursuit_controller/share/nav2_pure_pursuit_controller/nav2_pure_pursuit_controller.xml
import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, GroupAction, SetEnvironmentVariable
from launch.conditions import IfCondition
from launch.substitutions import LaunchConfiguration, PythonExpression
from launch_ros.actions import LoadComposableNodes
from launch_ros.actions import Node
from launch_ros.descriptions import ComposableNode
from nav2_common.launch import RewrittenYaml
def generate_launch_description():
bringup_dir = get_package_share_directory('yhs_nav2')
launch_dir = os.path.join(bringup_dir, 'launch')
workspace_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
map_file_dir = os.path.join(workspace_dir, 'yhs_nav2', 'map')
use_respawn = LaunchConfiguration('use_respawn')
declare_use_respawn_cmd = DeclareLaunchArgument(
'use_respawn', default_value='False',
description='Whether to respawn if a node crashes. Applied when composition is disabled.')
namespace = LaunchConfiguration('namespace')
declare_namespace_cmd = DeclareLaunchArgument(
'namespace',
default_value='',
description='Top-level namespace')
use_sim_time = LaunchConfiguration('use_sim_time')
declare_use_sim_time_cmd = DeclareLaunchArgument(
'use_sim_time',
default_value='false',
description='Use simulation (Gazebo) clock if true')
params_file = LaunchConfiguration('params_file')
autostart = LaunchConfiguration('autostart')
declare_autostart_cmd = DeclareLaunchArgument(
'autostart', default_value='true',
description='Automatically startup the nav2 stack')
log_level = LaunchConfiguration('log_level')
declare_log_level_cmd = DeclareLaunchArgument(
'log_level', default_value='info',
description='log level')
map_yaml_file = LaunchConfiguration('map')
declare_map_yaml_cmd = DeclareLaunchArgument(
'map',
default_value=os.path.join(map_file_dir, '416.yaml'),
description='地图名称')
lifecycle_nodes = ['behavior_server','controller_server','map_server','planner_server','bt_navigator','waypoint_follower','amcl']
remappings = [('/tf', 'tf'),
('/tf_static', 'tf_static')]
declare_params_file_cmd = DeclareLaunchArgument(
'params_file',
default_value=os.path.join(bringup_dir, 'param', 'yhs_nav2.yaml'),
description='Full path to the ROS2 parameters file to use for all launched nodes')
param_substitutions = {
'use_sim_time': use_sim_time,
'yaml_filename': map_yaml_file}
configured_params = RewrittenYaml(
source_file=params_file,
root_key=namespace,
param_rewrites=param_substitutions,
convert_types=True)
bringup_cmd_group = GroupAction([
Node(
package='nav2_behaviors',
executable='behavior_server',
name='behavior_server',
output='screen',
respawn=use_respawn,
respawn_delay=2.0,
parameters=[configured_params],
arguments=['--ros-args', '--log-level', log_level],
remappings=remappings),
Node(
package='nav2_controller',
executable='controller_server',
output='screen',
respawn=use_respawn,
respawn_delay=2.0,
parameters=[configured_params],
arguments=['--ros-args', '--log-level', log_level],
remappings=remappings + [('cmd_vel', 'cmd_vel_nav')]),
Node(
name='nav2_container',
package='rclcpp_components',
executable='component_container_isolated',
parameters=[configured_params, {'autostart': autostart}],
arguments=['--ros-args', '--log-level', log_level],
remappings=remappings,
output='screen'),
Node(
package='nav2_bt_navigator',
executable='bt_navigator',
name='bt_navigator',
output='screen',
parameters=[configured_params],
arguments=['--ros-args', '--log-level', log_level],
remappings=remappings),
Node(
package='nav2_map_server',
executable='map_server',
name='map_server',
parameters=[{'yaml_filename': os.path.join(map_file_dir, '416.yaml')}]
),
Node(
package='nav2_amcl',
executable='amcl',
name='amcl',
output='screen',
respawn=use_respawn,
respawn_delay=2.0,
parameters=[configured_params],
arguments=['--ros-args', '--log-level', log_level],
remappings=remappings),
Node(
package='nav2_waypoint_follower',
executable='waypoint_follower',
name='waypoint_follower',
output='screen',
respawn=use_respawn,
respawn_delay=2.0,
parameters=[configured_params],
arguments=['--ros-args', '--log-level', log_level],
remappings=remappings),
Node(
package='nav2_planner',
executable='planner_server',
name='planner_server',
parameters=[{
'expected_planner_frequency': 2.0,
'use_sim_time': False,
'planner_plugins': ['GridBased'],
'GridBased': {
'plugin': 'nav2_navfn_planner/NavfnPlanner',
'tolerance': 0.5,
'use_astar': True,
'allow_unknown': False,
'smooth_path': True,
'angle': 0.05
}
}]),
Node(
package='nav2_lifecycle_manager',
executable='lifecycle_manager',
name='lifecycle_manager',
output='screen',
parameters=[{'autostart': True},
{'node_names': lifecycle_nodes}]),
Node(
package='tf2_ros',
executable='static_transform_publisher',
name='static_transform_publisher',
output='screen',
arguments=['0', '0', '0', '0', '0', '0', 'map', 'base_link']),
])
ld = LaunchDescription()
ld.add_action(declare_namespace_cmd)
ld.add_action(declare_params_file_cmd)
ld.add_action(declare_use_sim_time_cmd)
ld.add_action(declare_autostart_cmd)
ld.add_action(declare_log_level_cmd)
ld.add_action(declare_map_yaml_cmd)
ld.add_action(declare_use_respawn_cmd)
ld.add_action(bringup_cmd_group)
return ld