首先确保已经创建config、launch文件夹,文件夹下有对应的文件,创建的节点能够通过launch文件正常启动。
解决办法:
-
在setup.py文件中,仿照添加launch文件步骤,添加config文件夹
# add launch file (os.path.join('share', package_name), glob('launch/*launch.[pxy][yma]*')), # add config file (os.path.join('share', package_name), glob('config/*.[yma]*')),
-
在launch文件中增加config文件路径,并在节点中使用
config = os.path.join( get_package_share_directory('test_yaml'), # 'config', 把这个config注释掉 'test_yaml_config.yaml' ) Node( package='test_yaml', ... # load param from yaml parameters=[config] )
注意:# ‘config’, 把这个config注释掉
因为实际测试发现,在第1步添加config文件夹时,并没有生成文件夹。
-
注意yaml文件书写格式
test_node: # node name 这里必须填写对应的节点名称,或命名空间(如果有) # must declare ros__parameters ros__parameters: # test params test_param: 0.01
-
删除之前编译生成的文件夹,然后再重新编译,安装,启动
rm -rf build/ install/ log/