ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

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

    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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

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

Question Tools

1 follower

Stats

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

Seen: 1,125 times

Last updated: Nov 04 '19