ROS2-2001
ros2
config_error
ai_generated
true
ros2 launch:替换错误:参数 'my_param' 期望类型 'double' 但得到 'integer'
ros2 launch: Substitution error: parameter 'my_param' expected type 'double' but got 'integer'
ID: ros2/ros2-launch-parameter-substitution-type-mismatch
90%修复率
85%置信度
1证据数
2024-01-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| ros2:humble | active | — | — | — |
| ros2:iron | active | — | — | — |
| ros2:rolling | active | — | — | — |
| launch:2.0.0 | active | — | — | — |
根因分析
启动文件使用的替换结果与声明的参数类型不兼容(例如整数 vs 双精度浮点数),因为 LaunchConfiguration 或 Python 替换返回了 int 而非 float。
English
Launch file uses a substitution that evaluates to a type incompatible with the declared parameter type (e.g., integer vs double) due to LaunchConfiguration or Python substitution returning an int instead of float.
官方文档
https://docs.ros.org/en/humble/Tutorials/Intermediate/Launch/Using-Substitutions.html解决方案
-
使用 PythonExpression 显式将替换结果转换为期望类型。示例: from launch.substitutions import PythonExpression param_value = PythonExpression(['float(', LaunchConfiguration('my_param'), ')']) 这将强制替换结果为浮点数。 -
在启动文件中使用类型化替换(如 FloatSubstitution,如果可用),或确保 LaunchConfiguration 默认值为浮点数: from launch.substitutions import LaunchConfiguration param = LaunchConfiguration('my_param', default=0.0) # 默认值为浮点数
无效尝试
常见但无效的做法:
-
Changing the parameter type in the node's declaration to match the substitution type
50% 失败
The node may expect a specific type for correct operation; changing the declaration can cause runtime errors in the node.
-
Wrapping the substitution in str() without converting to the correct numeric type
90% 失败
String substitution will be interpreted as a string, not a number, causing a different type mismatch error.