image_common
image_common copied to clipboard
Can't remap topic name and set hint at the same time;
OS: Ubuntu 20.04 ROS: Galactic Verions: 2.3.0-3 installed from Debian
I am trying to create a generic ROS2 node that subscribes to an image topic of a user's choice (through remapping of a topic name) and a user can in addition set the transport hint. Pretty straight forward, this is how image_saver
from the image_view
package used to work on ROS1
node->declare_parameter("transport", "raw");
std::string transport = node->get_parameter("transport").get_value<std::string>();
image_sub_ = image_transport::create_subscription(
&(*node), "image", std::bind(&MyClass::imageCallback, this, std::placeholders::_1), transport);
I run my node with ros2 run my_package my_node --ros-args -r image:=/my_image_topic/image_raw -p transport:=compressed
but the output of ros2 node info my_node
shows:
/my_node
Subscribers:
/image/compressed: sensor_msgs/msg/CompressedImage
If I don't set the parameter from the command line the remapping of the topic name works and I get:
/my_node
Subscribers:
/my_image_topic/image_raw: sensor_msgs/msg/Image
I have also tried doing this using TransportHints
and creating the subscriber with it_.subscribe("image", 10, &MyClass::imageCallback, this, &hints);
, and the overwriting the image_transport
parameter; The first problem here is that this parameter from TransportHints is never declared, so I had to declare it from my node in order to overwrite it; But then the behavior is still the same; We can either remap the topic name or change the hint but not both at the same time;
I also tried this out with the image_saver
node from image_view
package on ROS2 and could not get that one to run either;
I suspect that this might be a bug somewhere in the code when resolving names of topics and parameters; My current workaround is to set both the topic name and the hint from parameters;
Please ask this question on ROS Answers. Be sure to provide your complete code and the complete steps that you followed so that others can try to reproduce the problem.