ros2
config_error
ai_generated
true
ros2 launch: Substitution error: Undefined variable 'my_var' in launch file
ID: ros2/launch-file-substitution-undefined-variable
90%Fix Rate
87%Confidence
1Evidence
2023-07-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| Humble | active | — | — | — |
| Iron | active | — | — | — |
| Jazzy | active | — | — | — |
| Rolling | active | — | — | — |
Root Cause
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中文
启动文件使用了未声明或未作为参数传递的变量替换(例如$(var my_var)),导致解析失败。
Official Documentation
https://docs.ros.org/en/rolling/Tutorials/Intermediate/Launch/Using-Substitutions.htmlWorkarounds
-
95% success Add a DeclareLaunchArgument for the variable in the launch file.
Add a DeclareLaunchArgument for the variable in the launch file.
-
90% success Pass the variable as a command-line argument when launching.
Pass the variable as a command-line argument when launching.
-
85% success Use a default value in the substitution to avoid undefined errors.
Use a default value in the substitution to avoid undefined errors.
中文步骤
Add a DeclareLaunchArgument for the variable in the launch file.
Pass the variable as a command-line argument when launching.
Use a default value in the substitution to avoid undefined errors.
Dead Ends
Common approaches that don't work:
-
Using $(env my_var) instead of $(var my_var) without setting environment variable
60% fail
Substitution type mismatch; $(env) expects an environment variable, not a launch argument.
-
Adding the variable directly in the launch file without DeclareLaunchArgument
70% fail
ROS2 launch requires explicit declaration; inline usage without declaration still fails.
-
Setting the variable in a separate YAML config file without including it
50% fail
YAML config files aren't automatically loaded; they must be included via IncludeLaunchDescription.