TF_OLD_DATA error when I publish a new topic.
Hello,
I'm trying to create a map of the environment using pcl_ndt
. I use data from simulated velodyne in gazebo.
I'm subscribing to PointCloud2 msg and publishing the genrated map via PointCloud2 msg in new topic /ndt_map
However, after a few seconds of publishing /nadt_map
topic, I got this warning :
Warning: TF_OLD_DATA ignoring data from the past for frame base_link at time 36,221 according to authority /ndt_map
Possible reasons are listed at http://wiki.ros.org/tf/Errors%20explained
at line 277 in /tmp/binarydeb/ros-melodic-tf2-0.6.5/src/buffer_core.cpp
I already used this command that should have solved the problem:
rosparam set use_sim_time true
but the error still persist.
I saw that this could happen when reproducing bagfile, but for my case, I'm using online data from the gazebo simulator.
Thanks for helping shedding light on this issue!
UPDATE: this is my callback :
void pts_callback(const sensor_msgs::PointCloud2::ConstPtr& input){
// Convert the sensor_msgs/PointCloud2 data to pcl/PointCloud
pcl::fromROSMsg(*input, cloud);
ndt.align(*outputCloud, init);
// Get the transformation matrix
t = ndt.getFinalTransformation();
// Transforme the cloud with the transformation matrix
pcl::transformPointCloud(cloud, *transformed_cloud, t);
tf::TransformBroadcaster br;
tf::Transform transform;
//create tf transform from t
transform = get_tf_transform(t);
br.sendTransform(tf::StampedTransform(transform, input->header.stamp, "world", "base_link"));
sensor_msgs::PointCloud2::Ptr map_msg(new sensor_msgs::PointCloud2);
pcl::toROSMsg(*transformed_cloud, *map_msg);
ndt_pub.publish(*map_msg);
}
I'm subscribing to VelodyneScan packets with :
points_sub_ = nd.subscribe("velodyne_points", 100000, &pts_callback, this);
and I publish map with :
ndt_pub = nd.advertise<sensor_msgs::PointCloud2>("ndt_map", 1000);
Do you update the timestamp of the PointCloud2 message before publishing it every time?
Yes, for the broadcasting I use
input->header.stamp
I updated the question with the callback that I used. See edit above.Unsure about C++ but in python when I create a new message it doesn't set the timestamp (so secs and nsecs both start at 0). That's probably the case when you initialize
map_msg
. Try setting the stamp explicitly (equal to input->header.stamp like you do for the transform) for themap_msg
as well.I am not 100% sure but i think what is happening is an error caused by your queue size. if you reduce this size, my bet is that you are not going to have anymore the issue.
I am going to try why i think is that.
Lets imagine that your callback function is slower than the main frecuency of value subscribing. When this happens, you will be recieving data on which you will not be able to actually run the callback function (because it is already running). This data will be put on queue until the callback function is available to be recalled. this will cause that always will be acummulating more and more data, until it will reach a point when you will be using data with a stamp enough past to be considered "actually past" and this is why it ...(more)
... If you reduce the queue size, the accumulations are controlled (to the number you give, in you case you can acummulate up to 100000! ) and all the extra messages are discarded. Let me know if this was the issue!