ROS发布pcl::PointXYZ数据时,时间戳问题

在利用ROS发布pcl::pointXYZ数据时,出现错误。

运行时出现错误:ERROR: terminate called after throwing an instance of 'std::runtime_error'   what():  Time is out of dual 32-bit range

#include 
#include 
#include 

typedef pcl::PointCloud PointCloud;

int main(int argc, char** argv)
{
    ros::init (argc, argv, "pub_pcl");
    ros::NodeHandle nh;
    ros::Publisher pub = nh.advertise ("points2", 1);

    PointCloud::Ptr msg (new PointCloud);
    msg->header.frame_id = "some_tf_frame";
    msg->height = msg->width = 1;
    msg->points.push_back (pcl::PointXYZ(1.0, 2.0, 3.0));

    ros::Rate loop_rate(4);
    while (nh.ok())
    {
        msg->header.stamp = ros::Time::now ();
        pub.publish (msg);
        ros::spinOnce ();
        loop_rate.sleep ();
   } 
}
出现错误:

error: no se puede convertir ‘ros::Time’ a ‘uint64_t {aka long unsigned int}’ en la asignación (it's in Spanish, I don't know how to change my compiler language)
error: 'ros::Time' cannot be converted to 'uint64_t {aka long unsigned int}' in assignment


解决方法:

参考:http://answers.ros.org/question/172730/pcl-header-timestamp/


pcl_conversions has conversion functions :http://docs.ros.org/indigo/api/pcl_co...

To convert the time:

#include 
...
pcl_conversions::toPCL(ros::Time::now(), point_cloud_msg->header.stamp);

Or convert an entire header from a ros message:

pcl_conversions::toPCL(ros_msg->header, point_cloud_msg>header);




你可能感兴趣的:(ROS)