基于上一篇的action代码上继续,链接如上:
ROS2 通信三大件之动作 -- Action-CSDN博客
参考链接:ROS2——教你写新版Launch文件 | 范子琦的博客
1、创建文件
src/action_moudle/launch/action_launch.launch.py 路径下创建文件action_launch.launch.py
# 导入库
from launch import LaunchDescription
from launch_ros.actions import Nodedef generate_launch_description():"""launch内容描述函数,由ros2 launch 扫描调用"""action_server = Node(package="action_moudle",executable="action_server")action_client = Node(package="action_moudle",executable="action_client")# 创建LaunchDescription对象launch_description,用于描述launch文件launch_description = LaunchDescription([action_server, action_client])# 返回让ROS2根据launch描述执行节点return launch_description
src/action_moudle/CMakeLists.txt
# 安装 Launch 文件
install(DIRECTORY launchDESTINATION share/${PROJECT_NAME})
2、编译运行测试
编译后可以在路径下 install/action_moudle/share/action_moudle/launch/action_launch.launch.py找到刚刚编译的文件
启动终端执行:
ros2 launch action_moudle action_launch.launch.py
可以看到两个节点运行 ,比较简单 ,不多说了,根据需求边用边学