LaunchConfiguration和DeclareLaunchArgument属于launch文件的高阶应用,它们需要配合使用,可以实现开发者自行定义参数通过ROS的launch命令向launch文件传递数据。这使得不需要改动launch文件就可以实现对launch文件的相关变量进行赋值,提高了launch文件的灵活性。
向launch文件传递参数初步功能实现
下面通过实例具体说明LaunchConfiguration和DeclareLaunchArgument怎么实现向launch文件传递参数。
launch文件名为:example7.laun.py
from launch_ros.actions import Node
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.actions import LogInfo
from launch.substitutions import LaunchConfiguration
def generate_launch_description():
t_ns = 'turtle_ns'
n_name_conf = LaunchConfiguration('n_name')
n_name_arg = DeclareLaunchArgument(
'n_name',
default_value='node_name'
)
turtle_node = Node(
package='turtlesim',
namespace='turtle_ns',
executable='turtlesim_node'

最低0.47元/天 解锁文章
1462

被折叠的 条评论
为什么被折叠?



