基于上一篇的action代码上继续,链接如上:
参考链接:
src/action_moudle/launch/action_launch.launch.py 路径下创建文件action_launch.launch.py
# 导入库
from launch import LaunchDescription
from launch_ros.actions import Node
def 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 launch
DESTINATION share/${PROJECT_NAME})
编译后可以在路径下 install/action_moudle/share/action_moudle/launch/action_launch.launch.py找到刚刚编译的文件
启动终端执行:
ros2 launch action_moudle action_launch.launch.py
可以看到两个节点运行 ,比较简单 ,不多说了,根据需求边用边学