ros:time::now()

在这里插入图片描述

Let’s make the second turtle follow the first turtle, and not the carrot. Change your code to the following:

   try{
      listener.lookupTransform("/turtle2", "/turtle1",  
                               ros::Time(0), transform);

You can also see we specified a time equal to 0. For tf, time 0 means “the latest available” transform in the buffer. Now, change this line to get the transform at the current time, “now()”:

try{
listener.lookupTransform("/turtle2", “/turtle1”,
ros::Time::now(), transform);

First, make sure you stopped the launch file from the previous tutorial (use ctrl-c). Compile the code, and run it again:

$ roslaunch learning_tf start_demo.launch
So, all of the sudden lookupTransform() is failing, telling you repeatedly:

[ERROR] [1287871653.885277559]: You requested a transform that is 0.018 miliseconds in the past, but the most recent transform in the tf buffer is 7.681 miliseconds old.
When trying to transform between /turtle1 and /turtle2.

Why is that? Well, each listener has a buffer where it stores all the coordinate transforms coming from the different tf broadcasters. When a broadcaster sends out a transform, it takes some time before that transform gets into the buffer (usually a couple of milliseconds). So, when you request a frame transform at time “now”, you should wait a few milliseconds for that information to arrive.

tf provides a nice tool that will wait until a transform becomes available. Let’s look at what the code would look like:

try{
ros::Time now = ros::Time::now();
listener.waitForTransform("/turtle2", “/turtle1”,
now, ros::Duration(3.0));
listener.lookupTransform("/turtle2", “/turtle1”,
now, transform);
The waitForTransform() takes four arguments:

Wait for the transform from this frame…
… to this frame,
at this time, and
timeout: don’t wait for longer than this maximum duration
Note: The use of ros::Time::now() is for this example. Usually this would be the timestamp of the data wishing to be transformed.

So waitForTransform() will actually block until the transform between the two turtles becomes available (this will usually take a few milliseconds), OR --if the transform does not become available-- until the timeout has been reached.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值