ros2 tf2 time problem with data from bag replayed

asked 2022-11-03 03:23:35 -0500

fury.nerd gravatar image

updated 2022-11-03 03:25:18 -0500

hi, i have a recorded bag include a viz_topic with type of MarkerArray,where the data is filled in cpp implementation in ros2, as something like:

...   
...  
...   
visualization_msgs::msg::MarkerArray msg;  
msg.header.frame_id = "map";  
msg.header.stamp = rclcpp::Clock().now();  
...
...
...

when i replay the bag (ros2 bag play $mybag), and wish rivz2 to display the MarkerArray w.r.t a frame base_link, and i use the following python implementation to describe the tf relationship between base_link and map, as like:

...   
...  
...  
tf_broadcaster = TransformBroadcaster()  
...  
...  
...  
t = TransformStamped()  
t.header.frame_id  = "map"  
t.child_frame_id   = "base_link"  
t.transform.translation.x = x  
t.transform.translation.y = y  
t.transform.translation.z = z  

t.transform.rotation.x = qx  
t.transform.rotation.y = qy  
t.transform.rotation.z = qz  
t.transform.rotation.w = qw  

t.header.stamp = node.get_clock().now().to_msg()  
tf_broadcaster.sendTransform(t)  
...  
...  
...

the python code could run, and i can see in the rviz2 the frames base_link and map is moving relatively as expected, but rviz2 cannot display the MarkerArray as expected, with error like:

No transform to fixed frame [base_link]. TF error: [Lookup would require extrapolation into the past. Requested time 1667286909.763899 but the earliest data is at time 1667462286.672915, when looking up transform from frame [map] to frame [base_link]]

i think it is about timestamp issue, but cannot figure out how to address it, could i get some help? thanks

edit retag flag offensive close merge delete