Unable to read & render .pcd files in ros rviz

asked 2018-05-11 00:33:13 -0600

Ajay gravatar image

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

edit retag flag offensive close merge delete

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.

PeteBlackerThe3rd gravatar imagePeteBlackerThe3rd ( 2018-05-11 03:08:43 -0600 )edit

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/3... )

Ajay gravatar imageAjay ( 2018-05-11 03:48:34 -0600 )edit

According to the link https://stackoverflow.com/questions/3... not able rendering point cloud in rviz. Please can u help me, way to visualize point cloud in rviz

Ajay gravatar imageAjay ( 2018-05-11 03:50:53 -0600 )edit

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.

PeteBlackerThe3rd gravatar imagePeteBlackerThe3rd ( 2018-05-11 04:34:56 -0600 )edit

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

Ajay gravatar imageAjay ( 2018-05-11 06:10:59 -0600 )edit

Hello PeteBlackerThe3rd ,

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

Ajay gravatar imageAjay ( 2018-05-12 02:12:27 -0600 )edit