多个YAML文件在ROS2启动中。

huangapple go评论78阅读模式
英文:

multiple yaml files in ros2 launch

问题

In ROS2 (Foxy), you can load multiple YAML files in a launch file as follows:

  1. def generate_launch_description():
  2. path_file1 = 'file1.yaml'
  3. path_file2 = 'file2.yaml'
  4. file_parameters1 = os.path.join(
  5. get_package_share_directory('pkg1'),
  6. 'config',
  7. path_file1
  8. )
  9. file_parameters2 = os.path.join(
  10. get_package_share_directory('pkg1'),
  11. 'config',
  12. path_file2
  13. )
  14. return LaunchDescription([
  15. Node(
  16. package="pkg1",
  17. executable="node1",
  18. name="node1",
  19. output="screen",
  20. parameters=[file_parameters1, file_parameters2]
  21. )
  22. ])

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

  1. <node name="node1" type="node1" pkg="pkg1" output="log">
  2. <rosparam command="load" file="$file1.yaml"/>
  3. <rosparam command="load" file="$file2.yaml"/>
  4. </node>

i want to know if we can do the same in ros2 (foxy)
i know that i can load one file like this

  1. def generate_launch_description():
  2. path_file = 'test.yaml'
  3. file_parameters = os.path.join(
  4. get_package_share_directory('pkg1'),
  5. 'config',
  6. path_file
  7. )
  8. return LaunchDescription([
  9. Node(
  10. package="pkg1",
  11. executable="node1",
  12. name="node1",
  13. output="screen",
  14. parameters=[file_parameters
  15. ]
  16. )
  17. ])

there is a way to load 2 yaml files in ros2?

答案1

得分: 0

是的,你可以简单地为第二个 .yaml 文件定义另一个路径,并将其附加到参数中。

示例:

  1. def generate_launch_description():
  2. first_path_file = 'test.yaml'
  3. second_path_file = 'second_test.yaml'
  4. first_file_parameters = os.path.join(
  5. get_package_share_directory('pkg1'),
  6. 'config',
  7. first_path_file
  8. )
  9. second_file_parameters = os.path.join(
  10. get_package_share_directory('pkg1'),
  11. 'config',
  12. second_path_file
  13. )
  14. return LaunchDescription([
  15. Node(
  16. package="pkg1",
  17. executable="node1",
  18. name="node1",
  19. output="screen",
  20. parameters=[first_file_parameters, second_file_parameters]
  21. )
  22. ])

请注意,你可以在一个 .yaml 文件中为多个节点定义参数,这可能会是一个更清晰的解决方案。

英文:

Yes you can simply define another path for the second .yaml and append it to the parameters.

Example:

  1. def generate_launch_description():
  2. first_path_file = 'test.yaml'
  3. second_path_file = 'second_test.yaml'
  4. first_file_parameters = os.path.join(
  5. get_package_share_directory('pkg1'),
  6. 'config',
  7. path_file
  8. )
  9. second_file_parameters = os.path.join(get_package_share_directory(
  10. ('pkg1'),
  11. 'config',
  12. second_path_file)
  13. return LaunchDescription([
  14. Node(
  15. package="pkg1",
  16. executable="node1",
  17. name="node1",
  18. output="screen",
  19. parameters=[first_file_parameters, second_file_parameters
  20. ]
  21. )
  22. ])

Mind that you can define parameters for multiple nodes in one .yaml, this could be a cleaner solution.

huangapple
  • 本文由 发表于 2023年4月13日 15:08:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76002578.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定