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

Processing bag file with ROS node

asked 2019-03-20 15:18:13 -0600

daniel-p gravatar image

updated 2019-03-21 13:15:56 -0600

I have a large bag file with sensor messages captured at 100 FPS. I also have a third-party ROS node that listens to the topic in the bag file, transforms the sensor messages, and publishes the result in another topic. The processing takes around 0.1s per message.

I would like to process the bag file with the node writing the results directly in a new bag file. I tried doing this by running:

roslaunch third-party-node third-party-node.launch &
rosbag record -O large_output_bag_file.bag output_topic &
rosbag play large_bag_file.bag

While this works, some messages seem to be skipped, probably due to the slow processing speed of the node. Also, I feel like there must be a more direct way using a single command.

Is there a standard direct way to wrap a ROS node to e.g. an executable that has a bag file as input and another one as output, guaranteeing to process all input messages?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-03-21 10:18:22 -0600

VictorLamoine gravatar image

There are two ways you can improve the behavior of your processing:

Play the bag file slower

rosbag has this functionnality, check rosbag play --help

  -r FACTOR, --rate=FACTOR
                        multiply the publish rate by FACTOR

This will play your bag file 2 times slower than the original timings:

rosbag play -r 0.5 large_bag_file.bag

Increase the queue size of your subscriber

http://wiki.ros.org/ROS/Tutorials/Wri...

Each subscriber has a fixed queue size, when a message arrives it is put in the queue and processed whenever your subscriber callback is available (the callback cannot be run in parallel). If you process messages slower than the rate of incoming messages the queue will grow. If it reaches it's limit messages will start being thrown away.


If you tweak the publish rate and queue size you will be able to process all the messages, as fast as your machine can. Unfortunately there seems to be no easy way to detect that a subscriber is throwing away messages (= checking the queue size).

edit flag offensive delete link more

Comments

If the sensor message rate is constant over time: Measure how long your subscriber callback takes for a few samples and compute the mean value. Then tweak rosbag play rate to make sure that your publish rate is just a little bit lower than the subscriber maximum frequency. You'll never loose messages and process the file as fast as possible.

VictorLamoine gravatar image VictorLamoine  ( 2019-03-21 10:20:24 -0600 )edit

Thanks for the answers! Still, is there some standard way of turning a ROS node to a "bag file processor"? Like instead of running the 3 processes as above (roslaunch, rosbag play, rosbag record) just running some node wrapper like: third-party-node-wrapper -i input.bag -o output.bag

daniel-p gravatar image daniel-p  ( 2019-03-21 13:17:11 -0600 )edit
1

Nodes are standalone executables, so there's no easy way to wrap them to run them synchronously. Some nodes are written as a library (which contains the logic) and a separate main file that sets up ROS. If your node is written like that, you could write the driver you're suggesting.

ahendrix gravatar image ahendrix  ( 2019-03-21 13:26:11 -0600 )edit

Thank you, that is what I wanted to know.

daniel-p gravatar image daniel-p  ( 2019-03-21 13:50:32 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-03-20 15:18:13 -0600

Seen: 816 times

Last updated: Mar 21 '19