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

Revision history [back]

click to hide/show revision 1
initial version

Here is a sample that can solve your problem. This is a snippet and it should work properly with normal rate of 30Hz. If this is not solving then let me know about the exact problem.

//// c++ headers #include <iostream> // ROS headers #include <ros ros.h=""> #include <sensor_msgs pointcloud2.h=""> // point cloud definition typedef pcl::PointCloud<pcl::pointxyz> PointCloud; // namspace using namespace std; using namespace sensor_msgs;

void callback(const sensor_msgs::PointCloud2ConstPtr& pCloud) { // new cloud formation pcl::PointCloud<pcl::pointxyz>::Ptr cloud (new pcl::PointCloud<pcl::pointxyz>); pcl::fromROSMsg (*pCloud, *cloud);

// cloud is the one you are interested about. }

int main(int argc, char** argv) { ros::init(argc, argv, "test_node");

ros::NodeHandle nh;
ros::Rate rate(30); // frequency of operation

// subscribe
ros::Subscriber sub = nh.subscribe ("/camera/depth/points", 1, callback);


ros::spin();
return 0;

}

Regards, Prasanna

Here is a sample that can solve your problem. This is a snippet and it should work properly with normal rate of 30Hz. If this is not solving then let me know about the exact problem.

//// c++ headers
 #include <iostream>
 // ROS headers
 #include <ros ros.h="">
    <ros/ros.h>
#include <sensor_msgs pointcloud2.h="">
<sensor_msgs/PointCloud2.h>
// point cloud definition
 typedef pcl::PointCloud<pcl::pointxyz> pcl::PointCloud<pcl::PointXYZ> PointCloud;
// namspace
 using namespace std;
 using namespace sensor_msgs;

sensor_msgs;

void callback(const sensor_msgs::PointCloud2ConstPtr& pCloud) { // new cloud formation pcl::PointCloud<pcl::pointxyz>::Ptr pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::pointxyz>); pcl::PointCloud<pcl::PointXYZ>); pcl::fromROSMsg (*pCloud, *cloud);

*cloud);

// cloud is the one you are interested about. }

}

int main(int argc, char** argv) { ros::init(argc, argv, "test_node");

"test_node");
ros::NodeHandle nh;
ros::Rate rate(30); // frequency of operation

// subscribe
ros::Subscriber sub = nh.subscribe ("/camera/depth/points", 1, callback);


ros::spin();
return 0;
}

}

Regards, Prasanna