From 3165a8c7cf533ea5fa50313203ba95be4af1d32f Mon Sep 17 00:00:00 2001
From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com>
Date: Mon, 20 May 2024 13:44:39 +0200
Subject: [PATCH] Get user specified parameters at startup (#46) (#51)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
(cherry picked from commit 46f3d22f3d5660529f4372aeed3fbcb41852a911)

Co-authored-by: john-maidbot <78750993+john-maidbot@users.noreply.github.com>
---
 .../src/draco_publisher.cpp                   | 23 +++++++++++++++----
 .../src/draco_subscriber.cpp                  |  5 ++++
 .../src/zlib_publisher.cpp                    |  1 +
 .../src/zstd_publisher.cpp                    |  1 +
 4 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/draco_point_cloud_transport/src/draco_publisher.cpp b/draco_point_cloud_transport/src/draco_publisher.cpp
index 7a1db1a..de20d13 100644
--- a/draco_point_cloud_transport/src/draco_publisher.cpp
+++ b/draco_point_cloud_transport/src/draco_publisher.cpp
@@ -88,6 +88,7 @@ void DracoPublisher::declareParameters(const std::string & base_topic)
   declareParam<int>(
     encode_speed_paramDescriptor.name, config_.encode_speed,
     encode_speed_paramDescriptor);
+  getParam<int>(encode_speed_paramDescriptor.name, config_.encode_speed);
 
   rcl_interfaces::msg::ParameterDescriptor decode_speed_paramDescriptor;
   decode_speed_paramDescriptor.name = "decode_speed";
@@ -102,6 +103,7 @@ void DracoPublisher::declareParameters(const std::string & base_topic)
   declareParam<int>(
     decode_speed_paramDescriptor.name, config_.decode_speed,
     decode_speed_paramDescriptor);
+  getParam<int>(decode_speed_paramDescriptor.name, config_.decode_speed);
 
   rcl_interfaces::msg::ParameterDescriptor encode_method_paramDescriptor;
   encode_method_paramDescriptor.name = "encode_method";
@@ -116,6 +118,7 @@ void DracoPublisher::declareParameters(const std::string & base_topic)
   declareParam<int>(
     encode_method_paramDescriptor.name, config_.encode_method,
     encode_method_paramDescriptor);
+  getParam<int>(encode_method_paramDescriptor.name, config_.encode_method);
 
   rcl_interfaces::msg::ParameterDescriptor deduplicate_paramDescriptor;
   deduplicate_paramDescriptor.name = "deduplicate";
@@ -123,6 +126,7 @@ void DracoPublisher::declareParameters(const std::string & base_topic)
   deduplicate_paramDescriptor.description =
     "Remove duplicate point entries.";
   declareParam<bool>(deduplicate_paramDescriptor.name, true, deduplicate_paramDescriptor);
+  getParam<bool>(deduplicate_paramDescriptor.name, config_.deduplicate);
 
   rcl_interfaces::msg::ParameterDescriptor force_quantization_paramDescriptor;
   force_quantization_paramDescriptor.name = "force_quantization";
@@ -133,6 +137,7 @@ void DracoPublisher::declareParameters(const std::string & base_topic)
   declareParam<bool>(
     force_quantization_paramDescriptor.name, config_.force_quantization,
     force_quantization_paramDescriptor);
+  getParam<bool>(force_quantization_paramDescriptor.name, config_.force_quantization);
 
   rcl_interfaces::msg::ParameterDescriptor quantization_POSITION_paramDescriptor;
   quantization_POSITION_paramDescriptor.name = "quantization_POSITION";
@@ -146,8 +151,9 @@ void DracoPublisher::declareParameters(const std::string & base_topic)
       .set__to_value(31)
       .set__step(1)});
   declareParam<int>(
-    quantization_POSITION_paramDescriptor.name, config_.quantization_NORMAL,
+    quantization_POSITION_paramDescriptor.name, config_.quantization_POSITION,
     quantization_POSITION_paramDescriptor);
+  getParam<int>(quantization_POSITION_paramDescriptor.name, config_.quantization_POSITION);
 
   rcl_interfaces::msg::ParameterDescriptor quantization_NORMAL_paramDescriptor;
   quantization_NORMAL_paramDescriptor.name = "quantization_NORMAL";
@@ -160,8 +166,9 @@ void DracoPublisher::declareParameters(const std::string & base_topic)
       .set__to_value(31)
       .set__step(1)});
   declareParam<int>(
-    quantization_NORMAL_paramDescriptor.name, config_.quantization_COLOR,
+    quantization_NORMAL_paramDescriptor.name, config_.quantization_NORMAL,
     quantization_NORMAL_paramDescriptor);
+  getParam<int>(quantization_NORMAL_paramDescriptor.name, config_.quantization_NORMAL);
 
   rcl_interfaces::msg::ParameterDescriptor quantization_COLOR_paramDescriptor;
   quantization_COLOR_paramDescriptor.name = "quantization_COLOR";
@@ -174,8 +181,9 @@ void DracoPublisher::declareParameters(const std::string & base_topic)
       .set__to_value(31)
       .set__step(1)});
   declareParam<int>(
-    quantization_COLOR_paramDescriptor.name, config_.quantization_TEX_COORD,
+    quantization_COLOR_paramDescriptor.name, config_.quantization_COLOR,
     quantization_COLOR_paramDescriptor);
+  getParam<int>(quantization_COLOR_paramDescriptor.name, config_.quantization_COLOR);
 
   rcl_interfaces::msg::ParameterDescriptor quantization_TEX_COORD_paramDescriptor;
   quantization_TEX_COORD_paramDescriptor.name = "quantization_TEX_COORD";
@@ -189,8 +197,9 @@ void DracoPublisher::declareParameters(const std::string & base_topic)
       .set__to_value(31)
       .set__step(1)});
   declareParam<int>(
-    quantization_TEX_COORD_paramDescriptor.name, config_.quantization_GENERIC,
+    quantization_TEX_COORD_paramDescriptor.name, config_.quantization_TEX_COORD,
     quantization_TEX_COORD_paramDescriptor);
+  getParam<int>(quantization_TEX_COORD_paramDescriptor.name, config_.quantization_TEX_COORD);
 
   rcl_interfaces::msg::ParameterDescriptor quantization_GENERIC_paramDescriptor;
   quantization_GENERIC_paramDescriptor.name = "quantization_GENERIC";
@@ -204,8 +213,9 @@ void DracoPublisher::declareParameters(const std::string & base_topic)
       .set__to_value(31)
       .set__step(1)});
   declareParam<int>(
-    quantization_GENERIC_paramDescriptor.name, config_.quantization_POSITION,
+    quantization_GENERIC_paramDescriptor.name, config_.quantization_GENERIC,
     quantization_GENERIC_paramDescriptor);
+  getParam<int>(quantization_GENERIC_paramDescriptor.name, config_.quantization_GENERIC);
 
   rcl_interfaces::msg::ParameterDescriptor expert_quantization_paramDescriptor;
   expert_quantization_paramDescriptor.name = "expert_quantization";
@@ -217,6 +227,7 @@ void DracoPublisher::declareParameters(const std::string & base_topic)
   declareParam<bool>(
     expert_quantization_paramDescriptor.name, config_.expert_quantization,
     expert_quantization_paramDescriptor);
+  getParam<bool>(expert_quantization_paramDescriptor.name, config_.expert_quantization);
 
   rcl_interfaces::msg::ParameterDescriptor expert_attribute_types_paramDescriptor;
   expert_attribute_types_paramDescriptor.name = "expert_attribute_types";
@@ -228,7 +239,9 @@ void DracoPublisher::declareParameters(const std::string & base_topic)
   declareParam<bool>(
     expert_attribute_types_paramDescriptor.name, config_.expert_attribute_types,
     expert_attribute_types_paramDescriptor);
+  getParam<bool>(expert_attribute_types_paramDescriptor.name, config_.expert_attribute_types);
 
+  // we call get param at runtime to get the latest value for these
   declareParam<std::string>("attribute_mapping.attribute_type.x", "POSITION");
   declareParam<std::string>("attribute_mapping.attribute_type.y", "POSITION");
   declareParam<std::string>("attribute_mapping.attribute_type.z", "POSITION");
diff --git a/draco_point_cloud_transport/src/draco_subscriber.cpp b/draco_point_cloud_transport/src/draco_subscriber.cpp
index eb404ca..68646de 100644
--- a/draco_point_cloud_transport/src/draco_subscriber.cpp
+++ b/draco_point_cloud_transport/src/draco_subscriber.cpp
@@ -50,10 +50,15 @@ namespace draco_point_cloud_transport
 void DracoSubscriber::declareParameters()
 {
   declareParam<bool>(std::string("SkipDequantizationPOSITION"), false);
+  getParam<bool>(std::string("SkipDequantizationPOSITION"), config_.SkipDequantizationPOSITION);
   declareParam<bool>(std::string("SkipDequantizationNORMAL"), false);
+  getParam<bool>(std::string("SkipDequantizationNORMAL"), config_.SkipDequantizationNORMAL);
   declareParam<bool>(std::string("SkipDequantizationCOLOR"), false);
+  getParam<bool>(std::string("SkipDequantizationCOLOR"), config_.SkipDequantizationCOLOR);
   declareParam<bool>(std::string("SkipDequantizationTEX_COORD"), false);
+  getParam<bool>(std::string("SkipDequantizationTEX_COORD"), config_.SkipDequantizationTEX_COORD);
   declareParam<bool>(std::string("SkipDequantizationGENERIC"), false);
+  getParam<bool>(std::string("SkipDequantizationGENERIC"), config_.SkipDequantizationGENERIC);
 
   auto param_change_callback =
     [this](std::vector<rclcpp::Parameter> parameters) -> rcl_interfaces::msg::SetParametersResult
diff --git a/zlib_point_cloud_transport/src/zlib_publisher.cpp b/zlib_point_cloud_transport/src/zlib_publisher.cpp
index 00f3f2d..fe763f1 100644
--- a/zlib_point_cloud_transport/src/zlib_publisher.cpp
+++ b/zlib_point_cloud_transport/src/zlib_publisher.cpp
@@ -56,6 +56,7 @@ void ZlibPublisher::declareParameters(const std::string & base_topic)
   declareParam<int>(
     encode_level_paramDescriptor.name, this->encode_level_,
     encode_level_paramDescriptor);
+  getParam<int>(encode_level_paramDescriptor.name, this->encode_level_);
 
   auto param_change_callback =
     [this](const std::vector<rclcpp::Parameter> & parameters) -> rcl_interfaces::msg::
diff --git a/zstd_point_cloud_transport/src/zstd_publisher.cpp b/zstd_point_cloud_transport/src/zstd_publisher.cpp
index 9806fb5..50bc705 100644
--- a/zstd_point_cloud_transport/src/zstd_publisher.cpp
+++ b/zstd_point_cloud_transport/src/zstd_publisher.cpp
@@ -61,6 +61,7 @@ void ZstdPublisher::declareParameters(const std::string & base_topic)
   declareParam<int>(
     encode_level_paramDescriptor.name, this->encode_level_,
     encode_level_paramDescriptor);
+  getParam<int>(encode_level_paramDescriptor.name, this->encode_level_);
 
   auto param_change_callback =
     [this](const std::vector<rclcpp::Parameter> & parameters) -> rcl_interfaces::msg::