RCLPY_PARAM_OVERRIDE_001 ros2 config_error ai_generated true

rclpy.exceptions.ParameterNotSetException:参数 'my_param' 未设置,但通过 --ros-args -p 提供了覆盖

rclpy.exceptions.ParameterNotSetException: Parameter 'my_param' not set, but override was provided via --ros-args -p

ID: ros2/rclpy-parameter-override-not-applied

其他格式: JSON · Markdown 中文 · English
87%修复率
86%置信度
1证据数
2024-01-20首次发现

版本兼容性

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

根因分析

参数覆盖在节点声明之前提供,或者节点使用不同的名称/类型声明参数,导致覆盖被忽略。

English

The parameter override is provided before the node is declared, or the node declares the parameter with a different name/type, causing the override to be ignored.

generic

官方文档

https://docs.ros.org/en/humble/Tutorials/Intermediate/Parameters.html

解决方案

  1. Declare the parameter with a default value before using it in the node: self.declare_parameter('my_param', 'default_value'). Then ensure the override is passed in the launch file after the node is started: <node pkg="my_pkg" exec="my_node" name="my_node"><param name="my_param" value="override_value"/></node>
  2. Use the 'allow_undeclared_parameters' option in the node's constructor: node = rclpy.create_node('my_node', allow_undeclared_parameters=True). Then overrides will be applied regardless of declaration order.
  3. Move the parameter declaration to the beginning of the __init__ method, before any other node operations, and use the same name as in the override.

无效尝试

常见但无效的做法:

  1. Add more --ros-args -p arguments with different parameter names 90% 失败

    The issue is timing or naming, not the number of overrides; adding more won't fix the mismatch.

  2. Use a YAML file instead of command-line -p arguments 80% 失败

    YAML files have the same timing and naming constraints; the root cause remains.

  3. Set the parameter in the node's constructor before calling super().__init__() 85% 失败

    Parameters must be declared after the node is initialized; doing so before can cause undefined behavior.