From f724da5d37d3a9f88ee38d2aea05899679c3c448 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 28 Mar 2024 23:16:11 +0100 Subject: [PATCH] Fix #259 - `ParameterAlreadyDeclaredException` for parameter `position_proportional_gain` (backport #261) (#262) Signed-off-by: Alejandro Hernandez Cordero Co-authored-by: Patrick Roncagliolo Co-authored-by: Alejandro Hernandez Cordero --- ign_ros2_control/src/ign_system.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ign_ros2_control/src/ign_system.cpp b/ign_ros2_control/src/ign_system.cpp index 6f8c8f65..be4c3f08 100644 --- a/ign_ros2_control/src/ign_system.cpp +++ b/ign_ros2_control/src/ign_system.cpp @@ -182,8 +182,13 @@ bool IgnitionSystem::initSim( constexpr double default_gain = 0.1; - this->dataPtr->position_proportional_gain_ = this->nh_->declare_parameter( - "position_proportional_gain", default_gain); + try { + this->dataPtr->position_proportional_gain_ = this->nh_->declare_parameter( + "position_proportional_gain", default_gain); + } catch (rclcpp::exceptions::ParameterAlreadyDeclaredException & ex) { + this->nh_->get_parameter( + "position_proportional_gain", this->dataPtr->position_proportional_gain_); + } RCLCPP_INFO_STREAM( this->nh_->get_logger(),