ros2
runtime_error
ai_generated
true
rclpy.exceptions.ParameterAlreadyDeclaredException: Parameter 'use_sim_time' has already been declared
ID: ros2/parameter-already-declared
92%Fix Rate
90%Confidence
3Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 2 | active | — | — | — |
Root Cause
declare_parameter() called twice for the same parameter name. Common when mixing automatic and manual declaration.
genericWorkarounds
-
92% success Use has_parameter() before declare_parameter()
if not self.has_parameter('my_param'): self.declare_parameter('my_param', default_value) -
95% success Declare all parameters once in __init__ and use get_parameter() elsewhere
-
85% success Set automatically_declare_parameters_from_overrides=False if declaring manually
Dead Ends
Common approaches that don't work:
-
Catch the exception and ignore it
70% fail
Silently uses the first declaration value; later code may expect a different default
-
Undeclare then re-declare the parameter
65% fail
Causes a brief period where the parameter does not exist; external observers may see inconsistent state