How to read and publish pointcloud2.pointfield[].name ?
Hi all,
[Linux Distribution: Ubuntu 18.04, ROS Distribution: ROS Melodic, 3D Camera: ifm 03D303]
Full disclaimer: I am new to ROS.
I would like to display the string data of name from the pointfield array. Any hints or direction to how would i go about doing this?
Appreciate the help.
#include <ros/ros.h>
// PCL specific includes
#include <sensor_msgs/PointCloud2.h>
#include <pcl_conversions/pcl_conversions.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <sensor_msgs/PointCloud.h>
#include <sensor_msgs/point_cloud_conversion.h>
ros::Publisher pub;
void
cloud_cb (const sensor_msgs::PointCloud2ConstPtr& input)
{
// Create a container for the data.
sensor_msgs::PointCloud2 output;
output = *input;
for(int i = 0; i < output.fields.size(); ++i) {
geometry_msgs::Point32 point
double arr[i];
arr[i] = output.point[i];
ROS_INFO("[%s]", arr.c_str());
}
pub.publish (output);
}
int
main (int argc, char** argv)
{
// Initialize ROS
ros::init (argc, argv, "test_node");
ros::NodeHandle nh;
// Create a ROS subscriber for the input point cloud
ros::Subscriber sub = nh.subscribe<sensor_msgs::PointCloud2> ("/ifm3d/camera/cloud", 1, cloud_cb);
// Create a ROS publisher for the output point cloud
pub = nh.advertise<sensor_msgs::PointCloud2> ("output", 1);
// Spin
ros::spin ();
}
You can get name of field from
output.fields.name
and publish it asstd_msgs/String
Appreciate your time, @Choco93.
I have edited my code to read
output.fields.name
but it mentionedhas no member named ‘name’
. Any lights on this?