Open AiVerisimilitude opened 5 months ago
@AiVerisimilitude basically in this way can we have publishers and subscribers that supports both intra-process/type-adaptation as well as inter-process/compression-plugins depending on the situation, without recompilation?
And, what happens with intra-process enabled, but no type-adapter? Will zero-copy work?
@roncapat Current subscribers are not really touched, I only added a new way to get one that is type adapted which is based on rclcpp::Subscriber directly. And yes, you are correct that you can have a plublisher that supports both intra-process/type-adapted as well as inter-process/compression without recompilation. Compression plugins remain unaffected by this change but there is the step of conversion if you have compression plugins. This is also something I want to think about the current behavior of rclcpp::publisher since if we have both a inter-process raw subscriber (or intra process disabled) and a compression subscriber, if we publish a type-adapted type, serialization of the type adapted type will happen 2x, once in rclcpp::Publisher#316 rclcpp::TypeAdapter<MessageT>::convert_to_ros_message(*msg, ros_msg);
and again in our publisherBase rclcpp::TypeAdapter<MessageT>::convert_to_ros_message(*msg, *shared_msg)
(since the compression plugins require the image message).
As for zero copy, I believe it does but it depends on the result of this call in rclcpp::Publisher#278 auto unique_msg = this->duplicate_ros_message_as_unique_ptr(msg);
part of publish(const T & msg)
. If this does not trigger a copy when given a sensor_msgs::msg::Image::ConstSharedPtr
then yes, it supports zero copy, otherwise no >_<
Thank you for the feedback! Much appreciated.
As the title suggests, we added type adaptation to the raw transport. To achieve this, there are a couple of modifications that were made:
Plugins don't mesh well with the idea of type-adaptation without knowing the type beforehand. So here the design decision was to collapse the raw publish plugin into an implicit part of the image_tranport publisher.
Since the publisher now needs to be templated for supporting different type-adapted types, a new higher level publisher is needed which is named
PublisherBase
with an alias created for backwards compatibilityusing Publisher = PublisherBase<sensor_msg::mgs::Image>;
Usage:
Type adaptation is only supported on the raw transport. Here is an example of a type for usage in type-adaptation:
And an alias for easier to read code:
We can create a type-adapted publisher with:
And publish the type-adapted message with:
A subscriber can be used the normal way without type-adaptation:
Or with type-adaptation:
As final notes, this PR takes a backwards compatible approach so that it does not break existing code, but I don't necessarily like the structure. For example, I don't like having 2
create
functions, I would rather have one, but that would break existing implementations as we would need to return a shared pointer (in line with usage of regular publishers). However, I do find it a good starting point for discussion on how to move forward.