RCLPY_PARAM_OVERRIDE_001 ros2 config_error ai_generated true

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

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

Also available as: JSON · Markdown · 中文
87%Fix Rate
86%Confidence
1Evidence
2024-01-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Humble active
Iron active
Jazzy active

Root Cause

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

中文

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

Official Documentation

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

Workarounds

  1. 90% success 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>
    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. 85% success 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.
    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. 80% success 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.
    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. 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.

Dead Ends

Common approaches that don't work:

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

    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% fail

    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% fail

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