Rewriting a message into a new rosbag

asked 2016-07-20 12:45:51 -0500

Joy16 gravatar image

I have a rosbag that publishes the paths of a robot only once. I am writing a plugin to visualize it, so I want to rewrite the message again and again into my new rosbag. Below is the code, I am not sure if it is right, because my new rosbag doesn't publish it in constant fashion.

import rosbag
import random

with rosbag.Bag('Plugin.bag', 'w') as outbag:

    for topic, msg, t in rosbag.Bag('2016-07-18-16-06-32.bag').read_messages():
        if topic == "/input/path_manager/path" and msg.header:
              msg.header.frame_id = "map"   
    "path"+ str(random.randrange(1,200))
              outbag.write(topic, msg, t)
        if topic == "/tf" and msg.transforms:
              outbag.write(topic, msg, t)
edit retag flag offensive close merge delete