From 1cee33d03fd191fcbff4fec2b47dd3f1cf8ac6f7 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 28 Mar 2024 23:23:43 +0100 Subject: [PATCH] Fix #259 - `ParameterAlreadyDeclaredException` for parameter `position_proportional_gain` (backport #261) (#263) Signed-off-by: Alejandro Hernandez Cordero Co-authored-by: Patrick Roncagliolo Co-authored-by: Alejandro Hernandez Cordero --- gz_ros2_control/src/gz_system.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gz_ros2_control/src/gz_system.cpp b/gz_ros2_control/src/gz_system.cpp index eb07c6db..4ef5b28d 100644 --- a/gz_ros2_control/src/gz_system.cpp +++ b/gz_ros2_control/src/gz_system.cpp @@ -205,8 +205,13 @@ bool GazeboSimSystem::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(),