Add rosidl_buffer and rosidl_buffer_backend for native Buffer type support#941
Add rosidl_buffer and rosidl_buffer_backend for native Buffer type support#941
Conversation
cee2760 to
ea59c56
Compare
…pport Signed-off-by: CY Chen <cyc@nvidia.com>
Signed-off-by: CY Chen <cyc@nvidia.com>
Signed-off-by: CY Chen <cyc@nvidia.com>
Signed-off-by: CY Chen <cyc@nvidia.com>
326b4f8 to
c53b788
Compare
|
Pulls: #941 |
Signed-off-by: CY Chen <cyc@nvidia.com>
Signed-off-by: CY Chen <cyc@nvidia.com>
a19b54f to
6ec582e
Compare
…nter Signed-off-by: CY Chen <cyc@nvidia.com>
Signed-off-by: CY Chen <cyc@nvidia.com>
|
Pulls: #941 |
A new package was added to `rcl_logging` called `rcl_logging_implementation`. It depends on `rcpputils`, which I wasn't able to get building. Therefore, we are skipping building that package using `COLCON_IGNORE`. https://github.com/ros2/rclc needs to be pinned to an older version until ros2/rcl#1269 is added in https://github.com/micro-ROS/rcl. https://github.com/ros2/rosidl needs to be pinned to an older version due to breaking changes made with ros2/rosidl#941 This PR also fixes micro-ROS#251.
) ROS 2 Rolling merged ros2/rosidl#941 and ros2/rosidl#942 as part of the native buffer feature. The ROSIDL_RUNTIME_C__PRIMITIVE_SEQUENCE macro now emits two extra boolean fields (is_rosidl_buffer, owns_rosidl_buffer) in every primitive sequence struct, growing them from 24 to 32 bytes. Non-primitive sequences (e.g. Parameter__Sequence) are unchanged at 24 bytes. The rclnodejs code generator produces ref-struct-di definitions for these sequence types. Because the generated layout lacked the new fields, every message containing a primitive sequence had misaligned field offsets when serialized, causing Fast DDS to segfault in get_serialized_size_* during rcl_publish. Changes: 1. rosidl_gen/templates/message-template.js — Detect Rolling+ at generation time via DistroUtils.getDistroId() and compute needsRosidlBufferFields once per message. Conditionally emit is_rosidl_buffer and owns_rosidl_buffer in the generated sequence struct only for primitive-package types (Bool, Byte, Int8, …, Float64, String) on Rolling+. Generated files get clean, static struct definitions with no runtime require() or ternary. 2. .github/workflows/linux-x64-build-and-test.yml — Add rosidl_buffer_py and pybind11 to rosdep --skip-keys for the Rolling nightly install, since these new packages from the native buffer feature have unresolvable rosdep keys in the tarball context. Verified: Rolling: test-parameters (33), test-parameter-service (9), test-action-client (19) — all pass. Jazzy: test-parameters (33), test-parameter-service (9), test-action-client (18+1 pending) — all pass. Fix: #1481
A new package was added to `rcl_logging` called `rcl_logging_implementation`. It depends on `rcpputils`, which I wasn't able to get building. Therefore, we are skipping building that package using `COLCON_IGNORE`. https://github.com/ros2/rclc needs to be pinned to an older version until ros2/rcl#1269 is added in https://github.com/micro-ROS/rcl. https://github.com/ros2/rosidl needs to be pinned to an older version due to breaking changes made with ros2/rosidl#941 This PR also fixes micro-ROS#251.
A new package was added to `rcl_logging` called `rcl_logging_implementation`. It depends on `rcpputils`, which I wasn't able to get building. Therefore, we are skipping building that package using `COLCON_IGNORE`. https://github.com/ros2/rclc needs to be pinned to an older version until ros2/rcl#1269 is added in https://github.com/micro-ROS/rcl. https://github.com/ros2/rosidl needs to be pinned to an older version due to breaking changes made with ros2/rosidl#941
Compiling pcl_ros package in rolling results in errors like this:
In file included from
/build/perception_pcl-release-release-rolling-pcl_ros-2.8.0-1/tools/combined_pointcloud_to_pcd.cpp:47:
/ros-rolling-pcl-conversions-2.8.0-r1/include/pcl_conversions/pcl_conversions/pcl_conversions.h: In
function 'void pcl_conversions::moveFromPCL(pcl::PCLImage&, sensor_msgs::msg::Image&)':
/ros-rolling-pcl-conversions-2.8.0-r1/include/pcl_conversions/pcl_conversions/pcl_conversions.h:172:16:
error: 'using sensor_msgs::msg::Image_<std::allocator<void> >::_data_type = class
rosidl::Buffer<unsigned char, std::allocator<unsigned char> >' {aka 'class rosidl::Buffer<unsigned
char, std::allocator<unsigned char> >'} has no member named 'swap'
172 | image.data.swap(pcl_image.data);
| ^~~~
These are caused by ros2/rosidl#941 and
followup PRs, which change the type of `uint8[]` message fields from
`std::vector<uint8_t>` to `rosidl::Buffer<uint8_t>`. To maintain the
previous functionality, explicit typecasting is needed at a few
places. This causes invocation of the conversion operator [1], which
returns a reference to the underlying std::vector.
[1]: https://github.com/ros2/rosidl/blob/7c4e0f90f2979c16c906d65058fc7966360f52e1/rosidl_buffer/include/rosidl_buffer/buffer.hpp#L420
Signed-off-by: Michal Sojka <michal.sojka@cvut.cz>
Compiling pcl_ros package in rolling results in errors like this:
In file included from
/build/perception_pcl-release-release-rolling-pcl_ros-2.8.0-1/tools/combined_pointcloud_to_pcd.cpp:47:
/ros-rolling-pcl-conversions-2.8.0-r1/include/pcl_conversions/pcl_conversions/pcl_conversions.h: In
function 'void pcl_conversions::moveFromPCL(pcl::PCLImage&, sensor_msgs::msg::Image&)':
/ros-rolling-pcl-conversions-2.8.0-r1/include/pcl_conversions/pcl_conversions/pcl_conversions.h:172:16:
error: 'using sensor_msgs::msg::Image_<std::allocator<void> >::_data_type = class
rosidl::Buffer<unsigned char, std::allocator<unsigned char> >' {aka 'class rosidl::Buffer<unsigned
char, std::allocator<unsigned char> >'} has no member named 'swap'
172 | image.data.swap(pcl_image.data);
| ^~~~
These are caused by ros2/rosidl#941 and
followup PRs, which change the type of `uint8[]` message fields from
`std::vector<uint8_t>` to `rosidl::Buffer<uint8_t>`. To maintain the
previous functionality, explicit typecasting is needed at a few
places. This causes invocation of the conversion operator [1], which
returns a reference to the underlying std::vector.
[1]: https://github.com/ros2/rosidl/blob/7c4e0f90f2979c16c906d65058fc7966360f52e1/rosidl_buffer/include/rosidl_buffer/buffer.hpp#L420
Signed-off-by: Michal Sojka <michal.sojka@cvut.cz>
Compiling this in rolling results in the following error:
/build/bag2_to_image-release-release-rolling-bag2_to_image-0.1.1-1/src/bag2_to_image.cpp: In constructor 'bag2_to_image::Bag2ToImageNode::Bag2ToImageNode(const rclcpp::NodeOptions&)':
/build/bag2_to_image-release-release-rolling-bag2_to_image-0.1.1-1/src/bag2_to_image.cpp:165:52: error: no matching function for call to 'cv::Mat::Mat(sensor_msgs::msg::CompressedImage_<std::allocator<void> >::_data_type&)'
165 | auto mat = cv::imdecode(cv::Mat(image->data), imdecode_flag_);
| ^
These are caused by ros2/rosidl#941 and
followup PRs, which change the type of `uint8[]` message fields from
`std::vector<uint8_t>` to `rosidl::Buffer<uint8_t>`. To maintain the
previous functionality, explicit typecasting is needed. This causes
invocation of the conversion operator [1], which returns a reference
to the underlying std::vector.
[1]: https://github.com/ros2/rosidl/blob/7c4e0f90f2979c16c906d65058fc7966360f52e1/rosidl_buffer/include/rosidl_buffer/buffer.hpp#L420
Signed-off-by: Michal Sojka <michal.sojka@cvut.cz>
Compiling this in rolling results in the following error:
/build/bag2_to_image-release-release-rolling-bag2_to_image-0.1.1-1/src/bag2_to_image.cpp: In constructor 'bag2_to_image::Bag2ToImageNode::Bag2ToImageNode(const rclcpp::NodeOptions&)':
/build/bag2_to_image-release-release-rolling-bag2_to_image-0.1.1-1/src/bag2_to_image.cpp:165:52: error: no matching function for call to 'cv::Mat::Mat(sensor_msgs::msg::CompressedImage_<std::allocator<void> >::_data_type&)'
165 | auto mat = cv::imdecode(cv::Mat(image->data), imdecode_flag_);
| ^
These are caused by ros2/rosidl#941 and
followup PRs, which change the type of `uint8[]` message fields from
`std::vector<uint8_t>` to `rosidl::Buffer<uint8_t>`. To maintain the
previous functionality, explicit typecasting is needed. This causes
invocation of the conversion operator [1], which returns a reference
to the underlying std::vector.
[1]: https://github.com/ros2/rosidl/blob/7c4e0f90f2979c16c906d65058fc7966360f52e1/rosidl_buffer/include/rosidl_buffer/buffer.hpp#L420
Signed-off-by: Michal Sojka <michal.sojka@cvut.cz>
Description
This pull request adds
rosidl_bufferandrosidl_buffer_backendpackages - core C++ buffer types for the ROS 2 native buffer feature. This package introducesrosidl::Buffer<T>, a polymorphic container that's designed to replacestd::vector<T>foruint8[]message fields (to be adopted in later pull requests; we focus on only the core buffer types in this pull request.) The native buffer type and its backend class enable vendor-specific memory buffer implementation (CUDA, ROCm, etc.) while maintaining backward compatibility for existing CPU-basedstd::vector<T>user code.This pull request consists of the following key components:
Buffer<T>: PIMPL-based container providingstd::vector<T>-compatible API. All vector-compatible operations (element access, iterators, modifiers) are CPU-only and throwstd::runtime_errorfor non-CPU backends. Backend management APIs (get_backend_type(),get_impl(),to_vector()) work for all backends.BufferImplBase<T>: Minimal abstract base class of buffer implementation. All backend-specific APIs are to be provided by the vendor-specific backend implementations.CpuBufferImpl<T>: CPU-based buffer implementation wrappingstd::vector<T>.BufferBackend: Abstract interface for vendor-specific buffer backend implementations.Is this user-facing behavior change?
This pull request does not change existing behavior.
When adopted in later pull requests, message types with
uint8[]fields (e.g.,sensor_msgs/msg/Image.data) will userosidl::Buffer<uint8_t>instead ofstd::vector<uint8_t>. For CPU backends (the default),Buffer<T>is a transparent drop-in replacement.Did you use Generative AI?
Yes. Claude (claude-4.6-opus) via Cursor was used to assist with the
std::vector<T>compatibility feature in therosidl::Buffer<T>class and generate portions of the unit tests.Additional Information
This package/PL is part of the broader ROS2 native buffer feature introduced in this post.