ros2 config_error ai_generated true

ros2 launch: 替换错误:在启动配置中找不到参数'my_arg'

ros2 launch: Substitution error: argument 'my_arg' not found in launch configuration

ID: ros2/ros2-launch-arg-substitution-not-found

其他格式: JSON · Markdown 中文 · English
90%修复率
88%置信度
1证据数
2023-06-20首次发现

版本兼容性

版本状态引入弃用备注
ROS2 Humble (launch 1.0.0) active
ROS2 Iron (launch 1.1.0) active
ROS2 Rolling (launch 1.2.0) active

根因分析

启动文件使用$(var my_arg)或类似替换,但该参数从未通过DeclareLaunchArgument声明。

English

A launch file uses $(var my_arg) or similar substitution for an argument that was never declared with DeclareLaunchArgument.

generic

官方文档

https://docs.ros.org/en/humble/Tutorials/Intermediate/Launch/Launch-system.html

解决方案

  1. 在使用参数之前,在启动文件中添加DeclareLaunchArgument:from launch.actions import DeclareLaunchArgument; ld.add_action(DeclareLaunchArgument('my_arg', default_value='default'))
  2. 如果参数是可选的,使用条件替换:$(var my_arg 'default_value')来提供默认值。

无效尝试

常见但无效的做法:

  1. Add the argument to the launch command line without declaring it in the file 80% 失败

    Arguments passed on the command line must match a declared argument; otherwise, ros2 launch ignores them.

  2. Use $(env my_arg) instead of $(var my_arg) 90% 失败

    Environment variables are not the same as launch arguments; the substitution syntax is different.