Hello!
I am trying to modify an existing pointcloud2 by adding a new field to the pointcloud. This new field will be filled with zeros, except when a condition is met (for this example, i just placed when the field azimuth of a point is greater then 10), which should change the value of the new field to 20.
How do I write this new field to my bag file? I am not being able to modify the pointcloud_msg object.
bag_file = 'path_to_my_bag_file.bag"
bag = rosbag(bag_file);
pointcloud_msg = select(bag, 'Topic', '/my_pointcloudtopic');
msgs = readMessages(pointcloud_msg);
for message_number = 1:numel(msgs) %loop over all messages of the desired topic
msg = msgs{message_number};
num_points = msg.Width; %number of points in each message
vector_zeros = single(zeros(num_points, 1)); % Creates a vector with x elements, initialized to zero
all_azimuth_values_of_msg = readField(msg,'az');%Retrieve the azimuth coordinates of all points
for point = 1:num_points %read point by point
pt_az = all_azimuth_values_of_msg(point);
if pt_az > 10
vector_zeros(point) = 20;
end
%HERE I WANT TO APPEND THE NEW FIELD TO THE POINTCLOUD AND AFTER THE LOOP WRITE IT TO A NEW BAG FILE
end
end