Ask Your Question

Record .bag File via Python

asked 2019-11-04 07:04:27 -0500

occonni gravatar image

Hey guys,

I'm facing a tricky problem. I want to write incoming data (live) in a .bag file. I'm doing that this way (not via command-rosbag record), because I want to change these data a bit. The problem is: If I am writing 2 different topics in the .bag file, there are errors while replaying, e.g. parsing header error, chunk error etc. Thats just the case when writing 2 topics in the bag. I have implemented it the same way as mentioned in the API. Heres my code:

bag = rosbag.Bag('/home/bryan/Schreibtisch/ros_workspace/src/bag_recorder/scripts/test.bag','w')

def recorder():

    sub = rospy.Subscriber('/imu/data', Imu, sub_imu)
    sub1 = rospy.Subscriber('/gps_ublox/fix', NavSatFix, sub_gps)



def sub_imu(data):  

def sub_gps(data):

if __name__ == '__main__':
    except rospy.ROSInterruptException:

Do anybody know how to solve the problem? Recording both Sensors (around 50Hz and 10 Hz) with the command rosbag record works fine, but this way I need to postprocess the data via a python-script. The Errors occur at different time each time I want to record the signals. I also tried to kill this node properly via roskill or in python signal_shutdown but that won't effect the problem.

Maybe someone has an Idea.

Thank you.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-11-04 12:28:15 -0500

duck-development gravatar image

You write a node witch subscribe the nodes you like to record. Then it aplay the manipulation and republish it as an new topic then you recorded those republished topics with ros bag record.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-11-04 07:04:27 -0500

Seen: 474 times

Last updated: Nov 04 '19