Ros tf2_ros::Buffer.lookupTransform 运行报错lookupTransform base2laser error

项目场景:

tf2_ros::buffer.lookupTransform()用法及注意事项

问题描述

在tf树已经查到坐标之间的关系,但是在监听其中两个坐标之间关系时,却显示:运行报错,提示运行报错 lookupTransform base2laser error,“base_footprint” passed to lookupTransform argument target_frame does not exist.

原因分析:

// 参考tf2源码: https://docs.ros.org/en/noetic/api/tf2_ros/html/c++/classtf2__ros_1_1Buffer.html
用法: Buffer::lookupTransform(const std::string& target_frame, const std::string& source_frame,
                         const ros::Time& time, const ros::Duration timeout) const

作用:Get the transform between two frames by frame ID.

参数意义:
target_frame	The frame to which data should be transformed(目标坐标系)
source_frame	The frame where the data originated(原坐标系)
time	The time at which the value of the transform is desired. (0 will get the latest)
timeout	How long to block before failing(设置最长等待时间)
Returns
The transform between the frames

虽然在tf树中可以看到各个坐标之间的已经存在,但是却 Buffer::lookupTransform()时报错,主要是因为在使用时,大家都默认不填写第四个参数timeout或填写的时间比较短而导致的。这个参数表示最长等待监听时间,如果没有这个参数,那么监听一次,没有查询到数据,就失败,但是,有时候lookupTransform()函数处理时间比较长,所以导致出错。


解决方案:

Buffer::lookupTransform(const std::string& target_frame, const std::string& source_frame, const ros::Time& time, const ros::Duration timeout) const函数第四个参数填写完整,如 ros::Duration(1),最长等待1s,基本就可以解决该问题。当然,可以在该函数前后设置休眠时间来等待。

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值