-
这是一个小伙伴问小鱼的问题,结果小鱼想当然了,发现并不是一件容易的事情,涉及到了launch的上下文问题。
下一个launch比如要从上文中才能获取到某个参数的值,给一个代码例程
launch1.py
from launch import LaunchDescription from launch.substitutions import LaunchConfiguration from launch.actions import IncludeLaunchDescription from launch.launch_description_sources import PythonLaunchDescriptionSource from launch.substitutions import ThisLaunchFileDir def generate_launch_description(): test_p = LaunchConfiguration('test_p', default='12345678') return LaunchDescription([ IncludeLaunchDescription( PythonLaunchDescriptionSource([ThisLaunchFileDir(), '/launch2.py']), launch_arguments={'test_p': test_p}.items(), ) ])
launch2.py
from launch import LaunchDescription from launch.actions import OpaqueFunction from launch.substitutions import LaunchConfiguration from launch_ros.actions import SetParameter def launch_setup(context, *args, **kwargs): test_p = LaunchConfiguration('test_p') print(f"use_sim_time: {test_p.perform(context)}") set_test_p = SetParameter(name="test_p", value=test_p) return [ set_test_p, ] def generate_launch_description(): return LaunchDescription([ OpaqueFunction(function=launch_setup), ])
运行打印
[INFO] [launch]: All log files can be found below [INFO] [launch]: Default logging verbosity is set to INFO use_sim_time: 12345678
-
小 小鱼 从 中的 动手学ROS2 移动了该主题
-
这个代码是在launch1.py里调用launch2.py吧,参数是传给launch2.py了,但是怎么把参数传给launch2.py里的节点又是个大难题啊.
有没有大佬可以补充一下从launch1.py传参到launch2.py里的节点的代码呀。