Sunday, August 16, 2015

Programming a generic STM32F103C board in Arduino

A while back I purchased some generic STM32F103C8T6 development boards on eBay for about $4 each.  I initially had some limited success programming them using the GCC ARM Embedded (eabi) toolchain and a generic STM32 loader program.  Since then I've discovered a project to get them working with the Arduino 1.5+ toolchain.

There's a lot of different information about the various STM32 boards out there.  I'm documenting my notes here mostly for my own sanity since I don't play with these boards often.  Maybe you'll find it useful too.

Arduino hardware library for these boards:

"Support" forum:

The USB port
The generic boards do not have a meaningful USB bootloader.  The USB port is only useful for power.  (TODO: Flash the "Maple Mini" bootloader onto them for future ease of use?)

Arduino Board Selection & options
Tools -> Board -> Generic STM32F103C
Tools -> Variant -> "STM32F103C8 (20k RAM. 64k Flash)"
Tools -> Upload method -> "Serial"

FTDI / Serial connection
Connect 3.3V FTDI USB -> Serial programmer as follows:

  • STM32 UART0 TX pin A9 -> FTDI RX
  • STM32 UART0 RX pin A10 -> FTDI TX

I use the GND and 3.3 pins on the 4-pin header for power, but the ones on the IO pads work fine too.

Program / Run Jumper
  • Run mode:  Both jumpers at "0"
  • Program Mode: Jumper 0 (top) at "1"

With J0 set to "1", press "reset" just before hitting "upload" in Arduino to flash firmware.  Program will run immediately after flashing, but won't run after power-cycle until you set Jumper 0 back to "0".  (??)
I have no idea what the bottom jumper is for.

PC13 LED seems to be wired from +3.3V to the PC13 pin.  So setting the pin low lights the LED, and setting it high extinguishes it.

That's it!  With any luck, after loading the above library and following these notes you can push Arduino sketches to your super-cheap, 72MHz STM32 ARM board.


Sunday, July 26, 2015

Arduino-based barometric altimeter / altitude deviation alerter

While working on my instrument training, it occurred to me that I had everything I needed in my parts bin to build a device to help alert me to deviations in altitude. So, I built MonkeyAltimeter.

It started off on a breadboard while I worked on the code:

Then, I took it for a flight test (primarily to see how accurate it was in the cabin and see if my VSI routine worked):

Finally, I designed and printed a simple case for it:

The details,  parts list, operation manual, &etc are here:

The source code is here:


Thursday, April 9, 2015

My comments on FAA NPRM for "Operation and Certification of Small Unmanned Aircraft Systems"

have finally submitted my comments to the FAA's NPRM for model aircraft. After reading the proposed regulations, reading the responses from various advocacy groups, and considering both sides I have submitted the following. If you would like to comment to the FAA as well, the link is here:!docketDetail;D=FAA-2015-0150
The deadline for comments is April 24th, 2015.


I am a computer engineer, r/c model enthusiast, private pilot, and aircraft owner. I am writing in response to the FAA's proposal to regulate small unmanned aircraft systems, including model aircraft.

I support the exemption of recreational model aircraft from the regulation of unmanned aircraft systems.

I understand the critical need to maintain separation of the increasing proliferation of radio control and hobbyist unmanned aircraft ("model aircraft") from other aircraft in the national airspace system. I do not agree that trying to interpret model aircraft as being subject to the existing aircraft regulations is a productive way to accomplish this. Model aircraft have more in common with the existing (exempt) classes of amateur rockets, balloons, and even ultralight human-occupied aircraft than they do with the aircraft regulated under 14 CFR.

I agree with the Academy of Model Aeronautics points about the proposed regulations regarding model aircraft. Specifically, with my concerns added after each one:

AMA point:
• Rigidly defining a requirement to operate within visual line of sight and that calls into question the use of a specific technology or equipment, namely first-person view (FPV) goggles. The language of the 2012 statute concerning "within visual line of sight" indicates how far away a person should fly the model aircraft, not what method of control may be used for the recreational experience. The proposal for commercial unmanned aircraft acknowledges that an observer (spotter) can be used to ensure airspace safety, just as the AMA's community-based safety guidelines do.

My comments:
Many operations of "FPV" flying and equipment are done in close proximity to the ground, and in places where incursion with other aircraft in the national airspace system are impossible. The FAA should not preclude this fast growing activity, as it poses no threat to the nation's airspace or aircraft.

AMA point:
• Narrowly interpreting the words "hobby or recreational use." You should not regulate people who are flying model aircraft in connection with the hobby just because they receive payments. For decades, enthusiasts have participated in contests and competitions that have cash prizes, have been paid to instruct others on how to safely fly models, and have received compensation for aerobatic displays. These payments incidental to the hobby do not change the underlying recreational purpose of the activity or make the hobby any less safe, and regulating these activities would be highly disruptive to the hobby without any benefit.

My comments:
The adoption of advertisement driven technology has also blurred the line between "for compensation" and not. Hobbyists naturally want to share their love and enthusiasm for their activities, and in doing so will use "free" computer platforms like online blogs, YouTube, social networks, and other "cloud" based services. Many of these services are supported by "monetizing" the content, that is to say- selling advertisement space capitalizing on the popularity of the user-driven content. The FAA's guidelines for what constitutes "commercial" or "for hire" operations does not take into account this corner-case, and as such has been interpreted multiple (inconsistent) ways.

I recommend that the FAA more broadly accept model aircraft operation by hobbyists as "non-commercial."

AMA point:
• Making model aircraft subject to airspace requirements such as air traffic control clearance, that have never been applicable in the past and with which it is impossible or impractical to comply. Congress indicated the maximum obligation, which is actually stricter than what the FAA's guidance has been for the past 34 years: notifying the airport when operating within five miles. That is the most that model aircraft hobbyists should have to do.

My comments:
I support the FAA's efforts to keep the national airspace system safe for all operations within it. We need a clear, concise definition for what is and isn't allowed for hobby model aircraft. This may (by necessity) include airspace restrictions, airport proximity restrictions, and altitude restrictions. I encourage the administration to consider both sides carefully, and avoid blanket restrictions (on either side) that are difficult to interpret or comply with.

It's easy (and possibly convenient) to say "no operations within Class Bravo airspace." 
Consider that most model aircraft are operated within a few hundred feet of the ground, though, and much of the Class Bravo "Surface Area" actually becomes safely usable by the model aircraft community. I think there is a middle ground between what the AMA recommends and what the FAA has proposed, and I hope we are able to find it for the sake of both communities.

Thank you for providing us the opportunity for comment.

Kenneth C. Budd
AOPA Member # 03890068
EAA Member # 1132133
AMA Member # 1050433

Sunday, February 15, 2015

Initial reaction to NPRM 2015.02.15: Operation and Certification of Small Unmanned Aircraft Systems

The FAA's NPRM for operation of unmanned aerial systems has been published as of today.

Most of the commentary online is about the commercial use of UASs, which is, by far, the most interesting aspect. However, many are dismissing the entire NPRM as "having nothing about recreational flying."

This isn't exactly the case.  This post will address my reaction for recreational / hobbyist use.

The NPRM has an important distinction for recreational use- it adds Subpart E to "PART 101—MOORED BALLOONS, KITES, AMATEUR ROCKETS AND UNMANNED FREE BALLOONS", establishing the definition and rules for recreational flying.  By and large, it just codifies into law the existing requirements of the previous advisory circular. It is largely very reasonable.

That said, so far I have two comments on this I will be submitting to the FAA.  This is my initial reaction, so my specific comments and wording may change as I have more time to read and consider this document in the context of the larger framework of regulations.  But I wanted to get my thoughts out there while they were still fresh in my mind.

[...] denotes cuts by me for brevity: 

---- one: ----
§ 101.1 Applicability.(a) [...]
(ii) Flown within visual line of sight of the person operating the aircraft; and[...]

My comment: Does "within visual line of sight" assert that the operator must be looking at the aircraft at all times, or that it merely must be within range of visual sight at all times? If it's the former, does this preclude any operation using "First Person View" (FPV) video equipment on-board the aircraft, in all circumstances?
I understand the very important need to keep these aircraft separated from other aircraft in the NAS. An outright ban of FPV flying in all circumstances is not a good approach though, as it is one of the fastest growing areas of recreational flying and will likely be undertaken by many whether or not it is permitted.
If the intention is to ban FPV flying for fear of NAS separation issues, I would highly recommend instead that the administrator consider circumstances where NAS separation isn't an issue and exclude the "visual line of sight" requirement from those circumstances. (E.g. limited altitude & range, private property, &etc.)
---- two: ----
§ 101.41 Applicability[...]
(b) The aircraft is operated in accordance with a community-based set of safety guidelines and within the programming of a nationwide community-based organization;[...]

My comment: If I were the NTSB, I would question the validity of applying "law by proxy" to a set of community safety guidelines that have not been vetted via the NPRM rulemaking process. I'm not a lawyer, so I don't know the ramifications or enforcement capability of such a statement.

And finally, a note of caution to UAS pilots. Don't overlook or underestimate this little piece of wording right here:
§ 101.43 Endangering the safety of the National Airspace System.
No person may operate model aircraft so as to endanger the safety of the national airspace system.

The FAA is famous for "catch-all" regulations. In my opinion, you're staring at the one you will be charged with in every circumstance that the FAA wants to take an enforcement action against you and doesn't have a specific codified law for. It's the UAS equivalent of 14 CFR 91.13.

Don't think you're in the clear just because something you want to do wasn't specifically mentioned here.

Saturday, January 24, 2015

UAS Excelsior Alpha - Vectored Thrust Tricopter

I was doing some fast, straight line FPV flying with one of my quadcopters and a few things struck me about how multicopters fly in a straight (horizontal) line;

  • The more you pitch forward (to go faster) the less aerodynamic you are
  • The angle of the pitch actually serves to reduce lift, effectively fighting the motors
  • Finding the maximum forward speed is a risky, manual process.

So what if you wanted to build a multicopter optimized for forward flight?  I've seen some 250mm FPV racers that actually had the front two motors angled forward to increase the forward speed at a lower pitch angle.  I found myself asking - what if you could dynamically actuate the front motors forward instead of pitching the whole aircraft?  (Similar to the motors on an Osprey, but sans wings.)

Vectored thrust on multirotors is uncommon, but not new.  Still, this idea has a singular purpose which makes working out the details and controls a bit easier.

So, I decided to build one.  I give you Excelsior Alpha - my proof of concept Vectored Thrust Tricopter:

And here it is in flight:

I settled on a tricopter design because I liked the idea of yaw (rotation around the Z axis) control being completely independent of the individual motor speeds.  Otherwise, vectoring the front motors forward is going to have some weird roll/yaw side effects.  Tricopters don't alter the motor speeds for yaw. Instead, they vector the tail motor on the Y axis to rotate the aircraft around the Z axis.

For the thrust vectoring, I decided the simplest design would be to mount the front motors on a single shaft running along the X axis at the front, and then couple that shaft to the airframe in a way that allowed a servo to rotate it - effectively pitching the front motors fore and aft.

Here's a video of the drive actuator mechanism: (Note the frame plates have changed a bit since this was taken.)

Build One Yourself!

DISCLAIMER I:  This is a largely unproven design.  It needs some improvement. I hacked it together in a couple of weeks as a proof-of-concept.  I'm only sharing it because in spite of these facts it worked better than I expected, and I've had lots of people ask me for the build details.

DISCLAIMER II:  This is not a beginner project.  I do not recommend undertaking this if you aren't already familiar with RC TX/RX hardware, flight controllers, ESCs, and the like.   I'll list the parts, but I unfortunately I don't have time to write a walkthrough or answer questions about the basics of multirotor construction / configuration / flight / &etc.

Purchased parts: 

(Links go to items I used from, feel free to substitute / experiment!)

Main components
498x12mm Carbon Fiber Tube (drive motor arm, cut to ~290mm length)
OrangeRX R100 DSM Satellite Receiver (or use a traditional R/C receiver)
ZIPPY Compact 1800mAh 3S 25C Lipo  (3S 1300mAh - 2200mAh seem to work well.)
2 x 7x4.5 3-blade counter rotating props

Misc assembly hardware  (May be incomplete!)
M3 screws (~14mm?) & nuts
heat shrink tubing (for solder-on bullet connectors)
4" zip ties
velcro strap (hold the battery)

3D Printed Parts 

(main frame plates and various mounts)
I've uploaded all the parts to Thingiverse:

I printed them from PLA at .2mm layer height on my Printrbot Simple Metal.  (~25% infill I think)

You'll need to print:
1 x excelsior_top_plate
1 x excelsior_bottom_plate
2 x 12mm_collar (used to hold the motor arm in position)
1 x 12mm_sleeve_servo_arm 
1 x servo_arm
1 x 12mm-to-14mm-tube-adapter (to mount the Talon Tricopter Tail Mount to the 12mm tube)
4 x 12mm_tube_clip (optional - I use 3 for the ESCs and one to hold the XT60 battery clip)
[2015/05 Update:]
1 x Tricopter Yaw Mount / Plate set :

Miscellaneous Construction Notes:

I drilled a 3mm hole through the CF tubes to mount:
 - The motor mounts
 - The collars left & right of the main plate
 - The sleeve servo arm
 - The tail servo assembly & adapter

In each case I positioned the part first, then drilled the hole (in each side separately if necessary), then threaded the screw through the part and tube together.

The main motor arm is 290mm long because that was the longest length of a broken 500mm tube leftover from a crash that I happened to have on my bench.  It seems to work well, but that size is fairly arbitrary as it was determined by chaos theory, not computation.

Flight Controller Setup

[2015/05 Update:]
See post on Flight Controller software here:

Former text for posterity:


Basic setup:
  • I reflashed the FC with Cleanflight and the modified it (provide patch?) to allow me to control an additional servo on S2 using the AUX3 channel input
  • I changed the channel map put AUX3 on the elevator (pitch) stick, and pitch on the AUX3 channel.
  • I put the FC in 'ANGLE' mode at all times so it will hold the craft level when I actuate the thrust vectoring.  This allows me to adjust the pitch with the AUX3 knob (as a result of the remapping above) and control the forward/reverse vector with the elevator stick.

You could accomplish something similar without modifying the FC software by using a traditional R/C receiver and connecting "ELEV" from the RX to the vector servo instead of the FC.  Just be sure to put the FC in "Angle" mode since you won't have any pitch control unless you connect an analog AUX channel to the FC Elev input.

If you undertake this, let me know what happens and GOOD LUCK!  ;)

Sunday, January 4, 2015

Phoenix (Nebula Class) UAS - Status: LOST

Class: Nebula (F330)
Date Built: 2014.04.22
Date Lost: 2015.01.02

Today we declare Phoenix - my primary FPV quadcopter - LOST.  Its final flight was Friday, 2 Jan 2015 in the large private dirt field that I like to fly at.  I was performing some aggressive acrobatics when something on the quad failed, sending it into the infamous quadcopter death spiral.

Despite knowing where it failed and roughly where it went down - the quad was not located at the crash site.  I had a colleague join me in the search, and we gave up after an hour.  Two subsequent returns to the area and I have concluded that we can't find it because it is in fact no longer at the crash site.  My current working theory is that someone from the neighboring park saw it go down and took it in the few minutes between the crash and my going to retrieve it. :(
This was the aircraft that I learned FPV flying on. It will be missed.

Phoenix final specifications:

  • Frame: F330 Quadcopter Frame
  • Motors:  Turnigy D2822/17 1100kv 100W
  • ESCs: Turnigy Plush 10A
  • FC: MultiWii Pro (Mega2560) running MultiWii 2.3
  • RX: OrangeRX R100 DSM2
  • VTX: Boscam TS-351 200mw 5.8GHz
  • OSD:  MinimOSD running MWOSD
  • Camera:  GoPro Hero 2
  • Props:  7" x 4.5" x 3 blade orange
  • Battery:  Turnigy 3S 3000mAh 20C

Some memorable videos taken with this particular quad:

Friday, December 26, 2014

Beginner's Guide to Flying a Quadcopter

So you got a quadcopter or other multirotor aircraft recently. Welcome to the hobby! Here's some notes about getting started, learning to fly, and what to watch out for.

This is not an all-inclusive list, and I highly recommend also reading / watching some other guides. Above all else, be safe and be mindful of where you fly. Don't fly over unwitting crowds or people, over other people's property without their permission, or any place that might pose a hazard to aircraft, automobiles, or people.

I highly recommend learning to fly with an inexpensive "nano" quadcopter such as the Blade Nano QX or the Hubsan X4 (Amazon).  If your first quad is a DJI Phantom 2 or something of similar size and weight, please consider buying an inexpensive nano quad like the ones mentioned here and learning on that first. There are a few reasons for this:
  1. You will crash. Crashing a $60 quad is a lot easier to deal with than crashing a $600+ quad.
  2. Small, lightweight nano quads survive lots of crashes. 330mm, 450mm, and larger quads almost never survive a crash without some damage.
  3. Small, lightweight nano quads don't hurt when they hit people, animals, or things. Larger quads can.
  4. Small, lightweight quads require you to learn flying and orientation skills that are necessary to fly larger quads. Larger quads are more stable and have more advanced features, which can dangerously mask your lack of skill until it's too late. By learning on the smaller, more agile, less advanced quads you are actually becoming a competent enough pilot to handle the larger ones. 
Don't be the guy flying the larger ones who doesn't have the competence to handle it.
{end rant}


Always power on the quad with it sitting still and level. All quads need a few seconds sitting level to calibrate the MEMS gyro / accelerometer each time they power on. If you apply throttle and the quad tries to go off in one direction violently: Land, unplug the power, plug it back in and let it sit level for 10 seconds again.

Keep the "trim" settings on your controller centered. If the quad "drifts", it's not because your trim is wrong. That's not how quads work. There's something else going on.

Speaking of hovering: "Level" flight and "stationary" flight are not the same thing. Most quads have an auto-level mode. This does not mean they will hover in a stationary point without assistance. In fact, almost no quad will do that. (Certainly no nano quads will.) When you see a quad hovering in place and not drifting in any direction, there's a pilot who's moving the controls fairly constantly to correct for drift. That is normal. It actually takes a fair amount of practice. (When you see a quad hovering in place, do a flip, and then continuing to hover in that same place, you're looking at a pilot who's had hours of practice doing that. cough, cough.)

LiPo batteries:

Once you get a feel for how long the battery lasts, try and stop flying at about 80% drain instead of 100% (e.g. when the copter gets weak instead of when it just won't fly anymore.) This will more than double the lifetime of your batteries.

If you can, resist the temptation to immediately put the battery on the charger after you've drained it. (That also shortens the life of the battery.) Let it "rest" for a while before charging it again. 15 minutes is probably long enough for those little 1S batteries. 30-60m is more appropriate when you move up to larger quads with 3S & 4S batteries.

Yes, given the above two points you'll definitely want some more batteries.

Here's a good LiPo battery guide, if you're interested in knowing more about them.

Throttle & Orientation

The hardest skill to master when learning to fly a quadcopter is maintaining orientation. The second hardest skill is controlling throttle while you're also controlling other maneuvers. (This is why early on you always either suddenly hit the ceiling or the floor when you're surprised.)

Fly it "tail in" (tail facing towards you) for a while until you get comfortable with maintaining a stable altitude throughout. Tail in is the easiest way to fly, because you and the quad are facing the same direction. In this orientation, the controls are natural feeling. For a while, it will feel like that's the only way you can fly, and if the quad gets yawed (rotated around the Z axis) more than 50° to either side you'll quickly lose control. Patience!

Once you've mastered "tail in" flying and start to get bored with it, it's time to learn to fly at different orientations! (I don't recommend trying this before you have some experience and don't have to think about the throttle controls anymore. Stick to "tail in" flying until you're comfortable.)

Here's what worked for me when learning orientation:

Left / Right Passes:

Start with the quad in front of you and facing to your left. (Its left side is towards you.) Take off. Practice hovering. Remember that LEFT is towards you and RIGHT is away from you. Make a 180 turn by yawing to the right. Now it's facing right and the RIGHT side is towards you. Practice hovering like that. Repeat until you can make the turns and then maintain control without having to think about it so much.

Once you get that down, do the same thing but have the quad move forward before the 180° turn. Fly it by you with the LEFT side towards you, have it turn 180°, then fly it back by you with the RIGHT side towards you, turn 180°, &etc.


Once those maneuvers seem easy, add a straight out leg and straight in leg to each side so you're actually flying a large square in front of you (with the quad always flying forward.) Remember that on the "inbound" leg the quad is facing you so left and right will seem reversed. The same is true for the Left/Right passes though, so you should already start to have a feel for that.

Figure Eights

Now, try flying a figure eight in front of you. (With the quad flying forward throughout the maneuver.) If you can do it, congratulations. You have a solid handle on flying in all orientations.

Completing all of the above comfortably took me months. Feel free not to tackle any of it for a while. ;)

Outdoor flying

It's inevitable. You've been flying indoors a while, and you're tired of hitting walls and ceilings. So you think "It's nice out, let's go OUTSIDE!"  DANGER WILL ROBINSON.

These things are incredibly small, incredibly fast, and there is no documented service ceiling. They're often capable of flying higher than you can see them at!

You will lose control of the quadcopter.  How you fly and how you react when things go wrong are the difference between having to repair the quad or having to spend two hours in vein looking for it, giving up, and then sheepishly buying a new one.  I have lost three quadcopters so far.  Lost ... as in, they flew away and I never found them again.  It's easier to do than you think.  Here's some advice to try and prevent that.

  • Get low.  Don't fly above rooftops, treetops, or other nearby obstacles. (Certainly not if you haven't mastered ALL of the orientation lessons above.) A funny thing happens five feet above the immediate obstacle line: WIND. There's probably a steady breeze 20 feet up that doesn't exist at ground level. A steady breeze can carry your nano quad away faster than you can bring it back to you. The turbulence between the ground level and that steady breeze can also cause your quad to make unexpected turns, which can throw off your orientation.
  • Be willing to DROP.  At some point you will find yourself higher and/or farther away than you intended. Your instincts will be to add throttle and fly it back. BE WILLING TO ABORT and just cut throttle and let it crash. It's better to have to repair a quad than to not know where it ended up.

Flyaway Recovery

This is by far one of the hardest skills in outdoor quadcopter flying, so it's going to get the longest treatment. I don't think this applies as much to other R/C aircraft, because most R/C aircraft won't keep flying if you become disoriented to begin with. They just crash. But many quads will obediently keep themselves level and in the air even if you and the quad are on completely different pages about which way it's facing and/or moving... and this is how quads get lost.

In my (contentious) opinion you should master flyaway recovery with nano quads before you ever fly anything larger. Dropping a nano quad over the visible horizon is annoying, and possibly a slightly expensive ($100) lesson. Dropping a 4+ pound quadcopter with a 3S lipo battery over the visible horizon could cause serious injury or property damage. Better to learn the safe and cheap(er) way!

The set-up is this:

You're flying outdoors, a little higher than you're used to, maybe doing some fast maneuvers or trying something new, when suddenly you realize the quad is doing something other than you expect. It takes a few seconds to register this discord in your head and by the time you do the quad is a hard to see speck over the top of your neighboring horizon / obstacles. E.g.: It's either over and beyond a nearby treeline or rooftop. You're scared to cut throttle, because you don't actually know where it will come down. To not lose sight, you've had to add power, so it's now higher up (and further away). What do you do?!?!

This is a terrifying situation. Here's the reality:  Without experience, you are about to lose your quad and there's probably nothing you can do about it.  If it were a larger, advanced aircraft this is where many hit the "Return To Home" switch and pray. (Whether that's the Right Thing To Do™ is a subject for another day.) If it's a nano quad you really only have two options: A: Try and regain orientation at the risk of it going even further away, or B: Just give up, cut the throttle, and go searching for it.

Everyone tries option A first. Sometimes for too long. Two of my three aforementioned lost quads were this exact situation. I fought and fought to get it back and eventually watched in vein as it disappeared and was just.... gone. (The third was actually an equipment malfunction that I couldn't do anything about.)

When this happens to you (cough, cough) my one remaining piece of advice is this: DON'T TURN OFF THE TRANSMITTER. Pull the throttle to idle, run to wherever you think it may have came down. Stand still for a second, take in the surroundings, then "goose" the throttle a few times and listen. You may be able to hear it whining and trying to spin up the motors. This may be how you locate it. If not, well, how long you spend looking (and to what extent) is between you and your deity of choice. Good luck. :-P One hint, though, NANO QUADS are never as far away as they look. In fact, it's probably only half the distance away that you think it is, so start there.

Lost Orientation Recovery During a Flyaway

Let's go back to the point just before you lost it. You can see it, it's a speck on the horizon, and you don't know which way its facing.

Here's what you do:

Regardless of orientation:
  • Calm down. You're going to panic. Try not to "panic fly" though. 
  • Avoid any YAW inputs. (It will only make things worse) 
  • Avoid abrupt control inputs. You can lose control easily. 
  • Avoid full deflection of the controls. (Don't push any sticks all the way to the edge!) 
  • Turn on auto-level (if it's not on already.) 
IF you think the quad is facing TOWARD or AWAY from you:
  • Very gingerly try "LEFT ROLL" first. Try moving it left for a second or two. 
    • If it moves LEFT: Center the stick, pitch it back gingerly and hold it and just patiently wait. 
    • If it moves RIGHT: okay, it's actually facing you. pitch it forward gingerly and hold it, and just patiently wait. 
IF you think the quad is facing LEFT or RIGHT respective to you:
  • Very gingerly try to PITCH FORWARD first, for a second or two. 
    • If it moves LEFT: It's facing left. Center the stick, roll it left gingerly, hold it, and just patiently wait. 
    • If it moves RIGHT: It's facing right. Center the stick, roll it right gingerly, hold it, and just patiently wait. 
If you don't know which way it is facing (or the above maneuvers don't result it it moving left or right respective to you):

This is the most dangerous situation, because your attempt to determine orientation might actually send it out of sight. The good (?) news is, there's only a 1:4 chance that a direction you pick will be directly away from you. So ask yourself, do you feel lucky, punk?

Pick one of the above and try it. If you've already tried LEFT, then try FORWARD (or vice versa). I like to try "LEFT ROLL" first but that's just me. The main point is be deliberate and methodical in your attempts, don't just haphazardly try things. Try LEFT ROLL for a couple of seconds and if it doesn't move LEFT or RIGHT clearly, then counter with the same amount of RIGHT ROLL for just a second to freeze it and then move on to trying PITCH FORWARD instead. If you're slow and deliberate you, with practice, will be able to determine which side is facing you.

In all of the above situations:

Once you figure out which side is towards you:

  • Go ahead and bring it directly towards you by pitching / rolling it towards you. Do not attempt to "turn" or yaw it back into a more comfortable orientation. You might under/overshoot the turn and then you'll have to start all over again.
  • Be patient. You're panicked, your heart is racing, and "time dilation" is in full effect. Resist the temptation to yank the controls, and be willing to trust that the quad is coming towards you based on a small (25%?) control input even though you won't be able to tell for the first several seconds. If you direct it towards you and nothing seems to happen, then IT'S PROBABLY WORKING. Just hold it and count to five and you should suddenly see that it's getting bigger as it comes home. This is the most satisfying feeling in the world, btw.
  • Once you get it back: Land, sit down, breathe. You're more panicked than you realize. Losing control of a flying thing and then regaining it is a lot more mentally taxing than you imagine, and you probably need a minute to collect yourself. 
Read all of the above and visualize having to do it a few times, and you might just pull it off the first time it happens to you! ;)

Happy flying!