4

I'm trying to configure a RaspberryPi2 to record video data from the camera module to a rosbag. To get the camera working with ROS, I used code I found here: https://github.com/fpasteau/raspicam_node.

This works fine, but I have a problem capturing the data to a rosbag. When capturing in raw mode at a high frame rate, it captures smoothly for a few seconds, then freezes for a few seconds, then captures smoothly for a few seconds, then freezes, ...

For instance, I tried capturing a file with 640x480@30FPS and this is what rosbag info yields:

duration:    2:51s (171s)
size:        2.9 GB
messages:    5049
compression: none [2504/2504 chunks]
types:       rosgraph_msgs/Log      [acffd30cd6b6de30f120938c17c593fb]
             sensor_msgs/CameraInfo [c9a58c1b0b154e0e6da7578cb991d214]
             sensor_msgs/Image      [060021388200f6f0f447d0fcd9c64743]
topics:      /camera/camera_info   2505 msgs    : sensor_msgs/CameraInfo
             /camera/image         2504 msgs    : sensor_msgs/Image
             /rosout                 22 msgs    : rosgraph_msgs/Log      (2 connections)
             /rosout_agg             18 msgs    : rosgraph_msgs/Log

So if we have 171 seconds of video, at 90FPS, that should give 15390 messages, we only got 2504, which is about 14FPS. The file itself is 2.9GB in size. This means it had an average writing speed of ~17.5MB/s. Eventually I found a command to test the write speed of the SD card (dd if=/dev/zero of=~/test.tmp bs=500K count=1024), which says my writing speed is about ~19MB/s on average.

So my questions are:

  1. If the SD writing speed is causing the problem, how come the RaspberryPi can't utilise the full 90MB/s?
  2. Can I tune the RaspberryPi to write quicker to the SD card?
  3. I thought about getting a BananaPi, which comes with SATA, so I could connect a SATA drive and shouldn't run into any write speed issues. Before making that investment, does anyone have experience with BananaPis? I saw a test here: http://314256.blogspot.co.uk/2014/11/banana-pi-sata-disk-throughput-test.html, which looks like the BananaPi should be able to handle it.
  4. Any other ideas how to make it work on the RaspberryPi?
user473453
  • 894
  • 2
  • 11
  • 23

1 Answers1

0

It looks like the raspicam_node publishes images with bgra8 encoding (raspicam_raw_node.cpp#L266), so we need to store 4*640*480*30 Bytes/second = 36.86 MB/s. However ~18 MB/s seems to be pretty much the limit on a Raspberry 2 (microSD card performance comparison).

Instead of trying to save all the raw data, have rosbag store the sensor_msgs/CompressedImage from the /camera/image/compressed topic. You can tune the <base_topic>/compressed/jpeg_quality parameter (see compressed_image_transport's dynamic reconfigure parameters), but with the default of 80 you should get around 30:1 compression ratio, i.e. 1.23 MB/s.

The Raspberry should be able to handle this easily. Given the image quality of the tiny Raspberry camera, you will probably not even perceive any difference in quality.

Laurenz
  • 1,810
  • 12
  • 25