我不知道有什么开箱即用的解决方案可以完全按照您在此处描述的方式进行。
为了快速破解,如果您的主题没有时间戳,并且节点只是在消息到达时接收消息,最简单的做法是记录一个包并从两个不同的 @ 实例播放两个主题987654324@。像这样的:
first terminal
rosbag play mybag.bag --clock --topics /my/topic
second terminal started some amount of time later
rosbag play mybag.bag --topics /my/other_topic
不确定--clock 标志,是否需要它主要取决于模拟的含义。如果您想要控制时差而不是在两个不同的终端中按 Enter 键,您可以编写一个小的 bash 脚本来启动它们。
另一个仍然涉及包的选项,但可以让您更好地控制消息延迟的确切时间,即编辑包以使包中的消息已经具有正确的延迟。可以通过修改rosbag cookbook中的第一个示例相对容易地完成:
import rosbag
with rosbag.Bag('output.bag', 'w') as outbag:
for topic, msg, t in rosbag.Bag('input.bag').read_messages():
# This also replaces tf timestamps under the assumption
# that all transforms in the message share the same timestamp
if topic == "/tf" and msg.transforms:
outbag.write(topic, msg, msg.transforms[0].header.stamp)
else:
outbag.write(topic, msg, msg.header.stamp if msg._has_header else t)
将 if else 替换为:
...
import rospy
...
if topic == "/my/other_topic":
outbag.write(topic, msg, t + rospy.Duration.from_sec(0.5))
else:
outbag.write(topic, msg, t)
应该可以让你大部分时间到达那里。
除此之外,如果您认为该节点将来会很有用,或者您希望它也可以处理实时数据,那么您需要使用一些队列来实现您描述的节点。你可以从topic tools,git for topic tools source 中寻找灵感。