ros-perception / image_transport_plugins

A set of plugins for publishing and subscribing to sensor_msgs/Image topics in representations other than raw pixel data.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[ROS 2] multiple publishers redeclare the same parameters

brawner opened this issue · comments

Strange issue that I only found with the CompressedPublisher, but it appears that its parameters are declared twice (or at least it does for me).

Compiling ros2, image_transport and image_transport_plugins from source, I just have an rclcpp node with an image_transport publisher (ubuntu bionic). Upon starting the node, the compressed_publisher library fails to load and throws an exception:

Failed to load plugin image_transport/compressed_pub, error string: parameter 'format' has already been declared

That also means that the reference that's set the first time around becomes invalidated when publish() is eventually called. I.e., I tried putting an if(node->has_parameter("format")) around the declare_parameter line and subscribing to the compressed topic results in the error:

Unknown compression type '', valid options are 'jpeg' and 'png'

Related to #52.
@lukaszmitka, @mjcarroll

Could you provide more details, so that we can reproduce the issue?
Which ROS version are you using, is it Dashing or Eloquent?
What is the minimal code that causes the problem, could you provide essential .cpp and CMakeLists.txt?

ROS version: ros2 master

To reproduce the exception, you just need to create two publishers or reassign the first publisher (my case).

#include "rclcpp/rclcpp.hpp"
#include "image_transport/image_transport.h"

int main() {
  rclcpp::init(0, nullptr);
  auto node = rclcpp::Node("image_transporter");
  auto publisher1 = image_transport::create_publisher(&node, "topic1");
  // Throws in compressed_publisher
  auto publisher2 = image_transport::create_publisher(&node, "topic2");
  publisher1.shutdown();
  publisher2.shutdown();
  // Also throws
  auto publisher3 = image_transport::create_publisher(&node, "topic3");
}

Running this compiled binary will cause an exception to be thrown.

The problem was the publisher declaring parameters in node scope instead of topic scope. The fix above makes publisher to declare set of parameters: format, jpeg_quality and png_level for each topic.