FPC camera

FPV camera

Wilson
Copied !

The camera is just another information element. The vehicle does not use this information but makes it available to the cloud to be processed (for applications such as visual odometry) or simply watched.

We won’t really use live video but JPEG images captured at a fixed periodicity. When those images are displayed at the same speed they are captured then the sensation is that of watching live video.

Time Lapse Camera (tlcam) is a program that captures images from a USB camera and stores them in a sequence of files.

Since the Raspberry's storage is limited, only the last 20 images are saved. The program also generates a data file with the name of the last capture so that the cloud or the player knows which of the files holds the latest image.

The camera provides a first person view (FPV) to the WEB app when the camera is placed in the front of the vehicle.

Environment requirements

Ramdisk

For better performance, the images are stored in RAM memory instead of the SD FLASH. To do this we mount a disk in RAM space (ramdisk), with a root directory hanging from the Apache DocumentRoot so that the images are accessible by a WEB client such a browser.

First create a folder to use as a mount point for the RAM disk:

pi@wilson:~ $sudo mkdir /var/www/ramdisk

Then use the mount command to create a 64Mbytes disk:

pi@wilson:~ $sudo mount -t tmpfs -o size=64m tmpfs /var/www/ramdisk

You need to add the mount entry into /etc/fstab to make the RAM disk persist over reboots. Edit the /etc/fstab file and add the following line:

tmpfs /var/www/ramdisk tmpfs nodev,nosuid,noexec,nodiratime,size=64M 0 0

Remember however, that the data will disappear each time the machine is restarted.

V4L

Install the Video4Linux (V4L) library used by the tlcam program:

pi@wilson:~ $sudo apt-get install libv4l-dev

libjpeg

Install also the libjpeg library that is used by tlcam to manage JPEG images:

pi@wilson:~ $sudo apt-get install -y libjpeg62 libjpeg-dev

SW instalation

Download the tarball with the source code:

pi@wilson:~ $wget http://www.iambobot.com/downloads/wilson_tlcam.tar.gz -O ~/downloads/wilson_tlcam.tar.gz

Unzip the file you just downloaded:

pi@wilson:~ $tar -C / -xvf ~/downloads/wilson_tlcam.tar.gz

Compile the code:

pi@wilson:~ $winstall

tlcam

tlcam works independently of the Wilson program, and can even run stand-alone as a Time Lapse camera.

Is is convenient to use a camera with JPEG support. tlcam tends to support raw images in YUV but this part of the software needs still some debugging and more important is that when working with raw images the encoding needs to be performed by the Raspberry which implies a considerable additional CPU effort to the limited capacity of the Pi Zero.

To check that your camera is recognized, run tlcam with the info parameter just after you plug the camera:

pi@wilson:~ $tlcam --info

The outcome depends on the camera model. The following is the one reported by Microsoft LifeCam HD-3000:

Time Lapse Camera version 01.00.00-2020.04.12-180421
Driver Caps:
  Driver: "uvcvideo"
  Card: "Microsoft® LifeCam HD-3000: Mi"
  Bus: "usb-20980000.usb-1"
  Version: 1.0
  Capabilities: 84a00001
Camera Cropping:
  Bounds: 960x544+0+0
  Default: 960x544+0+0
  Aspect: 1/1
Formats supported:
  YUYV:    YUYV 4:2:2
  MJPG: C  Motion-JPEG
  V4L2_PIX_FMT_YUYV
  V4L2_PIX_FMT_MJPEG

The response tells us that the camera supports MJPEG and YUYV (not compressed). tlcam selects MJPEG by default when this format is available.

Test that the camera works. Connect a monitor to the HDMI port and run the program with the display option that plays the images as live video:

pi@wilson:~ $tlcam 100 display

If all goes well, on the one hand, the monitor is showing live video, on the other, the /var/www/ramdisk directory contains the JPEG files.

Run the program in normal mode, without the display option:

pi@wilson:~ $tlcam 100

Start the WEB app and check that the video is displayed.