ROS2基礎部分實驗内容較長的描述分别在前3次提示中。涉及文檔如下所示:

本節開始,主要涉及文檔如下圖所示:
如果不熟悉,請看直播回放,并且依據回放中的方法進行練習,注意直播時ROS2版本為foxy,鏡像中是 galactic。
本節涉及代碼在如下檔案夾:
參考:
所有代碼都已調試通過,但最好按文檔自學一遍,這樣才能掌握。
測試案例:
. install/setup.bash
ros2 launch sam_bot_description display.launch.py
ros2 launch slam_toolbox online_async_launch.py
ros2 run tf2_tools view_frames.py
ros2 launch nav2_bringup navigation_launch.py
ros2 run nav2_costmap_2d nav2_costmap_2d_markers voxel_grid:=/local_costmap/voxel_grid visualization_marker:=/my_marker
本部分詳細介紹參考釘釘直播回放和
Nav2官方教程➡First-Time Robot Setup Guide⬅搞不定
添加雷射主題檢視效果。
修改一下:
如遇到問題獨立思考。
自主完成實驗。
import launch
from launch.substitutions import Command, LaunchConfiguration
import launch_ros
import os
def generate_launch_description():
pkg_share = launch_ros.substitutions.FindPackageShare(package='sam_bot_description').find('sam_bot_description')
default_model_path = os.path.join(pkg_share, 'src/description/sam_bot_description.urdf')
default_rviz_config_path = os.path.join(pkg_share, 'rviz/urdf_config.rviz')
world_path=os.path.join(pkg_share, 'world/my_world.sdf')
robot_state_publisher_node = launch_ros.actions.Node(
package='robot_state_publisher',
executable='robot_state_publisher',
parameters=[{'robot_description': Command(['xacro ', LaunchConfiguration('model')])}]
)
joint_state_publisher_node = launch_ros.actions.Node(
package='joint_state_publisher',
executable='joint_state_publisher',
name='joint_state_publisher',
condition=launch.conditions.UnlessCondition(LaunchConfiguration('gui'))
)
rviz_node = launch_ros.actions.Node(
package='rviz2',
executable='rviz2',
name='rviz2',
output='screen',
arguments=['-d', LaunchConfiguration('rvizconfig')],
)
spawn_entity = launch_ros.actions.Node(
package='gazebo_ros',
executable='spawn_entity.py',
arguments=['-entity', 'sam_bot', '-topic', 'robot_description'],
output='screen'
)
robot_localization_node = launch_ros.actions.Node(
package='robot_localization',
executable='ekf_node',
name='ekf_filter_node',
output='screen',
parameters=[os.path.join(pkg_share, 'config/ekf.yaml'), {'use_sim_time': LaunchConfiguration('use_sim_time')}]
)
return launch.LaunchDescription([
launch.actions.DeclareLaunchArgument(name='gui', default_value='True',
description='Flag to enable joint_state_publisher_gui'),
launch.actions.DeclareLaunchArgument(name='model', default_value=default_model_path,
description='Absolute path to robot urdf file'),
launch.actions.DeclareLaunchArgument(name='rvizconfig', default_value=default_rviz_config_path,
description='Absolute path to rviz config file'),
launch.actions.DeclareLaunchArgument(name='use_sim_time', default_value='True',
description='Flag to enable use_sim_time'),
launch.actions.ExecuteProcess(cmd=['gazebo', '--verbose', '-s', 'libgazebo_ros_factory.so', world_path], output='screen'),
joint_state_publisher_node,
robot_state_publisher_node,
spawn_entity,
robot_localization_node,
rviz_node
])
複制