加载yaml地图
方法一
参考链接:链接
yahboom@VM:~/rplidar_ws_src/src/yahboomcar_nav/maps$ ros2 run nav2_map_server map_server --ros-args --param yaml_filename:=fishbot_map.yaml
[INFO] [1714904123.325652996] [map_server]:
map_server lifecycle node launched.
Waiting on external lifecycle transitions to activate
See https://design.ros2.org/articles/node_lifecycle.html for more information.
[INFO] [1714904123.326354743] [map_server]: Creating
ros2 lifecycle set /map_server configure
ros2 lifecycle set /map_server activate
ros2 launch rosbridge_server rosbridge_websocket_launch.xml
方法二: 编写为launch文件,加载yaml地图
import os
import yaml
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions import ExecuteProcess
from launch.substitutions import LaunchConfiguration
import launch_ros.actions
def generate_launch_description():
ld = LaunchDescription()
# map file
map_file_path = os.path.join(
get_package_share_directory('wheeltec_nav2'),
'map',
'WHEELTEC.yaml'
)
map_server_cmd = Node(
package='nav2_map_server',
executable='map_server',
output='screen',
parameters=[{
'yaml_filename': map_file_path}])
lifecycle_nodes = ['map_server']
use_sim_time = True
autostart = True
start_lifecycle_manager_cmd = launch_ros.actions.Node(
package='nav2_lifecycle_manager',
executable='lifecycle_manager',
name='lifecycle_manager',
output='screen',
emulate_tty=True, # https://github.com/ros2/launch/issues/188
parameters=[{
'use_sim_time': use_sim_time},
{
'autostart': autostart},
{
'node_names': lifecycle_nodes}])
ld.add_action(map_server_cmd)
ld.add_action(start_lifecycle_manager_cmd)
return ld
- 运行 launch文件: ros2 launch robot_nav2map_show.launch.py
ros@ros-virtual-machine:~/wh_robot$ ros2 launch robot_nav2map_show.launch.py
[INFO] [launch]: All log files can be found below /home/ros/.ros/log/2024-05-09-17-28-27-089551-ros-virtual-machine-9961
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [lifecycle_manager-2]: process started with pid [9964]
[INFO] [map_server-1]: process started with pid [9962]
[map_server-1] [INFO] [1715246907.206470040] [map_server]:
[map_server-1] map_server lifecycle node launched.
[map_server-1] Waiting on external lifecycle transitions to activate
[map_server-1] See https://design.ros2.org/articles/node_lifecycle.html for more information.
[map_server-1] [INFO] [1715246907.206592754] [map_server]: Creating
[lifecycle_manager-2] [INFO] [1715246907.209485626] [lifecycle_manager]: Creating
[lifecycle_manager-2] [INFO] [1715246907.211565108] [lifecycle_manager]: Creating and initializing lifecycle service clients
[lifecycle_manager-2] [INFO] [1715246907.303960694] [lifecycle_manager]: Starting managed nodes bringup...
[lifecycle_manager-2] [INFO] [1715246907.304226094] [lifecycle_manager]: Configuring map_server
[map_server-1] [INFO] [1715246907.451476723] [map_server]: Configuring
[map_server-1] [INFO] [map_io]: Loading yaml file: /home/ros/wh_robot/install/robot_nav2/share/robot_nav2/map/WHEELTEC.yaml
[map_server-1] [DEBUG] [map_io]: resolution: 0.05
[map_server-1] [DEBUG] [map_io]: origin[0]: -10
[map_server-1] [DEBUG] [map_io]: origin[1]: -10
[map_server-1] [DEBUG] [map_io]: origin[2]: 0
[map_server-1] [DEBUG] [map_io]: free_thresh: 0.196
[map_server-1] [DEBUG] [map_io]: occupied_thresh: 0.65
[map_server-1] [DEBUG] [map_io]: mode: trinary
[map_server-1] [DEBUG] [map_io]: negate: 0
[map_server-1] [INFO] [map_io]: Loading image_file: /home/ros/wh_robot/src/robot_nav2/map/WHEELTEC.pgm
[map_server-1] [DEBUG] [map_io]: Read map /home/ros/wh_robot/src/robot_nav2/map/WHEELTEC.pgm: 672 X 384 map @ 0.05 m/cell
[lifecycle_manager-2] [INFO] [1715246907.472013920] [lifecycle_manager]: Activating map_server
[map_server-1] [INFO] [1715246907.472134653] [map_server]: Activating
[map_server-1] [INFO] [1715246907.472440295] [map_server]: Creating bond (map_server) to lifecycle manager.
[lifecycle_manager-2] [INFO] [1715246907.574923038] [lifecycle_manager]: Server map_server connected with bond.
[lifecycle_manager-2] [INFO] [1715246907.575034213] [lifecycle_manager]: Managed nodes are active
[lifecycle_manager-2] [INFO] [1715246907.575060314] [lifecycle_manager]: Creating bond timer...