Part Two: Here is the original picture of the finished product:

3689618661?profile=original

This is the second part of a 2-part series on 'How to build a High-Definition FPV UAV using a Raspberry PI with HD camera, using a high speed WiFi link.

In my first post on the subject (located here), I discussed the parts I used, and how to install them into a Hobby King Go-Discover FPV model. 

In this post, I will discuss installing the Raspberry PI and the PI camera in the Go-Discover gimbals, and the software configuration for both the Raspberry PI and the ground station PC.

From the previous post, step 3 was completed by installing the Ubiquity Rocket M5 in the model.  Now onto step 4:

Step 4: Install the Raspberry PI and PI Camera

Here is a photo of the position of the PI in the Go-Discover model:

3689618887?profile=original

The PI fits nicely just behind the camera gimbals, with the USB and HDMI ports on top. In the right side you can see the Cat5 network cable attached. This cable connects to the ethernet switch, which is also connected to the Rocket M5 input port.  

The two cables shown on top are the servo control wires for the gimbals, which I have directly connected to channel 4 and 5 on my radio.  I am using channel 4 (normally the rudder stick on my radio. Since there is no rudder on a flying wing, this is a convenient channel to use to move left and right with the camera. I have not (yet) moved to a head tracker, but if you already have that setup, just assign the channels accordingly.

To install the PI camera, remove the stock plate from the gimbals (for a GoPro), and mount the PI camera as shown in this photo:

3689618926?profile=original

The PI camera case fits very nicely into the slot, and again I used a small piece of velcro to hold it down. You could use a couple of small screws instead if you want a more secure hold.  The two gimbals servos are also shown here. They are simple to install, just follow the Go-Discover instructions.

Here is a front view of the PI camera installed:

3689618962?profile=original

Here is the block diagram describing all the connections:

3689618829?profile=original

Some comments on my previous post suggested that it is possible to eliminate the ethernet switch and serial-to-ethernet converter using the Raspberry PI and a serial port on the PI. I believe this post describes how to talk to the PI via the NavLink, but in this case, I want to use the PI to bridge the connection from the ground station to the APM/PixHawk. Somebody please comment on this if you know more about it.   I believe it would require a TCP/IP to serial link from the PI to the telemetry port on the APM, and some software on the PI to act as the bridge.  The main connection to the ground station is via the Rocket M5 and TCP/IP, not through a telemetry link (900 Mhz or Zigbee like I used on my other models).

Step 5: Getting it all to work with software configuration (the really fun part starts now).

Check out this post on what others have done with streaming and the PI.  My experiments showed that using GStreamer on both the PI and on Windows gives really good results with very low latency, if you use the right parameters. 

Get GStreamer on the PI by following this blog.   This is the same version of GStreamer that I am using on my setup. 

Make sure your PI camera works ok by plugging in the PI to a standard monitor using the HDMI port and follow the instructions on the Raspberry PI website on how to get the camera up and running (without GStreamer).  Once you have a working PI and camera, you can then proceed to stream things over the network.  

Note: It is suggested that you first get the PI streaming video by plugging it directly into your local network where you can also connect your ground station PC with the correct IP addresses (without the Rocket M5).   For my PI, I picked 192.168.1.2,  and for the ground station, 192.168.1.1.    Make sure you can ping the PI from your PC and the PC from the PI.  

For streaming, you will also have to make sure all the ports you intent to use are open on the firewall (described later).

For the ground station PC,  you can download GStreamer here.  Make sure when you install, select to install everything , or full installation (not the default). 

Here is the command I use for the PI to pipe the camera output to GStreamer:

raspivid -t 0 -w 1280 -h 720 -fps 30 -b 1700000 -o - | gst-launch1.0 -v fdsrc ! h264parse config-interval=1 ! rtph264pay ! udpsink host = 192.168.1.1 port= 9000

The command is explained as follows:

raspivid is the command to start the camera capture on the PI.  The -w switch is for the width in pixels, and the -h switch is for the height.  In this case, I am using 1280 X 720, but you can try any combination that fits your needs. 

The -b switch is the bit rate for the sampling. In this case I chose 1.7mbs to send over the stream. Again you can experiment with higher or lower values. This settings seems to work good for me, and the latency is almost unnoticeable.  

the "-o - |" is piping the output to gstreamer.  Make sure you include the dash before the pipe "|" symbol. 

For the GStreamer command, all the filters are separated with an exclamation point "!", as these are individual drivers that are part of GStreamer.  Since the PI has hardware accelerated video, the output is in a format called "H264", which is a highly-compressed stream. The GStreamer filters are configured to transport the output via a UDP socket connection to the target PC. Notice the 'udpsink' element which specifies the host - in this case your ground station, and the UDP port.  I am using port 9000, but you can use any open port on your system, but be sure to open the firewall or it won't work!  You can also use TCP instead of UDP, but for such a data stream, I chose to use UDP since dropouts are certainly possible, and with UDP this is ok, but with TCP, you could have socket problems and higher latency. 

Note: to get the PI to execute this command on boot, make a shell script with the above command and add it to your local.rc boot sequence. That way when the PI boots, you get the stream without having to log into the PI remotely. 

For the ground station PC, once you have installed GStreamer and opened the correct ports, use this command (from the command prompt) to view the stream:

c:\gstreamer\1.0\x86_64\bin\gst-launch-1.0 udpsrc port=9000 ! application/x-rtp,encoding-name=H264,payload=96 ! rtph264depay ! avdec_h264 ! videoconvert ! autovideosink

If all goes well, you should see the PI camera output on your PC screen in a popup window.  For those of you what want to use FPV goggles, you can connect to the HDMI port on your PC to display the output if your goggles support HDMI. 

I have this command in a batch file (with a PAUSE) statement at the end to keep the window open.

WHEW!  If you got this far, you are amazing. 

The last step to complete the build is to connect to the APM from mission planner.  The method I used to connect was to install a utility that converts a TCP connection to a virtual serial port, but I also think that directly connecting the mission planner to the TCP port will also work, however I have not tried it. I will post back later after trying it.

Here is the link to setup the serial to ethernet device to have an IP address and port.

Here is the link to the configuration utility for installing the virtual serial port.   

Once you have a serial connection over TCP/IP working to the APM, you should be able to connect with Mission Planner. On the maiden flight, it worked perfectly, and I didn't see a single drop in the telemetry data or anything noticeable in the video transmission, however my first flight was limited to 2km.

The last step is to connect the Rocket M5 to the Nano M5 and test everything using the OTA (over the air) connection. If all is well, you are ready to fly!  But be careful on your maiden, you just spent $700. 

Finally, here is a photo of my Antenna Tracker with the Nano M5 attached. My next update will include a video of a longer flight.  

3689618942?profile=original

Happy Flying!

E-mail me when people leave their comments –

You need to be a member of diydrones to add comments!

Join diydrones

Comments

  • @Kendall,  sorry for the late response I have been out of town on a medical issue. I'll post the script as soon as I get back home. 

  • Hello  Patrick

    Thanks a'lot For Your Great Project

    if your Wifi Link Is duplex, is correct at Uav side you use "skew planar" Antenna with low gain and at ground station use 13 db helical antenna?   

  • Any updates Patrick?

  • Yes Please

  • @Kendall,   Thanks for the tip on the v4l-ctl, I was able to turn off the auto-focus on the C920.   

    I just compiled gstreamer 1.4 on my PI2 from source using a single shell script.  If you are interested, I can post it.

  • Here Gstreamer 1.2 includes uvch264src but, it was compiled from source on a BeagleBoneBlack/ Ubuntu

    I have the Pi v2B and not able to locate a source

    Here:http://www.oz9aec.net/index.php/gstreamer/487-using-the-logitech-c9...

    How to compile here:http://wiki.oz9aec.net/index.php/Building_Gstreamer_1.2_from_source

    D. Derek Malloy has very interesting blog on this topic as well. Again on the BBB.

    http://derekmolloy.ie/udp-video-streaming-beaglebone-black/

    http://derekmolloy.ie/streaming-video-using-rtp-on-the-beaglebone-b...

  • @Kendall,  for most of my projects I use the RPi camera and not the C920 but I am giving the C920 a try.  I just built a multi-rotor and mounted a C920 just to compare the two.  

    For later versions of GStreamer, the v4l2 plugin has limited control over the C920 so I have not tried using v4l2-ctl.  I think uvch264src is obsolete, as it has been replaced in the v4l2 plugin. Here is the pipeline I am using with the C920 on the UAV:

    gst-launch-1.0 -v v4l2src device=/dev/video0 ! video/x-h264, width=1920, height=1080, framerate=30/1, bitrate=4000000 ! h264parse config-interval=1 ! rtph264pay ! udpsink host={CGS_IP} port=9000

    Other than setting the stream to run H264, I would like to try setting the auto-focus to turn it off during a flight as my test yesterday seemed to indicate that the camera was constantly changing the focus, which was quite annoying.  

    For splitting the stream/multicasting (UDP or recording), I am splitting the stream on the GCS and not the UAV. Here is the pipeline string I am using to record the stream:

    udpsrc port=9000 buffer-size=60000 ! application/x-rtp,encoding-name=H264,payload=96 ! rtph264depay ! h264parse ! tee name=record ! queue ! avdec_h264 ! video/x-raw, format=I420 ! d3dvideosink sync=false record. ! queue ! mp4mux ! filesink location = /temp/fpv.mp4

    This works for either the RPi or the C920.  This pipeline splits the stream to a second device (Android phone):

    udpsrc port=9000  buffer-size=60000 ! application/x-rtp,encoding-name=H264,payload=96 ! rtph264depay ! h264parse ! tee name=split ! queue ! avdec_h264 ! video/x-raw, format=I420 ! d3dvideosink sync=false split. ! queue ! h264parse config-interval=1 ! rtph264pay config-interval=1 ! udpsink host= 192.168.0.143 port=9000

     

  • Patrick,

    Streaming in real time live video from the C920, taking advantage of it's h.264 output, freeing transcode processes and output to multicast udp: ip/port for ground station(s)

    I see that uvch264_src will accept the C920 h.264 output combined with v4l2 and multicast output using about 15% of the Pi cpu.

    I read that "Logitech C920 sometimes drops the next to last segment of RAW aux data contained within the MJPEG container. H264 data that is multiplexed with in the same container does not appear to be affected. This appears to be a bug in the Logitech C920 firmware and uvch264src should not error out in this case. Sometimes it can take 24 hours of continuous streaming for the problem to occur, but sometimes it takes only a couple of hours". https://bugzilla.gnome.org/show_bug.cgi?id=706276

    Another advantage of v4l2 are the utilities allowing camera setting to be changed "on the fly" not effecting the Stream

    v4l2-ctl

    - brightness (int) : min=0 max=255 step=1 default=128 value=128
    - contrast (int) : min=0 max=255 step=1 default=128 value=128
    - saturation (int) : min=0 max=255 step=1 default=128 value=128
    - white_balance_temperature_auto (bool) : default=1 value=1 - gain (int) : min=0 max=255 step=1 default=0 value=0
    - power_line_frequency (menu) : min=0 max=2 default=2 value=2
    - white_balance_temperature (int) : min=2000 max=6500 step=1 default=4000 value=4000
    - sharpness (int) : min=0 max=255 step=1 default=128 value=128
    - backlight_compensation (int) : min=0 max=1 step=1 default=0 value=0
    - exposure_auto (menu) : min=0 max=3 default=3 value=3 (0: Auto Mode 1: Manual Mode 2: Shutter Priority Mode 3: Aperture Priority Mode)
    - exposure_absolute (int) : min=3 max=2047 step=1 default=250 value=250 - exposure_auto_priority (bool) : default=0 value=1 - focus_absolute (int) : min=0 max=250 step=5 default=0 value=0 - focus_auto (bool) : default=1 value=1
    - zoom_absolute (int) : min=100 max=500 step=1 default=100 value=100

    I do not know how to find the correct libraries. libs, core, base, good, bad, ugly or the proper pipelines for multicast udp/port at each end.

    Both uvch264src & v4l2 were included in GStreamer .10

    Bug 706276 – uvch264src: don't error out on incomplete aux data segment with Logitech C920
  • @Kendall,  I think you are referring to the C920 settings? Please do post anything you have that will improve the performance. I have not measured the latency of the C920 but it's comparable to the PI cam, which is around 120ms for 720p.  

  • Forgot, you will also get two streams... one HD and one low res....all at the cost of about 12-14% Pi 2B cpu and about 160ms latency

This reply was deleted.