Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declare parameters in topic namespace for subscriber #70

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions compressed_image_transport/src/compressed_subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

#include <limits>
#include <vector>
#include <iostream>

constexpr const char* kDefaultMode = "unchanged";

Expand All @@ -67,24 +68,31 @@ void CompressedSubscriber::subscribeImpl(
typedef image_transport::SimpleSubscriberPlugin<CompressedImage> Base;
Base::subscribeImpl(node, base_topic, callback, custom_qos);
std::string mode;
rcl_interfaces::msg::ParameterDescriptor mode_description;
mode_description.name = "mode";
mode_description.type = rcl_interfaces::msg::ParameterType::PARAMETER_STRING;
mode_description.description = "OpenCV imdecode flags to use";
mode_description.read_only = false;
mode_description.additional_constraints = "Supported values: [unchanged, gray, color]";
mode = node->declare_parameter("mode", kDefaultMode, mode_description);

if (mode == "unchanged") {
config_.imdecode_flag = cv::IMREAD_UNCHANGED;
} else if (mode == "gray") {
config_.imdecode_flag = cv::IMREAD_GRAYSCALE;
} else if (mode == "color") {
config_.imdecode_flag = cv::IMREAD_COLOR;
} else {
RCLCPP_ERROR(logger_, "Unknown mode: %s, defaulting to 'unchanged", mode.c_str());
config_.imdecode_flag = cv::IMREAD_UNCHANGED;
uint ns_len = node->get_effective_namespace().length();
std::string param_base_name = base_topic.substr(ns_len);
std::replace(param_base_name.begin(), param_base_name.end(), '/', '.');
std::string mode_param_name = param_base_name + ".mode";
if (!node->has_parameter(mode_param_name))
{
rcl_interfaces::msg::ParameterDescriptor mode_description;
mode_description.name = "mode";
mode_description.type = rcl_interfaces::msg::ParameterType::PARAMETER_STRING;
mode_description.description = "OpenCV imdecode flags to use";
mode_description.read_only = false;
mode_description.additional_constraints = "Supported values: [unchanged, gray, color]";
mode = node->declare_parameter(mode_param_name, kDefaultMode, mode_description);
if (mode == "unchanged") {
config_.imdecode_flag = cv::IMREAD_UNCHANGED;
} else if (mode == "gray") {
config_.imdecode_flag = cv::IMREAD_GRAYSCALE;
} else if (mode == "color") {
config_.imdecode_flag = cv::IMREAD_COLOR;
} else {
RCLCPP_ERROR(logger_, "Unknown mode: %s, defaulting to 'unchanged", mode.c_str());
config_.imdecode_flag = cv::IMREAD_UNCHANGED;
}
}

}


Expand Down