Tuesday, February 4, 2014

A bug's eye view, brought to you by a nano quadrotor drone.

What's better than a tiny drone that buzzes like a bee through offices and hallways? How about a tiny drone shielded with a 3D-printed frame, controlled by a Raspberry Pi base station, and equipped with a miniscule video camera and transmitter?

As previously mentioned, I'm working on bringing next-generation science lessons to the classroom as part of a National Science Foundation grant called EnLiST, or Entrepreneurial Leadership in STEM Teaching and learning. Lately, this has meant working with the CrazyFlie, an open-source, 19-gram nano quadrotor drone developed by the Swedish team at Bitcraze.

Why bring tiny quadrotors into the classroom? Simply, drones fly on math, chemistry, physics, and computer science and programming. Having so many STEM (science, technology, engineering and mathematics) lessons wrapped up into a tiny package makes it super easy to cover a lot of important concepts, while holding students' attention and sparking their imaginations.

Additionally, when students design and fabricate these systems themselves with rapid prototyping equipment, they are taking on the role of engineers. And having students take on the role of engineers through project-based learning experiences is increasingly becoming a requirement for the "E" in STEM education, as prescribed in the Next Generation Science Standards.

The CrazyFlie is fairly capable out of the box, but because the drone is open-source, a whole hacker community has sprung up around enhancing this flying circuit board. This community served as the inspiration to "throw the kitchen sink" at this tiny drone, and to load it up with a wireless camera, 3D printed components, and a tiny Linux ground control station.

It's all an effort to explore the possibilities of tiny drones, and make them better positioned to serve students in the classroom.

Wire it up

NTSC camera (top), transmitter (left), and receiver (right)
If you're willing to sacrifice resolution, you can get some crazy small cameras and transmitters nowadays. The camera used for this application weighed in at only 1 gram, but only could provide NTSC resolution. That's about 0.3 megapixels. Our application at the grant didn't require a high resolution camera, so this worked just fine.

Before throwing everything on the tiny drone, it was necessary to first wire up the electronics to check for functionality and bugs. The camera, transmitter, and receiver were prototyped on breadboards. Thankfully, everything came out just fine.

In prototype form, the camera, transmitter, and receiver all were powered through a standard 5 volt RC battery elimination circuit (BEC), which took power from 7.4 volt lithium polymer batteries. This is the same equipment that powers radio receivers and servos in model RC aircraft, as well as the drones we build in the Drones for Schools initiative at EnLiST.

Although the CrazyFlie is powered by a 3.7 volt battery, it's possible to tap into the on-board regulator to power the camera and transmitter with 5 volts. But once the motors start spinning, available power to the camera components may not be so clean or reliable.

To make sure the camera and transmitter had adequate power, a Pololu 5 volt step-up voltage regulator was integrated into the system. This tiny board weighs just 0.4 grams and ensures everything remains powered, even if power were to drop to 2.5 volts.

And finally, a surface-mount, two-position switch provided a way to turn the camera and transmitter off. Recharge times were greatly improved when the transmitter and camera weren't leaching off the drone's power supply. And when transmitting video wasn't required, turning off the transmitter boosted flight time.

Frame it up

The second order of business was to make sure everything was secured on the tiny aircraft, and to protect the drone from bumps and falls. It also was important to guard the props from nicking people or objects. Weight had to be kept to a minimum, as the camera, transmitter, and voltage regulator already claimed about 3 grams of the CrazyFlie's 5 to 7 gram maximum payload.

Many frames have come out of the CrazyFlie community, but none quite fit my needs. One design came close to my specs, and I modified that design in SketchUp Pro, printed out the frame at the Champaign Urbana Community Fab Lab, and took it for a test-fly. Then I went back, made several revisions, and came up with the final product.

FPV camera mount
One of two interlocking prop guards
The prop guards attach to cylinders which snugly fit the CrazyFlie's motors
Final product printed in ABS plastic in two colors, to help indicate the forward position
The frame is not indestructible, but it doesn't have to be. It's meant to be sacrificed in the event of an accident, so as to preserve everything else. It's not a hassle to simply print another frame out of ABS plastic filament.

Code it up

The CrazyFlie can be flown from any PC with the CrazyFlie client software, using a USB radio dongle called the CrazyRadio, and a USB game controller. Xbox and PlayStation type USB controllers work best, and I personally use an inexpensive PlayStation-type controller for my work at EnLiST.

As some in the CrazyFlie community have pointed out, it's not always convenient to lug around a 5-pound laptop and assorted gear, in order to fly a 19-gram drone. The CrazyFlie was designed to be tiny, and likewise is best served by a tiny computer as a ground control station.

Enter the Raspberry Pi, a tiny Linux box that many in the Maker community are familiar with. For those who aren't familiar with the RasPi, it's an inexpensive, credit-card sized computer that's packed with ports for audio, USB, HDMI, and Ethernet.

This tiny computer can be connected to a monitor, keyboard and mouse, and treated much like any normal desktop computer loaded with the Linux operating system. Its 512MB of RAM and 700MHz ARM processor fall short of many recent smartphones in terms of power, but for many applications, you can't beat the size, performance, and efficiency for the price.

The CrazyFlie is one of those applications where the Pi fits "just right."

BitCraze has info about how to install the CrazyFlie client on a RasPi. Keep in mind that you must have your CrazyFlie turned on before you launch the client.

The RasPi CrazyFlie client works well if you always have access to a USB hub, monitor, and keyboard. But to truly make the RasPi a mobile base station, and run it without all those accessories, some extra steps are required.

Ideally, in a headless situation (sans screen and keyboard), the client will start when the CrazyRadio is plugged into the USB port. The BitCraze wiki described a process to make this possible, but for whatever reason, the method didn't work for me.

Instead, I created two udev rules. In Linux, any udev rules files in the udev directory are launched at startup and run continuously in the background.

It's possible to write a udev rule that launches a program when you plug a particular device into the USB port. In this case, I wanted the cfheadless client to launch when the CrazyRadio is plugged in.

First, I created a .rules file in the udev directory, and then opened the file in the nano editor. Logged in as the default user (pi), I created and opened this file from the command line:

sudo touch /etc/udev/rules.d/99-cfheadless.rules
sudo nano /etc/udev/rules.d/99-cfheadless.rules 
The nano editor opened the .rules file, and I coded the rules file as such:
SUBSYSTEM=="usb", ATTRS{idVendor}=="1915", ATTRS{idProduct}=="7777", MODE=="0664",
GROUP=="plugdev", RUN+="/home/pi/crazyflie-pc-client/bin/cfheadless"
This .rules file executed the cfheadless every time the USB radio was inserted into the Pi. It also had the added benefit of running the client on boot-up, meaning that no login was required.

To work correctly, the only stipulation was that the CrazyFlie had to be turned on before the RasPi. The client is up and working when the green LED on the CrazyFlie begins flashing.

Pulling out the CrazyRadio automatically kills the client, but won't safely shut down the RasPi. As you may have learned, the RasPi doesn't like to have its power pulled suddenly, as doing so can corrupt the SD card on which everything runs.

Fortunately, it's possible to write another udev rule that shuts the RasPi down safely once the radio dongle is pulled. It goes something like this:

ACTION=="remove", ENV{ID_VENDOR_ID}=="1915", ENV{ID_MODEL_ID}=="7777",
RUN+="/sbin/shutdown -h now"

With these two separate udev rules coded, the RasPi runs the cfheadless client on boot (as long as the dongle is inserted, and the CrazyFlie is live), and properly shuts down once the dongle is removed. No keyboard or monitor necessary.

It's the only proper way to travel with the CrazyFlie.

Keep it together

With the ground control station set up, everything needed to be protected and portable. A bare RasPi board might look attractive to hackers, but it's no way to travel with the tiny computer.

There was no shortage of RasPi cases on the market, and no shortage of makers who've whipped up innovative designs from a wide variety of materials. Adafruit spent a great deal of time developing their own RasPi enclosure, and to the debt of the hacker community, went open-source with the design.

As is my custom, I made a few modifications: a slot for access to the RasPi camera port, and an 8-bit style RasPi logo. Then, again with help from the C-U Community Fab Lab, cut and etched the design out of 1/8" acrylic plastic.

Clear acrylic was used for the sides and top of the case, and for dramatic effect, black opaque acrylic was used for the bottom.

In the above photo, you'll note an external RasPi camera board is attached. This is actually the official Near Infrared (NoIR) camera board, which, when paired with a blue filter, can be used to remotely sense plant health. More on that in a later post.

Another case was whipped up for the video receiver, which was simply a plastic projects box. Holes were drilled for RCA video, antenna, and power ports. The receiver module was soldered to a prototyping perfboard, and the perfboard was cut to fit the projects box. As the receiver becomes toasty warm during operation, holes were drilled in the lid for ventilation.

Fly away

The following video doesn't show the RasPi base station in action, but does document the development process of the FPV nano quadrotor. The "bug's-eye-view" provided by the drone is as unique as it is entertaining.

The future

As the EnLiST grant is working on several new proposals, I won't get into too much detail about what we hope to accomplish with this tiny, FPV-equipped drone. But I will say that because of the value of remote controlled and robotic vehicles for industry, research, and space exploration, we believe they also should be part of STEM education.

I will also note that this camera is capable of sensing light in the near infrared part of the spectrum, which as mentioned before, makes it capable of remotely sensing plant biology. Additionally, the camera is just one of many tiny sensors that could be carried by this miniature vehicle.

Outside of STEM education and scientific research, tiny drones might hold promise as a means to produce data and compelling video in confined spaces. I'll close with this video of the PD-100 by Prox Dynamics, to show the utility of advanced nano drones indoors.