ros的时间系统

最近很忙,也没空花时间去整理博客,因此仅按着自己能理解的方式记录。

ros的时间系统对于一个初学者来说其实很难处理,因为不去管好像也可以用,但会出一些报错,去学的话又觉得费工夫,不确定用不用的上。下面是一些概念的解释。
关于ros::time::now()在use_sim_time参数影响下的值。
No. The value of ros::time::now() depends on whether the parameter use_sim_time is set.

If use_sim_time == false, ros::time::now() gives you system time (seconds since 1970-01-01 0:00, so something like 1471868323.123456).
If use_sim_time == true, and you play a rosbag, ros::time::now() gives you the time when the rosbag was recorded (probably also something like 1471868323.123456).
If use_sim_time == true, and you run a simulator like Gazebo, ros::time::now() gives you the time from when the simulation was started, starting with zero (so probably something like 63.123456 if the simulator has been running for 63.123456 seconds).
Cases 2 and 3 are in simulation time, so a trajectory that takes 20 seconds to complete will always have a duration of 20, no matter whether the rosbag / the simulation is running at 0.1x, 1.0x or 10.0x real time.

Your example sounds like it’s an offset to whenever the trajectory is started. If that is the case, you should use ros::Duration and not ros::Time for that. Also see the documentation for this.
需要补充的是,当使用rosbag时,如果不开始播放,那么ros::time::now()反馈的值就是0,以此可以判断是否开始播放。参考:http://wiki.ros.org/roscpp/Overview/Time

而在lookupTransform里,通常用的就是ros::Time::now(),但很容易引起下面的错误:

[ERROR] [1560005873.049820397]: Lookup would require extrapolation into the future. Requested time 1560005873.049761685 but the latest data is at time 1560005873.037766578, when looking up transform from frame [turtle1] to frame [turtle2]

这主要是因为tf并不是实时转换的,而是有缓冲机制,为了避免这一点,可以使用ros::time(0),来获取最新的。

另外,令人不解的是,我在navigation/base_local_plannel的goal_functions.cpp:113行发现他用的是ros::Time(),我以为是这里出问题才会导致报错,但看了源码,ros::Time()调用了父类的默认构造函数,就是sec=0,nsec=0,似乎不是这里的问题。

另外walltime与ros time并不一样,前者直译为墙上时间,是无法变更的,而后者是可以加速、减速、暂停的:https://blog.csdn.net/sru_alo/article/details/102893536

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值