Robotics StackExchange | Archived questions

Record .bag File via Python

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():

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

    rospy.spin()

    bag.close()

def sub_imu(data):  
    bag.write('/imu/data',data)

def sub_gps(data):
    bag.write('/gps_ublox/fix',data)

if __name__ == '__main__':
    try:
        recorder()
    except rospy.ROSInterruptException:
        pass

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.

Asked by occonni on 2019-11-04 08:04:27 UTC

Comments

Answers

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.

Asked by duck-development on 2019-11-04 13:28:15 UTC

Comments