Point Cloud Handling in ROS

First we need to create a subscriber to the topic. It may be like:

ros::Subscriber sub = node_handle.subscribe("/3dcam/depth/points", 1, pc_cb);

Here, we have sub as the subscriber which is subscribing to the topic /3dcam/depth/points which we expect to get the point cloud messages from and pc_cb is the point cloud callback function. So, let’s look into the callback function.

First the function won’t return anything, so it is void. It will get the point cloud passed by reference and so we have the sensor_msgs::PointCloud2ConstPtr& as the type (& because it is passed by reference) in the arguments part as:

void pc_cb(const sensor_msgs::PointCloud2ConstPtr& in_ros_pc)

So what is that sensor_msgs::PointCloud2ConstPtr? It is a tyepdef for boost::shared_ptr! So what is a typedef and what is boost::shared_ptr and how did you know that at first place?

Okay, so you can know this information by looking at the header file <PointCloud2.h> in your ROS include directories (for me it was located at /opt/ros/melodic/include/sensor_msgs directory. Or you can find it online, e.g., here: http://docs.ros.org/en/diamondback/api/pcl/html/PointCloud2_8h_source.html#l00075

typedef boost::shared_ptr< ::sensor_msgs::PointCloud2 const> PointCloud2ConstPtr;

So now back to the questions, what is typedef and what is boost::shared_ptr? Let’s start with typedef! So typedef is basically creating an alias to a ((probably) complex) data type. For example, you might want to create an alias for unsigned int as ui. You can do this by

typedef unsigned int ui;

So we basically created an alias for the type: boost:shared_ptr<::sensor_msgs::PointCloud2 const> as PointCloud2ConstPtr! You can learn more about typedef in the wikipedia page here: https://en.wikipedia.org/wiki/Typedef.

The sensor_msgs::PointCloud2 is one of the most common types in ROS and you can find its definition locally in your machine (for me it was in /opt/ros/melodic/share/sensor_msgs/msg directory, there is a file: PointCloud2.msg) or online (e.g., here: http://docs.ros.org/en/melodic/api/sensor_msgs/html/msg/PointCloud2.html).

Alright, now what is boost:shared_ptr?

First things first, boost is a big thing and if you’re using c++, you should be aware of it. You can know more about it here: https://www.boost.org/ and here you can find a list of the libraries: https://www.boost.org/doc/libs/1_79_0/libs/libraries.htm and if you check this list, you can find the smart_ptr library as one of them which has a dedicated page here: https://www.boost.org/doc/libs/1_79_0/libs/smart_ptr/doc/html/smart_ptr.html. As the name suggests, it is a library for smart pointers and one of them is our pointer we are using here which is shared_ptr and very well explained here: https://www.boost.org/doc/libs/1_79_0/libs/smart_ptr/doc/html/smart_ptr.html#shared_ptr and chances are you have the file with the definition (for me it was here: /usr/include/boost/smart_ptr and the file name was: shared_ptr.hpp). You can have a look at this code to have an idea how this pointer is used: https://www.boost.org/doc/libs/1_43_0/libs/smart_ptr/example/shared_ptr_example.cpp
Note that the shared_ptr is part of the std as of c++11

Alright, let’s get into the function! We want to convert from the sensor_msgs::PointCloud2 to the pcl::PCLPointCloud2 which is the type that the PCL library can understand and allows us to use PCL functions with our point cloud.

So, we start with declaring the variables for the PCL point cloud as:

    pcl::PCLPointCloud2* pcl_pc = new pcl::PCLPointCloud2;
    pcl::PCLPointCloud2ConstPtr pcl_ptr(pcl_pc);

We have the variable pcl_pc that represent the point cloud in PCL type while in_ros_pc is of ROS sensor messages type and to make a conversion, we use the toPCL function from pcl_conversions as:


Note that we had to do the conversions to meet the toPCL arguments requirements.

void crop_cloud(const sensor_msgs::PointCloud2ConstPtr& in_ros_pc)
    pcl::PCLPointCloud2* pcl_pc = new pcl::PCLPointCloud2;
    pcl::PCLPointCloud2ConstPtr pcl_ptr(pcl_pc);


    sensor_msgs::PointCloud2 out_ros_pc;

    pcl::PCLPointCloud2 out_pcl_pc;



Posted in Uncategorized | Leave a comment

Happy Pi Day :)

Still this one is my bets ever 🙂


Posted in Uncategorized | Leave a comment

Me, science and reasoning

Despite the obvious and fundamental nature of science being useful for solving humanity problems and making our planet a better place to live in, the beautiful face of it is what really makes it so much interesting and exciting to do for living! This aspect is the core reason why I’m never attached to a narrow field or stick to an area of expertise. Solving complex problems that require learning something new and thinking of different approaches is an amazing style of life that stretches my mind and expands my horizon. Reasoning and scientific thinking is what really attracts me to doing science for a living

Posted in Uncategorized | Leave a comment

My obsession with mathematics <3

its interesting how my obsession with mathematics is leading my passions and paths in life! The title, mathematician” shakens my heart, the inclusion of math into any project is an enough inspirational motivation for me, I visualize my growing dreams as an exponential graph, my perception of music can’t drift from Fourier summation of harmonics, I see people everyday on way to work as a set of vectors belonging to a commuting basis, my eyes won’t stop seeing quiver field for each geometric shape l see whether it’s the sun or pavement, a not-good sleep l feel as a sparse matrix …

Posted in Uncategorized | Leave a comment

Pi day, Einstein and now Hawking!

I’ve always been obsessed with mathematics because the insight it gives for physics and I’ve been fond of physics for the beautiful description she offers for our universe, or maybe more, and this is true thanks to great minds like you, sir! Stephen #Hawking has always inspired me to learn, wonder and open my eyes to the charming cosmos around us. His books, lectures and even the movie have constituted a vast basis of myself, my passion and my perception of the world; a basis that founded many vectors for education, activities and career …

You left us on Pi day, just like how Einstein boarded z science deck!

Happy Pi day and RIP, Hawking 😦 ❤

Posted in Uncategorized | Leave a comment

MCL project posted in ECMI blog

So, I got my “Studying Uncertainty for robot localization using Monte Carlo Localization” project posted in ECMI (European Consortium for Mathematics in Industry) blog 🙂

here is the link: https://ecmiindmath.org/2018/01/29/studying-uncertainty-for-robot-localization-with-multiple-sensors-using-monte-carlo-localization/


Posted in Math, robotics, Updates | Tagged , | Leave a comment

ROT 13 with LabVIEW

So what about ciphering text message using LabVIEW? In this tutorial, we explore using ROT13 in LabVIEW; check it here!

Make sure to also check LabVIEW main page here.

Posted in LabVIEW | Tagged , , , | Leave a comment

Audio signals with LabVIEW

Now, it’s time to play around with audio files inside LabVIEW. It’s always pretty cool to play with music. So, let’s try out and have some fun playing back the music, plotting it on a graph and do Fourier Transform to see the frequencies chart. Check out here.

Posted in LabVIEW | Tagged , | Leave a comment

Fourier Summation using LabVIEW

The next practice of using LabVIEW is out! In this one, we will apply the previous VI into something practical. Let’s build a Fourier summation. If you don’t remember, then any function (not quite any function, but let’s skip the theory for now) can be represented by Fourier approximation as:

f(x) = ∑a cos (nx) + b sin(nx)

In this formula, a and b are the Fourier coefficients that can be calculated using some equations, but for simplification purposes we will enter them manually.

Check out this page to follow on.

Posted in LabVIEW, Math, Signal Processing | Tagged , | Leave a comment

Introduction to LabVIEW

So, I finally started to create the LabVIEW content. Check out the page here! Introduction material has been added.

Posted in LabVIEW, Signal Processing, Updates | Tagged , | Leave a comment