ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How to read coordinates via pointcloud2

asked 2020-04-25 04:32:44 -0500

dembele123 gravatar image

updated 2020-04-25 06:01:41 -0500

Sorry to bother! My sensor publisher publish pointcloud2 msg and I would like to cluster them and for that I need their XYZ coordinates and their intensity which I can see i rostopic echo of that topic but don't know how to read them in my program. My idea is to subscribe to that publisher and then make clustering with that dots. I would like to have them in struct array with xyz and intensity data and then write code for dbScan I tried various solutions from internet but won't work for me. Do you know maybe how can I read xyz and intensity from sensor_msgs::pointcloud2 in c++? Kind regards

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-04-25 04:50:24 -0500

gvdhoorn gravatar image

updated 2020-04-25 09:01:47 -0500

I'd recommend you take a look at the introductory tutorials about PCL usage in ROS 1, as they show you how to go from a sensor_msgs/PointCloud2 to the appropriate C++ data structure.

You don't need to (and don't want to) do that manually, nor do you want to use sensor_msgs/PointCloud2 directly.

Refer to wiki/perception_pcl/Tutorials for example code and some discussion, and refer to wiki/pcl/Overview for an overview of how PCL is used/integrated with ROS 1.


Edit:

I already tried it before and with this code

Ah. I must have missed that in your original question text. /s


The errors you show are linker errors. You are most likely not linking against the required libraries.

You'll have to make sure to link against pcl_ros and pcl_conversions.

Finally: do not post these sort of things in a comment. Edit your original question to add the new information (such as errors). Use the edit button/link for that.

edit flag offensive delete link more

Comments

Thank you for reply I already tried it before and with this code but gave me few errors which I cant solve. They say :

In function void pcl::detail::FieldMapper<pcl::PointXYZI>::operator()<pcl::fields::x>()': clustering.cpp:(.text._ZN3pcl6detail11FieldMapperINS_9PointXYZIEEclINS_6fields1xEEEvv[_ZN3pcl6detail11FieldMapperINS_9PointXYZIEEclINS_6fields1xEEEvv]+0x1b6): undefined reference topcl::console::print(pcl::console::VERBOSITY_LEVEL, char const*, ...)'

and same for y,z and inensity. my callback function is this one :' void Cluster_class::DbScan(const sensor_msgs::PointCloud2 &msg ){ pcl::PCLPointCloud2 pcl_pc2; pcl_conversions::toPCL(msg, pcl_pc2); pcl::PointCloud<pcl::pointxyzi> cloud; pcl::fromPCLPointCloud2(pcl_pc2, cloud); }'

dembele123 gravatar image dembele123  ( 2020-04-25 05:28:24 -0500 )edit

Yes, i forgot target_link_libraries pcl, thank you very much !

dembele123 gravatar image dembele123  ( 2020-04-25 06:00:09 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2020-04-25 04:32:44 -0500

Seen: 1,169 times

Last updated: Apr 25 '20