文章目錄
-
- 問題産生:
- 報錯資訊:
- 問題分析:
- 解決方案:
-
-
- 1,利用ros::Time(0)進行替代
- 2,加入延時等待函數
-
- 總結:
- 參考網址:
問題産生:
最近在跑一個程式時,需要采集TF樹中兩個坐标的坐标變換,但是在運用過程中,通過下面語句進行坐标采集時,出現如下報錯:
語句:
tf_transform = tf_buffer.lookupTransform(desired_camera_frame, current_camera_frame, ros::Time(0), ros::Duration(0));
這裡我想擷取坐标desired_camera_frame和current_camera_frame的坐标變換。
報錯資訊:
[ERROR] [1619773238.770668534]: Lookup would require extrapolation into the past. Requested time 1619773238.270257792 but the earliest data is at time 1619773238.276599648, when looking up transform from frame [camera_color_optical_frame] to frame [desired_cam_frame]
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIn5GcuMjNyMjMwcTMwMDNwEjMwIzLc52YucWbp5GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.png)
問題分析:
可以看到我們擷取資訊的時間與資料最早的時間并不比對。
因為每個監聽器都有一個緩沖區,存儲來自不同TF廣播的所有坐标轉換。當廣播者發送轉換時,轉換進入緩沖區需要一段時間(通常是幾毫秒)。是以,當您在“現在”請求幀轉換時,從緩沖區提取不到目前的釋出變換,您應該等待幾毫秒,等待該資訊到達,是以應該使用ros::Time(0)而不是ros::Time::now().
解決方案:
1,利用ros::Time(0)進行替代
tf_transform = tf_buffer.lookupTransform(desired_camera_frame, current_camera_frame, ros::Time(0), ros::Duration(0));
好處:本身具有等待緩沖區最新tf資料的屬性。
2,加入延時等待函數
tf_transform = tf_buffer.lookupTransform(desired_camera_frame, current_camera_frame, ros::Time::now(), ros::Duration(0.5));
缺點:需要根據報錯語句設定等待時間。
總結:
1,
ros::Time::now()擷取目前的時間,在時間“now”請求坐标系變換時,您應該等待幾毫秒以獲得該資訊。
2,
ros::Time(0)表示使用緩沖中最新的tf資料
參考網址:
1,
https://www.cnblogs.com/flyinggod/p/10811164.html
2, https://blog.csdn.net/qq_39534332/article/details/91348925
3,
https://answers.ros.org/question/325486/tf2-transform-error-lookup-would-require-extrapolation-into-the-past/