Part 2: How to build a High-Definition FPV UAV using a Rasperry PI with HD camera, using a high speed WiFi link

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

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:

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:

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:

Here is the block diagram describing all the connections:

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,  and for the ground station,    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 = 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.  

Happy Flying!

Views: 94736

Comment by Patrick Duffy on September 30, 2014 at 3:10pm

Hello MD,  My first thought on this was to use the Nano M5 on the ground because it seemed easier to mount to my tracker.  Now I think better choice would be to use two Rocket M5 devices and use the antennas found at this link.   These are not cheap, ~ $200 for the set, but maybe worth the investment. They are matched pairs of both LHCP and RHCP spiral antennas, and since they are small and lightweight and would be pretty simple to mount to a tracker. My tracker can hold about 2 lbs, but this setup is even a bit lighter than the Nano M5, so I would try the dual-rocket M5 solution if starting from scratch.  Here's a link where I purchased the M5.  I don't think you will find anything from Ubiquity that will involve a circularly polarized setup because their products are typically used in line-of-sight applications which work better with a parabolic antenna which has two elements, a vertical and horizontal dipole. This is not the best solution for a 'moving' target where you have reflections interfering with the signal. My experience with the tracker is that the GPS signal is a few moments behind the actual position of the UAV, so a narrow beam width parabolic may not work as well.  I am thinking about trying these matched pair LHCP/RHCP antennas myself, and investing in a 2nd Rocket M5 to try it out, but I have to wait a while so the 'budget' is not blown. If you decide to try it out, please do post your experience. 

Comment by Steve on September 30, 2014 at 3:36pm

Thanks for posting your setup..I like many people on here have longed for HD FPV. Couple questions I have are have you tried different cameras possibly USB based? Does the ribbon cable camera have benefits regarding decoding? I have done tests ethernet based and wifi-based and over ethernet I didn't notice lag with small SOC's but wifi was killer once I moved outdoors..I guess the Ubiquiti must be really good but I can't comprehend how small of a latency you are getting..I saw a diagram for the DJI-Lightbridge where they detailed where latency occurs on encode/decode and how much latency you can expect for different cameras they sell. But none of them were near 100ms. I wanna say 300-400ms(I might be off). Is the Ubiquiti the main reason this out performs the lightbridge? I don't know what they are using for sending/decoding but I'm throughly impressed with your results! I'm gonna have to hop on the ubiquiti train! I'd love to see some video results if you ever have time..thanks for the insight

Comment by Patrick Duffy on September 30, 2014 at 4:19pm

Hello Steve, I have not tried anything but the Raspberry PI B+ model using this setup. The Rocket M4/Nano M5 MIMO setup can do 100mbs over WiFi, so I could not detect any difference between a cat5 cable and using the Rocket/Nano M5.   It would certainly be good if somebody else duplicated my results. I spent a good deal of time finding the right setup to use for GStreamer with the PI, so there is a possibility that I left out some of the steps I did to make this work so I would like to prove it with somebody else trying my setup.  I will post a video, possibly tomorrow, showing the latency. 

Comment by MD on September 30, 2014 at 4:23pm

Patrick - Just ordered two Rocket M5s and looking at different antennas as we speak. Have everything else (Pi is a B, not b+ so maybe should change it but first I will test it). LHCP antennas are a bit sparse unless asking for them to be built but still looking. Would like to at least assess a few on paper before buying but excited to give this a try.

Comment by Artem on September 30, 2014 at 4:33pm

Immersion RC carries both RHCP and LHCP versions of their omnies and matching CP patches (i think those are crosshair):

Comment by John G. on September 30, 2014 at 4:59pm

whats the reconnect time in the event of signal loss or degradation? 

Comment by MD on September 30, 2014 at 5:13pm

Artem - Thanks for the link. Trying to find some helicals as well as the omnis. If I cant find anything I will get the ones from Circular Wireless. Just trying to understand why they command such a higher $. 

Comment by Artem on September 30, 2014 at 5:22pm

@md, those "patches" from ImmercionRC are actually CP crosshairs, which are 13dbi the are actually pretty good. they have both right hand and left hand versions. 

Comment by Patrick Duffy on September 30, 2014 at 8:39pm

I have made a video demonstrating the latency of the PI over WiFi using 1280x720 30fps, with GStreamer 1.7mbs. sample rate. As expected, the actual latency depends on the scene change. For gradual changes, it appears synchronized , for large scene changes, it's a hundreds of ms (not seconds). The screen on the left is the receiver, the screen on the right is the real time TV image I recorded with the UAV pointing at the TV.  For 720 pixels wide, it's even better, and for most FPV goggles, this is still beyond the resolution supported.

Comment by Patrick Duffy on September 30, 2014 at 8:48pm

I found these matched RHCP/LHCP matched pairs that look like they would work, but I could not find a gain spec. I have a similar antenna I am using for my analog video that has twice the number of turns, and it is advertised as 16dbi, so these probably are around 12dbi. 


You need to be a member of DIY Drones to add comments!

Join DIY Drones


Season Two of the Trust Time Trial (T3) Contest 
A list of all T3 contests is here. The current round, the Vertical Horizontal one, is here

© 2019   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service