Unable to visualise PointCloud in Rviz (ROS) from publisher and subscriber node
I am using the below code for publisher and subscriber. I am able to visualise PointCloud on Rviz for input node but failed to visualise output node. As i am quite new in ROS. How i can solve the problem? I have even set in Rviz the Fixed Frame: base_link.
ros::Subscriber subPointCloud;
ros::Publisher pubPointCloud;
void DEM(const sensor_msgs::PointCloud2ConstPtr& input)
{
ROS_DEBUG("Point Cloud Received");
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
sensor_msgs::PointCloud2 output;
// Convert from ROS message to PCL point cloud
pcl::fromROSMsg(*input, *cloud);
pcl::toROSMsg(*cloud, output);
output.header.stamp = ros::Time::now();
output.header.frame_id = "/base_link";
pubPointCloud.publish(output);
}
int main(int argc, char** argv)
{
ROS_INFO("Starting LIDAR Node");
ros::init(argc, argv, "kitti_lidar_node");
ros::NodeHandle nh;
subPointCloud = nh.subscribe<sensor_msgs::PointCloud2>("input", 1, DEM);
pubPointCloud = nh.advertise<pcl::PointCloud<pcl::PointXYZ> > ("output", 1);
ros::spin();
return 0;
}
When you say it failed to visualise in RVIZ what exactly do you mean? Does RVIZ show and error? A important first check would be to use the
rostopic echo <topic>
command to see if any messages are being published on theoutput
topic.Rviz does not shows any error, than also i am not able to visualise the output. Further, i can see topics are successfully publishing and subscribing topics: rostopic list -v.
As i don't have sufficient point to attached Rviz screenshot here. I have post the image on following link may you can check: link text