Building an embedded circuit for a UAV

All off topic discussions go here. Everything from the funny thing your cat did to your favorite tv shows. Non-programming computer questions are ok too.
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Building an embedded circuit for a UAV

Post by AndrewAPrice »

I want to undertake a project to turn an RC plane into a UAV. The way I'd like to do it is to build a light-weight onboard computer, which places me into the realms of embedded programming which sounds challenging yet like a lot of fun (programming for something practical that interacts with the world!)

I wish to have my own code running on an embedded processor controlling the RC plane. Rather than the RF receiver directly controlling the engines and servos on the plane, I'd like the RF receiver to pass them to the processor which will then control the plane. While flying, the processor will read from an onboard gyro and stabilize the plane, and if it detects it's not receiving a signal from me (out of range) the plane will turn and head back in my direction. I would also like the processor to log the flight's GPS coordinates, record a video of the flight and save this onto an on-board USB flash drive that I can later remove and plug in to my computer afterward and watch a playback from the plane's POV.

In the far future, I'd also like to set up way points and when there is no RF signal (I turn the hand controller off) it'll automatically fly the route programming into it.

The problem with all of this isn't the programming involved, but the components I require and, just as importantly, how to connect them.

From my research so far the basic concept is to reroute the RF receiver to a bunch of ADCs so the processor can understand it. Then the processor communicates to a set of ADCs that control the engines and servos. I've later come across these nifty things called microcontrollers/Systems-on-a-Chip which contain ADCs, DACs, an IO controller and occasionally a USB or ethernet controller all in a single IC which is the way I want to go. So from there I'm assuming it's just as simple as connecting each device through an IO channel and make sure each is receiving it's correct power, and away you go. But it can't be that simple (or that complex because I have no clue where to start!)

I know that I will need a debugging/flashing kit for the microcontroller. Most microcontrollers I've come across are simple 20MHz systems, that while they will be able to handle flying, I don't think they will be able to handle streaming live video onto a storage device, so I'm looking at ARMs which seem to have decent processing power. For example I've come across this 400MHz ARM9 with 64KB ROM while also being reasonably priced:
http://search.digikey.com/scripts/DkSea ... G20B-CU-ND
My first concern is it says 64KB of RAM - can I use external memory? This is a lot if I didn't want to record video (in which case I would have gone for a 20MHz controller), but even a 640x480 gray scale image would use up 300KB alone.

I've found other components I'd like to use:

5MP camera (quite impressive - it records 1920x1080 at 30fps, 1280x720 at 60fps - I'd need a lens though)
http://search.digikey.com/scripts/DkSea ... 84-1017-ND

14 Channel 10Hz GPS receiver
http://www.sparkfun.com/commerce/produc ... ts_id=9060

Analogue temperature sensor (which I assume goes through the microcontroller's ADC)
http://www.sparkfun.com/commerce/produc ... ts_id=9438

2 axis gyro: (I wonder why 3 axis gyros are rare, I guess I need to buy a 1 axis gyro and mount it sideways to measure roll)
http://www.sparkfun.com/commerce/produc ... ts_id=9425

While these components seem to do what I want I don't know how to get them to work together, and I know I need a lot more components (like the USB controller). Also the camera outputs a raw RGB stream which is ((1280x720*60fps*10-bits)/8) 65MB/s which could quite simply overload the processor, so I might have to look into a dedicated MPEG encoder (Digikey doesn't stock these unless you order mass quantities, and I also don't know if they will be compatible with the format the camera outputs) which then feeds a compressed signal to the microcontroller.

So basically I know what I want to achieve, but no clue where to start. I would appreciate if someone could give me a rundown of the components I require since I haven't done anything like this before. And my mind is filled with a lot of other questions. How exactly do I connect each sensor up to the micro-controller (do I directly connect an IO pin with a pin on that component, or must I de/multiplex it or change the voltage)? How do I calculate the total power consumption of each component?

Thanks.
My OS is Perception.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Building an embedded circuit for a UAV

Post by Combuster »

I'm planning on building a semi-autonomous robot at the local hackerspace, and my design is largely based around a Nokia smartphone (found someone who repairs broken ones and I plan on getting a semi-defective one for cheap there). Not to use as a spy plane, but to process the camera input and feed the results via a neural net to a pair of motors. The good thing about a smartphone is that you can easily start off programming the key components as (in the right model) you have camera, GPS, flash storage, and wireless networking. I planned on using the car kit port as a communication channel to the engines (in simple terms: left earplug, left wheel, right earplug, right wheel)

You could do with less, like just grabbing an 10 MHz AVR and doing all the routing stuff, and dedicating an old cellphone for video recording and nothing else. It saves you some trouble of manually building a high-speed ARM board.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: Building an embedded circuit for a UAV

Post by thepowersgang »

I agree with combuster, it would be easier to have the camera be a separate system to the control systems as, unless you are doing image processing on board for navigation, the nav/control system doesn't need to know about the video feed. Your could essentially just strap a cheap digital camera to the bottom of the plane, along with a large memory card and set it recording.

Also, could you document your attempts, there's a guy I know who's doing a similar sort of thing (except with it being internet RC, instead of radio/gps)
http://wiki.ucc.asn.au/LURC
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Building an embedded circuit for a UAV

Post by AJ »

Hi,

For a forum I have found useful in the past with this sort of thing, see AVR Freaks.

Cheers,
Adam
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: Building an embedded circuit for a UAV

Post by Owen »

That chip is way outside your (And most people's) capabilities. It comes in a 217-LFBGA package. Thats about 15x15m, 217 pins spaced at a ridiculously close interval. You'd need at least a 4 layer PCB of your own design.

Basically, to use that, you'd need to pay a company to assemble the design for you. Expect to pay $1,000, whether you order one or 100 - most of the cost is one off setup fee.

Your best bet is to use something like an AVR, or my preference, a dsPIC, and handle the video some other way (Perhaps get one of those wireless video recorders?). Particularly if you use one of the motor control dsPICs, it will have a large bank of PWM outputs for controlling motors (Be they normal motors, in which case it will control speed, or servo motors, in which case it will control position). Additonally, it will have ADCs for reading analog sensors, lots of digital I/O for digital sensors, and they run at 40MIPS (Well, the dsPIC33s do, the 30s at 30MIPS), and are designed for this kind of stuff. They come in hobbyist friendly DIP packages (Surface mount packages are doable, but harder to prototype with, and you'll need to design and fabricate a PCB, etc), and even better, you can normally get a few samples off Microchip free. The PICKit2 programmer costs $35 and is all you need to program them.

I'd strongly advise getting whatever chip you want to use and playing around with it first, of course.
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: Building an embedded circuit for a UAV

Post by earlz »

I would agree with what others said, don't try to make a huge project on your first go.

I would suggest either a digital camera for recording or possibly building another board with an AVR and small little camera part(one at sparkfun has 640x480 w/ color capable of onboard JPEG compression and streaming video) and then setting up a micro-SD/SD card writer for writing out the video, and then having all your flight control stuff isolated from it. If your batteries go dead in your camera you don't want the plane to die do you? lol

But yea, AVRs are very hobby friendly... You might want one of the better ATMegas for your flight control because with a lot of them you only get like 4kb of code ROM, which probably won't be enough for anything complex like that..

Also, another thing you might want to try, at Sparkfun there are these little ultrasonic detector things that will detect how far away an object is. You may want to invest in a few of those so your plane has a chance of not running into "unexpected" objects. They sell there for like $20, and just one would suffice if you get one with a very wide beam..
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: Building an embedded circuit for a UAV

Post by Owen »

Depending on the complexity of the control code, an ATMega won't cut it.
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: Building an embedded circuit for a UAV

Post by AndrewAPrice »

@Owen: Is this what I'm looking for? http://www.microchip.com/stellent/idcpl ... e=en532453

I also like the fact that the PIC32 has a USB controller, and it's 80MHz/>100MIPS. I'm installing MPLAB so I can try out the emulator first.

@Earlz: There is actually a reason I want high definition video (at least 720p) - I want to do aerial video photography. All of the remote videoing stuff is limited to analogue PAL/NTSC with static over long ranges and Wi-fi doesn't reach very far and has high power consumption.

Perhaps this encoder: (by the same company that make the camera)
http://www.ovt.com/products/ip_detail.php?id=7
and use the USB interface to interface with the PIC32 (the datasheet says the PIC32 supports fullspeed 12Mpbs USB2.0) which then writes onto an SD card. My concern now is if the 80MHz PIC32 would be fast enough to stream that onto the SD card
My OS is Perception.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Building an embedded circuit for a UAV

Post by Combuster »

hmm, aerial photography != filming. Those are two distinct pipelines. HD video processing requires a high end computer. Even on a 400MHz ARM, when you want to do some simple processing on the video (yuv->rgb conversion, then copying to the screen), you can reach atmost 12fps at 640x480. If you don't need the framerate, you can make photos instead, pipe the data out, then make the next photo.

In my case, it works out to about this relation: processor frequency / 100 = sustainable pixels per second.

Also, from what I've seen, even high resolution camera's don't do more than 640x480 in realtime because of the sheer amount of data (try it, 5 megapixel * 3 color channels * 8bpp = 120Mbit per frame, you do the rest). You will really need to make photo's in that case.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: Building an embedded circuit for a UAV

Post by AndrewAPrice »

A bit of bad news, the PIC32's USB 2.0 interface is 12Mbit/s which I mistakingly took as the maximum USB 2.0 speed, but USB 2.0 can operate as high as 480Mbit/s. :( ARM is still a serious contender.
Owen wrote:You'd need at least a 4 layer PCB of your own design.
Could I buy a 15mm x 15mm LFBGA socket, solder wires to the underside of the socket (like this but replace the IC with an empty socket), and then connect the other end of the wires onto a 2d circuit board? (well.. wiring 214 pins through a socket would be tedious :shock:)
Combuster wrote:hmm, aerial photography != filming. Those are two distinct pipelines. HD video processing requires a high end computer. Even on a 400MHz ARM, when you want to do some simple processing on the video (yuv->rgb conversion, then copying to the screen), you can reach atmost 12fps at 640x480. If you don't need the framerate, you can make photos instead, pipe the data out, then make the next photo.
My idea wasn't to actually process the video in real-time, but just copy the stream coming from the encoder via USB into a file on a drive, which I could then post process on my computer to extract the video if need be. The most important thing is that the video stream is captured.

Anyway, going back to the OV550-B49 encoder that I was looking at, it states:
Embedded 8-bit Microcontroller: Embedded 512-Byte data memory, embedded 12KB program memory
Miscellaneous: Embedded 3.3V to 1.8V regulators, embedded PLL, optional external serial EEPROM, general purpose I/O (GPIO), power-down control
I was wondering if that means the microcontroller is used in the encoding process, or a microcontroller free to run my own code on. If the latter is true, then could I could make the encoder act as a USB host rather than a device and plug a USB flash drive directly into it, avoiding the need to send the video through the other microcontroller. Also, if it handles GPIO, then I could connect the PIC32 (which would be handle flight stabilization and reading sensors) to it for when I want something logged such as periodical GPS readings onto the flash drive.

I'm quite excited if the OV550-B49 turns out to be a general microcontroller. I could basically build my own camera just by connecting two ICs.

EDIT: I contacted the manufacture to ask them if it'll suit my needs.
My OS is Perception.
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: Building an embedded circuit for a UAV

Post by Owen »

Sorry, I made a slight mistake in my post: The "BGA" means "Ball Grid Array". That means tiny (0.25mm spacing!) solder balls arranged in a grid.

Completely un-hand solderable. Besides, at speeds > 50Mhz, wiring like that doesn't work (Noise, capacitance, impedance issues..)

The PIC32s are the most powerful processors I've seen in a package that a hobbyist can handle (64 or 100pin LQFPs are very easy to solder to circuit boards with enough knowhow); however, designing a board for a 64-pin chip with 0.5mm spaced pins should not be anyone's first electronics undertaking!

Note that the video encoder you linked to also comes in a 49-BGA. Sure, 49 balls is a lot less to route; you could do it on a 2 layer board, like the PIC32. But it's a BGA. Again, not something you can solder with an iron.

Look at the picture on the page you linked to. Thats what the chip looks like. And it's small enough to fit on your little finger. It's a mobile phone component; they're all useful, low power, and impossible for hobbyists (and small businesses) to work with.
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: Building an embedded circuit for a UAV

Post by AndrewAPrice »

Owen wrote:Note that the video encoder you linked to also comes in a 49-BGA. Sure, 49 balls is a lot less to route; you could do it on a 2 layer board, like the PIC32. But it's a BGA. Again, not something you can solder with an iron.
So I couldn't try a SchmartBoard (they send out free samples too and come in a range of shapes and sizes)?

(I also found this http://www.instructables.com/id/Toaster ... ering-BGA/)
My OS is Perception.
whowhatwhere
Member
Member
Posts: 199
Joined: Sat Jun 28, 2008 6:44 pm

Re: Building an embedded circuit for a UAV

Post by whowhatwhere »

I'll just linkdump here since I'm also doing this sort of thing.

DIYDrones
Arduino

Read both.

EDIT: I suppose it's better to give some of my thoughts as well.
1) I'd say start with the kit. It's the best damned thing I can find, and it's cheap as hell. It also gives you all the styrofoam plane body and proper places to mount the Arduino controller board. It's all open source and easy to follow. You _can_ build your own bootstrap (as in the software required to control the servos and such yourself) but it really won't make that much of a difference for the average person.
2) Your video processing issues are nil. Instead of processing it onboard, send it via a UHF transmitter. (http://www.youtube.com/watch?v=dhC5i5DJxVI for details. Costs alot. Works wonders.)
3) There are a ton of resources out there for people that are into this sort of thing. Me? I've had lots of ideas, but I don't have much money for these sort of hobbies.
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: Building an embedded circuit for a UAV

Post by Owen »

MessiahAndrw wrote:
Owen wrote:Note that the video encoder you linked to also comes in a 49-BGA. Sure, 49 balls is a lot less to route; you could do it on a 2 layer board, like the PIC32. But it's a BGA. Again, not something you can solder with an iron.
So I couldn't try a SchmartBoard (they send out free samples too and come in a range of shapes and sizes)?

(I also found this http://www.instructables.com/id/Toaster ... ering-BGA/)
Have you ever soldered anything surface mount before? Get very used to it before trying a BGA. Also get used to routing boards with lots of traces.

BTW, the codec chip you linked to hasn't even reached the engineering samples phase yet.
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: Building an embedded circuit for a UAV

Post by AndrewAPrice »

What about FPGAs?

The IC's I've found only support a certain type of video-format input (YUV not RGB) or they have a limitation in their resolution, output format, interconnectivity.

I did some more research in to FPGAs and there are several hobby-friendly kits around. To add to that I've found open-source HDL H. 264 encoders and USB controllers, so if all I want to do is save a 10-bit RGB 1920x1080@30fps stream from the camera onto a USB flash drive, then I could do the entire thing in hardware logic on an FPGA?

Actually, I have no clue where to start. What do I look for in FPGAs? I assume there is a limit to the logic/speed of each chip, for example you can't synthesize a 10Ghz CPU on a cheap $10 kit?
My OS is Perception.
Post Reply