英文:
multiple yaml files in ros2 launch
问题
In ROS2 (Foxy), you can load multiple YAML files in a launch file as follows:
def generate_launch_description():
path_file1 = 'file1.yaml'
path_file2 = 'file2.yaml'
file_parameters1 = os.path.join(
get_package_share_directory('pkg1'),
'config',
path_file1
)
file_parameters2 = os.path.join(
get_package_share_directory('pkg1'),
'config',
path_file2
)
return LaunchDescription([
Node(
package="pkg1",
executable="node1",
name="node1",
output="screen",
parameters=[file_parameters1, file_parameters2]
)
])
This code will load both "file1.yaml" and "file2.yaml" as parameters for your ROS2 node in the launch file.
英文:
there is a possibility to load 2 yaml files in launch file like in ros1?
in ros1 i can do
<node name="node1" type="node1" pkg="pkg1" output="log">
<rosparam command="load" file="$file1.yaml"/>
<rosparam command="load" file="$file2.yaml"/>
</node>
i want to know if we can do the same in ros2 (foxy)
i know that i can load one file like this
def generate_launch_description():
path_file = 'test.yaml'
file_parameters = os.path.join(
get_package_share_directory('pkg1'),
'config',
path_file
)
return LaunchDescription([
Node(
package="pkg1",
executable="node1",
name="node1",
output="screen",
parameters=[file_parameters
]
)
])
there is a way to load 2 yaml files in ros2?
答案1
得分: 0
是的,你可以简单地为第二个 .yaml 文件定义另一个路径,并将其附加到参数中。
示例:
def generate_launch_description():
first_path_file = 'test.yaml'
second_path_file = 'second_test.yaml'
first_file_parameters = os.path.join(
get_package_share_directory('pkg1'),
'config',
first_path_file
)
second_file_parameters = os.path.join(
get_package_share_directory('pkg1'),
'config',
second_path_file
)
return LaunchDescription([
Node(
package="pkg1",
executable="node1",
name="node1",
output="screen",
parameters=[first_file_parameters, second_file_parameters]
)
])
请注意,你可以在一个 .yaml 文件中为多个节点定义参数,这可能会是一个更清晰的解决方案。
英文:
Yes you can simply define another path for the second .yaml and append it to the parameters.
Example:
def generate_launch_description():
first_path_file = 'test.yaml'
second_path_file = 'second_test.yaml'
first_file_parameters = os.path.join(
get_package_share_directory('pkg1'),
'config',
path_file
)
second_file_parameters = os.path.join(get_package_share_directory(
('pkg1'),
'config',
second_path_file)
return LaunchDescription([
Node(
package="pkg1",
executable="node1",
name="node1",
output="screen",
parameters=[first_file_parameters, second_file_parameters
]
)
])
Mind that you can define parameters for multiple nodes in one .yaml, this could be a cleaner solution.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论