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 source code of the pcd_to_cloud tool (you can find it here) but the 32-bit range error is present again. Funny though if I call directly
rosrun pcl_ros pcd_to_cloud capture0001.pcd [40]
it works O_O
EDIT4: I took over almost the complete code of the pcd_to_cloud tool (removed the waiting interval and replaced it with ros::Rate:
#include <ros/ros.h>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl_ros/publisher.h>
#include <pcl_conversions/pcl_conversions.h>
#include <ros/publisher.h>
#include <string>
class PMDCloudPublisher
{
protected:
std::string tf_frame;
ros::NodeHandle nh;
ros::NodeHandle private_nh;
public:
sensor_msgs::PointCloud2 cloud;
std::string file_name, cloud_topic;
pcl_ros::Publisher<sensor_msgs::PointCloud2> pub;
PMDCloudPublisher()
: tf_frame("/base_link"),
private_nh("~")
{
cloud_topic = "cloud";
pub.advertise(nh, cloud_topic.c_str(), 1);
private_nh.param("frame_id", tf_frame, std::string("/base_link"));
ROS_INFO_STREAM("Publishing data on topic \"" << nh.resolveName(cloud_topic) << "\" with frame_id \"" << tf_frame << "\"");
}
int start()
{
if (file_name == "" || pcl::io::loadPCDFile(file_name, cloud) == -1)
return (-1);
cloud.header.frame_id = tf_frame;
return (0);
}
bool spin ()
{
int nr_points = cloud.width * cloud.height;
std::string fields_list = pcl::getFieldsList(cloud);
ros::Rate r(40);
while(nh.ok ())
{
ROS_DEBUG_STREAM_ONCE("Publishing data with " << nr_points
<< " points " << fields_list
<< " on topic \"" << nh.resolveName(cloud_topic)
<< "\" in frame \"" << cloud.header.frame_id << "\"");
cloud.header.stamp = ros::Time::now();
pub.publish(cloud);
r.sleep();
}
return (true);
}
};
int main(int argc, char* argv[])
{
ros::init (argc, argv, "cloud_publisher");
ros::NodeHandle nh;
PMDCloudPublisher c;
nh.getParam("pcdFile", c.file_name);
if (c.start () == -1)
{
ROS_ERROR_STREAM("Could not load file \"" << c.file_name <<"\". Exiting...");
return (-1);
}
ROS_INFO_STREAM("Loaded a point cloud with " << c.cloud.width * c.cloud.height
<< " points (total size is " << c.cloud.data.size() << ") and the following channels: " << pcl::getFieldsList (c.cloud));
c.spin();
return 0;
}
And again I get the same stupid ... dual 32-bit range error. Omg...
Originally posted by rbaleksandar on ROS Answers with karma: 299 on 2015-08-05
Post score: 1