最近在跟着小鱼老师的动手学ros2,准备重新把ros2的基础打一遍,鱼香ros yyds!(不是打广告
在编写ROS2 launch.py文件的过程中经常需要定义launch_ros.actions中的Node类对象。其中output具体有啥作用一直令我费解,不如做个小实验,看看output给定不同参数都有什么不同的效果。例子就用小鱼老师教程里的村子们,village.launch.py
那么output可以设为啥呢?搜了好一会没找到,不如写一个whatever进去 (๑•̀ㅂ•́)و✧
ValueError: whatever is not a valid standard output config i.e. "screen", "log" or "both"
哈哈果然报错了,贴心的开发者们提示了output的标准参数。
于是发现output可以设为‘screen’、‘log’ 以及‘both’。
screen
输出到屏幕,在控制台中可以看到输出(get_logger()、std::cout),同时$ROS_HOME/log下也将有日志写入(注:$ROS_HOME默认路径为~/.ros)。但是通过std::cout 进行输出的内容仅在控制台中显示。
log
输出到日志,发现使用std::cout输出的内容并没有显示到控制台,同时log中也并没有记录std::cout的内容。
both
顾名思义,就是screen和log两个都要。就结果而言,控制台中get_logger()和std::cout的内容都输出了,log中仍然没有发生什么变化。
总结
附上ROS wiki里面的解释:http://wiki.ros.org/roslaunch/XML/node
output="log|screen"(optional)
- If 'screen', stdout/stderr from the node will be sent to the screen. If 'log', the stdout/stderr output will be sent to a log file in $ROS_HOME/log, and stderr will continue to be sent to screen. The default is 'log'.
个人体验下来,用screen或者both就完事了,不必太过纠结于这点,了解即可。 ┑( ̄Д  ̄)┍