0
$\begingroup$

Rosanswers logo

Good afternoon,

I have a problem when converting a laser scan into a point cloud map using ros indigo virtual machine. I get the following error :

terminate called after throwing an instance of 'tf2::ExtrapolationException' what(): Lookup would require extrapolation into the past. Requested time 1467669390.062319560 but the earliest data is at time 1467669390.111446506, when looking up transform from frame [LIDAR] to frame [base_link] Aborted (core dumped)

After running this code:

#include <tf/transform_listener.h>
#include <laser_geometry/laser_geometry.h>
#include <ros/ros.h>


class My_Filter {
     public:
        My_Filter();
        void scanCallback(const sensor_msgs::LaserScan::ConstPtr& scan);
     private:
        ros::NodeHandle node_;
        laser_geometry::LaserProjection projector_;
        tf::TransformListener tfListener_;

        ros::Publisher point_cloud_publisher_;
        ros::Subscriber scan_sub_;
};

My_Filter::My_Filter(){
        scan_sub_ = node_.subscribe<sensor_msgs::LaserScan> ("/scan", 100, &My_Filter::scanCallback, this);
        point_cloud_publisher_ = node_.advertise<sensor_msgs::PointCloud2> ("/cloud", 100, false);
        tfListener_.setExtrapolationLimit(ros::Duration(10.0));
}

void My_Filter::scanCallback(const sensor_msgs::LaserScan::ConstPtr& scan){
    sensor_msgs::PointCloud2 cloud;
    projector_.transformLaserScanToPointCloud("base_link", *scan, cloud, tfListener_);
    point_cloud_publisher_.publish(cloud);
}

int main(int argc, char** argv)
{
    ros::init(argc, argv, "my_filter");

    My_Filter filter;

    ros::spin();

    return 0;
}

Thank you for your help


Originally posted by viki_rover on ROS Answers with karma: 3 on 2016-07-11

Post score: 0


Original comments

Comment by ignacio on 2021-06-17:
I ended up in this thread looking for a solution for this problem. But my issue was that I assigned a time to stamp pc.header.stamp = ros::Time::now(); instead of separating accordingly in sec and nsec

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

You are trying to transform the laser scan to base_link before you have the required tf information. You can solve this by either

The message filter is the most idiomatic. Otherwise I'd recommend waitForTransform with a timeout.


Originally posted by Felix Endres with karma: 6468 on 2016-07-11

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by viki_rover on 2016-07-14:
Thank you for your answer it worked !

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.