Display PointCloud2 in Rviz
Hi!
I realize this question has been chewed a lot here but from all the answers I've read nothing seems to work. I'm using ROS Indigo on Ubuntu 14.04 LTS (32bit).
Before I start reading and publishing my own data I decided to check out how things actually work with one of these PCD files.
Here is my publisher:
#include <ros/ros.h>
#include <pcl_ros/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <string>
typedef pcl::PointCloud<pcl::PointXYZ> PointCloud;
using std::string;
int main(int argc, char** argv)
{
ros::init (argc, argv, "cloud_publisher");
ros::NodeHandle nh;
string pcdFile = "";
nh.getParam("pcdFile", pcdFile);
if(pcdFile == "") {
ROS_ERROR_STREAM("Unable to find file \"" << pcdFile << "\"");
nh.shutdown();
}
ros::Publisher pub = nh.advertise<PointCloud> ("cloud_publisher/cloud_from_file", 1);
PointCloud::Ptr msg(new PointCloud);
if (pcl::io::loadPCDFile<pcl::PointXYZ> (pcdFile, *msg) == -1)
{
ROS_ERROR_STREAM("Unable to read from file \"" << pcdFile << "\"");
nh.shutdown();
return -1;
}
ros::Rate r(10);
while (nh.ok())
{
msg->header.frame_id = "/my_frame";
//msg->header.stamp = ros::Time::now().toNSec();
pub.publish(msg);
ros::spinOnce();
r.sleep();
}
return 0;
}
Basically I read a PCD file and send it on its way to the rest of the ROS network. I want to see the result in RViz. Now here is the thing - I get the ever so lovely error
No tf data. Actual error: Fixed Frame [map] does not exist
in my global status of Rviz. I also added a PointCloud2 item to RViz but the moment I selected the topic that my cloud_publisher is publishing roslaunch (I use a launch file to load the PCD file in my node) breaks with another known error the moment I set the topic of my PointCloud2 to cloud_publisher/cloud_from_file:
terminate called after throwing an instance of 'std::runtime_error'
what(): Time is out of dual 32-bit range [cloud_publisher-1] process has died [pid 2015, exit code -6, cmd /home/rosuser/catkin_ws/devel/lib/pcl_misc/cloud_publisher __name:=cloud_publisher __log:=/home/rosuser/.ros/log/32182a0e-3b92-11e5-9e58-001e0ba4cf00/cloud_publisher-1.log]. log file: /home/rosuser/.ros/log/32182a0e-3b92-11e5-9e58-001e0ba4cf00/cloud_publisher-1*.log all processes on machine have died, roslaunch will exit
I read that you have to either provide a transformation (using TF) from the map fixed frame to all others that you publish (in my case I have only my_frame) or simply set my_frame to be the global frame too. Well neither is working due to the crash of my node.
Can you please help me resolve this issue? It is not possible that displaying a single item (in my case a point cloud) in Rviz is that complicated.
Thanks!
EDIT: I just tried using rostopic echo /cloud_publisher/cloud_from_file and my publisher crashed again! It seems the issue is not because of Rviz (although the missing TF data is still bothering me...). Something fishy is going on with the topic itself...
EDIT2: I forgot to mention that I have also tried this solution. I also wrote the wrong architecture. I have a 32bit CPU.
EDIT3: I tried borrowing code from ...