Is it possible to define a custom array type in ROS2?
Hello everyone,
here's my situation: I have a buffer in RAM that is shared between two applications, first is a C program that collects frames and metadata from a camera, fills the buffer with that data and signals the other application, which is a ROS2 node, to grab that data. The ROS2 node is then supposed to pack the data into a sensor_msgs/Image message and publish it so it can be recorded with rosbag record.
Image message has a 'uint8[] data' field which translates into 'vector<uint8> data' on ROS2. The problem is that our whole system is time critical and we cannot afford to copy data from the mentioned buffer in RAM to that vector and there is no mechanism to make a C++ vector's data field point to some fixed address where data is.
So, the question is whether it is possible to create a custom array type for ROS2 messages or not. I would like it to be a regular array so I can just point it to where the data is to avoid time consuming copy operation. If there is some other mechanism to achieve this, info on that would be much appreciated.
Thank you in advance.
I believe there is, it's called placement new. Whether that is usable here is something else.
Perhaps in combination with a custom allocator you could force the ROS msg to be placed in a buffer you've already allocated.
How that'd interact with the serialisation phase in the ROS 2 publication pipeline I wouldn't know though.
Have you considered making the two nodes run on separate threads, then just communicating between them directly? Otherwise, I think that a custom allocator is a good candidate.