ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
The python bag API is actually really easy to use. In your case something like this should work (not tested). I suppose the main question is how you want to synchronize the messages. Here I assume that the new topic should be publishes every time a new topic2 message has arrived and there was a topic1 message (anytime) before. This may not be exactly what you want, but I hope this will help you enough to get going.
import rosbag
from std_msgs.msg import Int32, String
inbag = rosbag.Bag('in.bag')
outbag = rosbag.Bag('out.bag', 'w')
try:
parent = 0;
for topic, msg, t in inbag.read_messages(topics=['topic1', 'topic2']):
if topic == 'topic1':
parent = msg
else:
if parent != 0:
parent.sub = msg;
outbag.write('newtopic', parent)
finally:
bag.close()
2 | No.2 Revision |
The python bag API is actually really easy to use. In your case something like this should work (not tested). I suppose the main question is how you want to synchronize the messages. Here I assume that the new topic should be publishes every time a new topic2 message has arrived and there was a topic1 message (anytime) before. This may not be exactly what you want, but I hope this will help you enough to get going.
import rosbag
from std_msgs.msg import Int32, String
inbag = rosbag.Bag('in.bag')
outbag = rosbag.Bag('out.bag', 'w')
try:
parent = 0;
None;
for topic, msg, t in inbag.read_messages(topics=['topic1', 'topic2']):
if topic == 'topic1':
parent = msg
else:
if parent != 0:
None:
parent.sub = msg;
outbag.write('newtopic', parent)
finally:
bag.close()