This message pops up when I push the button ‘2D Pose Estimate.’ There is my launch file, my config file of AMCL, and the launch file for RVIZ2.
I notice that, in your cloud system, you set ‘use_sim_time’ to false. Why?
We are doing a simulation.
I almost confirm that my AMCL uses its parameters rather that the information in the yam file. I change the set_initial_pose to true, it still wants an initialization. I set the map_topic to some random number, it still can load the map.
localization.launch.py
import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch_ros.actions import Node
from launch.substitutions import LaunchConfiguration
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.actions import DeclareLaunchArgument, ExecuteProcess,IncludeLaunchDescriptionfrom nav2_common.launch import RewrittenYaml
def generate_launch_description():
ld = LaunchDescription() use_sim_time = LaunchConfiguration('use_sim_time', default='true') # Launch path default_launch_file_path = os.path.join(get_package_share_directory('robot_bringup'), 'launch') print(f"The launch folder is at {default_launch_file_path}." ) # Map path path_for_robot_slam = get_package_share_directory('robot_slam') default_map_dir = LaunchConfiguration('default_map_dir', default=os.path.join( path_for_robot_slam, 'maps','official_map','map.yaml')) declare_default_map_dir = DeclareLaunchArgument( 'default_map_dir', default_value=default_map_dir, description='Full path to map file to load') ld.add_action(declare_default_map_dir) # obot_localization package path path_for_robot_localization = get_package_share_directory('robot_localization') # lifecycle_manager run_lifecycle_manager_cmd = Node( package='nav2_lifecycle_manager', executable='lifecycle_manager', name='lifecycle_manager_node', output='screen', parameters=[{'use_sim_time': use_sim_time}, {'autostart': True}, {'node_names': ['map_server','amcl_node']}]) ld.add_action(run_lifecycle_manager_cmd) run_map_server_cmd = Node( package='nav2_map_server', executable='map_server', name='map_server', output='screen', parameters=[{'use_sim_time': use_sim_time}, {'yaml_filename': default_map_dir}]) ld.add_action(run_map_server_cmd) amcl_config_dir = os.path.join(path_for_robot_localization, 'config') print(f"The current AMCL config dir has been redirected to :{amcl_config_dir}.") params_file = LaunchConfiguration('params_file',default=os.path.join(amcl_config_dir,'amcl.yaml')) namespace = LaunchConfiguration('namespace',default='') param_substitutions = { 'use_sim_time': use_sim_time } configured_params = RewrittenYaml( source_file=params_file, root_key=namespace, param_rewrites=param_substitutions, convert_types=True) run_amcl_cmd = Node( package='nav2_amcl', executable='amcl', name='amcl_node', output='screen', parameters=[configured_params]) ld.add_action(run_amcl_cmd) #RVIZ use_rviz = LaunchConfiguration('use_rviz', default='true') rviz_config_dir = os.path.join(path_for_robot_localization, 'config') print(f"The current rviz config dir has been redirected to :{rviz_config_dir}.") rviz_config_file = LaunchConfiguration('rviz_config_file', default=os.path.join(rviz_config_dir,'robot_localization.rviz')) start_rviz_cmd = IncludeLaunchDescription( PythonLaunchDescriptionSource( os.path.join(default_launch_file_path, 'rviz2.launch.py') ), launch_arguments={ 'rviz_config_file': rviz_config_file, 'use_rviz': use_rviz }.items() ) ld.add_action(start_rviz_cmd) return ld
amcl.yaml
amcl:
ros__parameters:
use_sim_time: true
alpha1: 0.2
alpha2: 0.2
alpha3: 0.2
alpha4: 0.2
alpha5: 0.2
base_frame_id: "base_footprint"
beam_skip_distance: 0.5
beam_skip_error_threshold: 0.9
beam_skip_threshold: 0.3
do_beamskip: false
global_frame_id: "map"
lambda_short: 0.1
laser_likelihood_max_dist: 2.0
laser_max_range: 100.0
laser_min_range: -1.0
laser_model_type: "likelihood_field"
max_beams: 60
max_particles: 8000
min_particles: 200
odom_frame_id: "odom"
pf_err: 0.05
pf_z: 0.99
recovery_alpha_fast: 0.0
recovery_alpha_slow: 0.0
resample_interval: 1
robot_model_type: "nav2_amcl::DifferentialMotionModel"
save_pose_rate: 0.5
sigma_hit: 0.2
tf_broadcast: true
transform_tolerance: 1.0
update_min_a: 0.2
update_min_d: 0.25
z_hit: 0.5
z_max: 0.05
z_rand: 0.5
z_short: 0.05
scan_topic: scan
map_topic: map
set_initial_pose: false
always_reset_initial_pose: false
first_map_only: true
initial_pose:
x: 0.0
y: 0.0
z: 0.0
yaw: 0.0
rviz2.launch.py
#!/usr/bin/env python3
import os
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, ExecuteProcess,IncludeLaunchDescription,RegisterEventHandler
from ament_index_python.packages import get_package_share_directory
from launch.substitutions import Command, LaunchConfiguration
from launch.conditions import IfCondition, UnlessCondition
from launch_ros.actions import Node
from launch.event_handlers import OnProcessExitdef generate_launch_description():
# Create the launch description and populate
ld = LaunchDescription()use_sim_time = LaunchConfiguration('use_sim_time', default='true') declare_use_sim_time = DeclareLaunchArgument( 'use_sim_time', default_value='true', description='Use simulation (Gazebo) clock if true') ld.add_action(declare_use_sim_time) wait_time = '5s' print(f"Rviz2 will start before {wait_time}. Rviz runs before other program will course errors.") # Robot path TURTLEBOT3_MODEL = os.environ['TURTLEBOT3_MODEL'] path_for_turtlebot_description = get_package_share_directory("turtlebot_description") default_rviz_config_path = os.path.join( path_for_turtlebot_description, 'rviz', 'model.rviz') print(f'Rviz default config file is at : {default_rviz_config_path}.') # RVIZ. declare_rviz_config_file_cmd = DeclareLaunchArgument( name='rviz_config_file', default_value=default_rviz_config_path, description='Relative path to the RVIZ config file to use') ld.add_action(declare_rviz_config_file_cmd) use_rviz = LaunchConfiguration('use_rviz') declare_use_rviz_cmd = DeclareLaunchArgument( name='use_rviz', default_value='True', #default_value='False', description='Whether to start RVIZ') ld.add_action(declare_use_rviz_cmd) rviz_config_file = LaunchConfiguration('rviz_config_file') start_rviz_cmd = Node( condition=IfCondition(use_rviz), package='rviz2', executable='rviz2', name='rviz2', output='screen', arguments=['-d', rviz_config_file], parameters=[{'use_sim_time': use_sim_time}]) #ld.add_action(start_rviz_cmd) sleep_cmd = ExecuteProcess( cmd=['sleep', wait_time], output='screen') ld.add_action(sleep_cmd) event_sleep = RegisterEventHandler( event_handler=\ OnProcessExit(target_action=sleep_cmd,on_exit=[start_rviz_cmd]) ) ld.add_action(event_sleep) return ld