ROS2-2001
ros2
config_error
ai_generated
true
ros2 launch: Substitution error: parameter 'my_param' expected type 'double' but got 'integer'
ID: ros2/ros2-launch-parameter-substitution-type-mismatch
90%Fix Rate
85%Confidence
1Evidence
2024-01-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| ros2:humble | active | — | — | — |
| ros2:iron | active | — | — | — |
| ros2:rolling | active | — | — | — |
| launch:2.0.0 | active | — | — | — |
Root Cause
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.
generic中文
启动文件使用的替换结果与声明的参数类型不兼容(例如整数 vs 双精度浮点数),因为 LaunchConfiguration 或 Python 替换返回了 int 而非 float。
Official Documentation
https://docs.ros.org/en/humble/Tutorials/Intermediate/Launch/Using-Substitutions.htmlWorkarounds
-
90% success Explicitly cast the substitution to the expected type using PythonExpression. Example: from launch.substitutions import PythonExpression param_value = PythonExpression(['float(', LaunchConfiguration('my_param'), ')']) This forces the substitution to evaluate to a float.
Explicitly cast the substitution to the expected type using PythonExpression. Example: from launch.substitutions import PythonExpression param_value = PythonExpression(['float(', LaunchConfiguration('my_param'), ')']) This forces the substitution to evaluate to a float. -
85% success In the launch file, use a typed substitution like FloatSubstitution if available, or ensure the LaunchConfiguration default is a float: from launch.substitutions import LaunchConfiguration param = LaunchConfiguration('my_param', default=0.0) # default as float
In the launch file, use a typed substitution like FloatSubstitution if available, or ensure the LaunchConfiguration default is a float: from launch.substitutions import LaunchConfiguration param = LaunchConfiguration('my_param', default=0.0) # default as float
中文步骤
使用 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) # 默认值为浮点数
Dead Ends
Common approaches that don't work:
-
Changing the parameter type in the node's declaration to match the substitution type
50% fail
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% fail
String substitution will be interpreted as a string, not a number, causing a different type mismatch error.