ros2 config_error ai_generated true

ros2启动:替换错误:启动文件中未定义变量'my_var'

ros2 launch: Substitution error: Undefined variable 'my_var' in launch file

ID: ros2/launch-file-substitution-undefined-variable

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

版本兼容性

版本状态引入弃用备注
Humble active
Iron active
Jazzy active
Rolling active

根因分析

启动文件使用了未声明或未作为参数传递的变量替换(例如$(var my_var)),导致解析失败。

English

A launch file uses a variable substitution (e.g., $(var my_var)) that hasn't been declared or passed as an argument, causing a parse failure.

generic

官方文档

https://docs.ros.org/en/rolling/Tutorials/Intermediate/Launch/Using-Substitutions.html

解决方案

  1. Add a DeclareLaunchArgument for the variable in the launch file.
  2. Pass the variable as a command-line argument when launching.
  3. Use a default value in the substitution to avoid undefined errors.

无效尝试

常见但无效的做法:

  1. Using $(env my_var) instead of $(var my_var) without setting environment variable 60% 失败

    Substitution type mismatch; $(env) expects an environment variable, not a launch argument.

  2. Adding the variable directly in the launch file without DeclareLaunchArgument 70% 失败

    ROS2 launch requires explicit declaration; inline usage without declaration still fails.

  3. Setting the variable in a separate YAML config file without including it 50% 失败

    YAML config files aren't automatically loaded; they must be included via IncludeLaunchDescription.