0
$\begingroup$

Rosanswers logo

Hi there,

I am trying to understand how to publish and subscribe to a PointCloud2 data from Kinect. Here is a sample program that publishes a PointCloud data.

#include <ros/ros.h>
#include <pcl_ros/point_cloud.h>
#include <pcl/point_types.h>

typedef pcl::PointCloud<pcl::PointXYZ> PointCloud;

int main(int argc, char** argv)
{
  ros::init (argc, argv, "pub_pcl");
  ros::NodeHandle nh;
  ros::Publisher pub = nh.advertise<PointCloud> ("points2", 1);

  PointCloud::Ptr msg (new PointCloud);
  msg->header.frame_id = "some_tf_frame";
  msg->height = msg->width = 1;
  msg->points.push_back (pcl::PointXYZ(1.0, 2.0, 3.0));

  ros::Rate loop_rate(4);
  while (nh.ok())
  {
    msg->header.stamp = ros::Time::now ();
    pub.publish (msg);
    ros::spinOnce ();
    loop_rate.sleep ();
  }
}

However, there are errors. My system cannot find files #include <pcl_ros/point_cloud.h> and #include <pcl/point_types.h>. I tried to search for the files, and got them under /pcl-1.5/pcl/point_types.h.

I tried to #include the above path. Now the error changed to fatal error: Eigen/StdVector: No such file or directory, compilation terminated.

Here are my Questions:

  1. Why I have files under /pcl-1.5/pcl/point_types.h rather than general

    pcl/point_types.h? Does it make a difference. Same question for pcl_ros/point_cloud.h

  2. What am I doing wrong? why an already given code is not running properly?

  3. I have no folder called pcl_ros. Why?

Any answer will be appreciated.


Originally posted by Latif Anjum on ROS Answers with karma: 79 on 2014-01-28

Post score: 2


Original comments

Comment by lfelipesv on 2014-01-28:
I think you will get errors trying to compile this file. But let's try to solve your first problem. When you look for roscd pcl_ros you find nothing, right? And what is your ROS distribution and Ubuntu Release?

Comment by Latif Anjum on 2014-01-28:
Interestingly roscd pcl_ros gives the following path. /opt/ros/fuerte/stacks/perception_pcl/pcl_ros

I have ros-fuerte and ubuntu 12.04.

Am I using two copies of pcl? one under /pcl-1.5/pcl and another under /stacks/perception_pcl?

Comment by lfelipesv on 2014-01-28:
Try to add manually the source: source /opt/ros/fuerte/setup.bash , or something like that and run again. Let me know if the same error occur.

Comment by Latif Anjum on 2014-01-28:
sorry for my dumbness but I didnt get it. Where should I add source /opt/ros/fuerte/setup.bash?

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

Which ros distro do you use? Have you added pcl to your CMakeLists.txt properly?

Assuming you use hydro with catkin you need add to your CMakeLists.txt:

find_package( PCL REQUIRED )
include_directories(  ${catkin_INCLUDE_DIRS}  ${PCL_INCLUDE_DIRS} )
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

and for each of your executables/libs you created like

add_executable( my_exec  my_cpp_file.cpp )

you need to link against both catkin and pcl libs:

target_link_libraries ( my_exec ${PCL_LIBRARIES} ${catkin_LIBRARIES} )

With catkin I think there is no separate ros pcl package anymore.


Originally posted by Wolf with karma: 7555 on 2014-01-28

This answer was ACCEPTED on the original site

Post score: 11


Original comments

Comment by Latif Anjum on 2014-01-28:
I am using ros-fuerte on ubuntu 12.04. I work with rosbuild (not much familiar with catkin).

Comment by Latif Anjum on 2014-01-28:
I have tried adding everything you suggested to CMakeLists.txt (excluding the catkin libraries because I dont use them) but it still cannot find pcl_ros/point_cloud.h. roscd pcl_ros finds the directory and point_cloud.h file exists under its include folder.

Comment by Wolf on 2014-01-28:
As mentioned this is the howto for catkin with ros hydro. Unfortunately, this does not help you for your ros fuerte. I think you have had to add some pcl packages back then, but I am not sure anymore

Comment by Robert1 on 2014-04-23:
Hi Wolf, I have the same problem and your tip will help me since i am using Hydro. I have question about this line add_executable( my_exec my_cpp_file.cpp ), my_exec name is goint to be "point_types" and my_cpp_file.cpp will be "point_types.cpp" Thanks alot for your input

$\endgroup$
0
$\begingroup$

Rosanswers logo

first find out where is your pcl header files. For example, I found mine at /usr/include/pcl-1.7/pcl/point_types.h. then update your package's CMakeLists.txt, include_directories( ${catkin_INCLUDE_DIRS} /usr/include/pcl-1.7/ /usr/include/eigen3/ )


Originally posted by scheng with karma: 11 on 2016-02-24

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.