Robotics StackExchange | Archived questions

Unable to read & render .pcd files in ros rviz

Hello All,

I am very new to ros development, I am trying to read and render .pcd file. But I am unable to success. Could anyone please suggest me possible solutions. This is the sample code i am using currently,

typedef pcl::PointCloud<pcl::PointXYZ> PointCloud;
using namespace std;
int main(int argc, char** argv)
{
double x_cloud; double y_cloud; double z_cloud;
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
ros::init (argc, argv, "my_pcl_tutorial");
ros::NodeHandle nh;
ros::Publisher pub = nh.advertise<PointCloud> ("points2", 1);
// .pcd file is in the same location as the source file.
pcl::io::loadPCDFile<pcl::PointXYZ> ("data.pcd", *cloud);
PointCloud::Ptr msg (new PointCloud);
msg->header.frame_id = "frame1";
msg->height = cloud->height;
msg->width = cloud->width;
for (size_t i = 0; i < cloud->size (); i++) {
x_cloud = cloud->points[i].x;
y_cloud = cloud->points[i].y;
z_cloud = cloud->points[i].z;
msg->points.push_back (pcl::PointXYZ (x_cloud, y_cloud, z_cloud));  }
ros::Rate loop_rate(4);
  while (nh.ok())  {
pub.publish (msg);
 ros::spinOnce ();
loop_rate.sleep ();
}}

[pcl::PCDReader::readHeader] Could not find file 'data.pcd'.

Also, unable to visualize the data in the RVIZ, Appreciate your help in this regards.

Thanks in Advance

Asked by Ajay on 2018-05-11 00:33:13 UTC

Comments

This is probably caused by the working directory your node is running with. Are you using rosun or roslaunch to start it? You could add a full absolute path to the pcd file to fix this.

Asked by PeteBlackerThe3rd on 2018-05-11 03:08:43 UTC

Thank you so much for your response. I am working with rosrun. Even I tried to do adding full path. But still same error.Also, i tried to render point cloud in rviz , using sample random point cloud generation as mentioned in this link https://stackoverflow.com/questions/39122509/rviz-display-o)

Asked by Ajay on 2018-05-11 03:48:34 UTC

According to the link https://stackoverflow.com/questions/39122509/rviz-display-own-point-cloud/50286000#50286000 not able rendering point cloud in rviz. Please can u help me, way to visualize point cloud in rviz

Asked by Ajay on 2018-05-11 03:50:53 UTC

If you're still getting the 'could not find file' error then there is no point worrying about RVIZ, you need to solve this problem first. The only explanation is that there was an error in your full path. Can you update your question with the full path and a listing of the location of the pcd file.

Asked by PeteBlackerThe3rd on 2018-05-11 04:34:56 UTC

Sure, This is the path I updated, but still it's giving same error pcl::io::loadPCDFilepcl::PointXYZ ("/home/ajay/catkin_ws/src/my_pcl/data.pcd", *cloud);

Asked by Ajay on 2018-05-11 06:10:59 UTC

Hello PeteBlackerThe3rd ,

Thanks for your help, I was made mistake in the path. Now it's working fine

Asked by Ajay on 2018-05-12 02:12:27 UTC

Answers