When working with ROS2 and tf2, you may encounter the following warning when visualizing data in RViz or processing buffers:
1
Warning: TF_OLD_DATA ignoring data from the past for frame base_link at time 4.294967 according to authority Authority undetectable
This message indicates that tf2 is dropping out-of-order or stale transforms because your TF publisher is using a “simulated time” (or older timestamps), while the receiver uses the default system clock. In that case, we can either hit the reset button, or we need to run nodes using use_sim_time
You only need to drive the /clock topic when you’ve told your nodes / rviz to run in simulation time (i.e. you’ve set the use_sim_time parameter to true, by default, use_sim_time=false).
node->declare_parameter("use_sim_time", true);
or rviz use_sim_time:=true
One example is replaying a bag and displaying on rviz. ros2 run rviz2 rviz2 --ros-args -p use_sim_time:=true
In your tf publisher node:
Enable Sim Time Parameter. In your node’s constructor or setup, set:
// Build and publish clockrosgraph_msgs::msg::Clockclk;clk.clock=imu_msg->header.stamp;// reuse the IMU’s timestampclock_pub_->publish(clk);imu_tf_publisher_->publish(*imu_msg);
Transform Listener
Life Cycle
tf2_ros::TransformListener starts its own subscription /tf, /tf_static: