CSCI 121 Lab #21: Makerspace@W&L
Goal / Turnin
The goal of this lab is to have fun learning how to build and fly a “micro-scale” quadcopter
Unmanned Aerial Vehicle
(UAV, a.k.a. drone). Because all drones operate on the same principles, you will also understand the
technology behind one of today's fastest-growing industries. Unlike the vast majority of
people who own a quadcopter, you will build yours from components, rather than buying it
pre-assembled. So will also also get a taste of the exciting
maker movement that is reshaping the technology
and education landscape worldwide.
As with last week's lab,
you will also pick up skills and understanding that can be applied to other cutting-edge technologies,
like biomedical sensors. Like last week's lab, this one will require no turnin; instead, you will work in a team
on a single workstation with a few other students, showing me your progress at each step.
Building, configuring, and flying your first drone – even a tiny, relatively safe one like ours –
would usually involve a few weeks of work. Because we have only three hours, I have done much of the
preliminary work already: configuring the remote-control transmitters, soldering the connectors onto the
flight controller boards, and other time-consuming, potentially frustrating tasks that you can skip over
today. The goal, then, is to cram as much learning and fun into the time we have as possible. We'll
try to spend no more than half an hour on each part before moving onto the next.
Before we begin, please bear in mind: Hardware is hard! In my experience – especially with
inexpensive components like the ones we're using in this lab – you have about a
50/50 chance of stuff working the first time you try it. If it doesn't work, you gently unplug and
replug the device, and it'll often work the second time around. Sometimes the equipment is genuinely broken,
which means you're out of luck until you re-order the part you need. But, more often, a little patience and
persistence is all it takes.
Part 1: 3D Printing Tutorial
The first half hour or so of lab will take place in the IQ Center on the second floor of the Science building.
IQ Center Director David Pfaff will guide you through the process of 3D printing a design like the
3DFly quadcopter frame we will use in the lab. Dave and I have
already printed out several of these frames beforehand, for you to use when you're ready to assemble
Part 2: Flying a simulator
Flying a drone for the first time can be intimidating. Unlike piloting
a real airplane, you are not onboard the UAV to get a first-person sense of what it is doing.
(The first time I flew one, much larger than the
ones we're building today, I flipped it mid-air and nearly destroyed an expensive video camera –
not to mention endangering myself and the professional pilot who was teaching me!)
To make learning easier, we will use a realistic but inexpensive flight simulator,
which works with the actual remote-control transmitters we will use the fly our 'copters.
You don't need administrator privileges to set up FPV Freerider, but the author charges a very reasonable $5 fee
for downloading it. So, once your team is assembled and ready, let me know, and I will pay the
fee and download this app onto your computer.
Once I've set up FPV Freerider, you can plug your transmitter into the USB port on the side of the monitor.
Your team number is on a little sticker at the top or front of the transmitter.
If you are in Team 1, 2, 3, or 4, your transmitter will work with both the simulator and the radio
receiver onboard the UAV you will build.
Team 5 has two transmitters: a Taranis transmitter configured to work with the simulator, and a Spektrum
DX8 transmitter configured to work with the receiver.
Before flying FPV Freerider, you'll need to calibrate the program to work with your transmitter. Click on the
button labeled Calibrate Controller and follow the directions there. Then pick a scene and start
flying! Within each scene you can use the Camera button to switch views (first-person or third-person)
and Acro vs. Self-Leveling mode. First-person acro is probably the most fun, but to train for our
UAVs today, you'll want to fly in third-person, self-leveling mode.
Give each team member a chance to fly the simulator. Then let me know when you're done so you can move on
to the next part.
Part 3: Reading raw values from the IMU
Like the Arduino microcontroller we used last week, our little flight-control boards can be flashed with
different kinds of firmware. Most people buy their flight boards pre-flashed with firmware that performs
all the necessary tasks to fly a UAV (reading from the sensors and radio receiver, sending commands to the
motors). So we can get a better understanding of how these devices work, I have instead flashed a much
simpler firmware program onto our boards to start: this program will read the accelerometer and gyrometer
values from the inertial measurement unit (IMU) on the board and send them as text messages over a serial
To get started on this part, take the flight board and little red FTDI adapter
I've provided, and connect the adapter to the board as shown here. Then unplug your transmitter from the USB cable
and plug the mini-end of the cable into the FTDI adapter. (Team 5 will have a green adapter that uses
a full-size male USB connector, so I will provide that team with a USB
extension cable.) One of the little LEDs on the board should light up steadily,
indicating that the board is powered.
In a terminal window on your computer, type the following:
miniterm.py /dev/ttyUSB0 115200
You should then see a stream of six values: the X, Y, and Z values of the accelerometer and gyrometer.
These are “raw” integer values read from the Analog-to-Digital Converter (ADC) on the
IMU. By slowly manipulating the board (pitching it forward and back, rolling it left and right, yawing
it clockwise and counter-clockwise), you should get a sense of the difference between the accelerometer
and gyrometer. Once your team is ready, let me know, so you can show me the output and explain the
Part 4: Flashing and testing the flight-control firmware
Now it's time to put flash the actual flight firmware onto the board.
is the most popular firmware for boards like ours, and often comes pre-installed on the board.
Instead, though, we will use the
Hackflight firmware developed by
me and me research students over the past year, which is a much-simplified version of Cleanflight that
is easier to understand and debug. (I also have firmware pre-configured for our board and vehicle,
so we don't have to use a separate
configurator program to set parameters.)
Unfortunately, the Arduino IDE does not work with flight-control boards like the one's were using today.
Instead, I will need to flash the Hackflight firmware onto your board, using the computer in my
office. So, once your team is ready for this stage, we'll walk over to my office, and I'll show
you how I flash the Hackflight firmware onto your board.
Once I've flashed the Hackflight firmware onto your board, it's time to do our first pre-flight check.
With one of your teammates holding the flight board flat on the table, plug
the FTDI adapter back into the board and the USB cable. The LEDs should blink rapidly, indicating the
the board is booting up. Then the green LED should stay solid for a few seconds, meaning that the
firmware is going through an auto-calibration sequence (reading the accelerometer and gyrometer values
from the IMU to determine what they should be when the board is lying flat and motionless). Once the
green LED shuts off, you can let go of the board. If it pitches or rolls more than 25 degrees in either
direction, the green LED will blink, as a warning that the vehicle is not ready to fly.
and unzip this zipfile, and you'll get a folder that
contains a Python program to help you visualize the orientation of the vehicle
and input from the transmitter. As with your previous labs, open a terminal
window in this folder. Then type:
The Hackflight app should pop up, showing that you have a serial connection to the board via /dev/ttyUSB0.
Click the Connect button, and in a few seconds you should see an image of a little quadcopter, with
an arrow on the top for orientation, corresponding to the tiny arrow on the board. As you gently roll
the board left and right, pitch it forward and back, and yaw it clockwise and counter-clockwise, the
image in the display should reflect these motions. As I mentioned in class, the firmware is using a
sensor fusion algorithm to “fuse” (combine) the six values from the IMU into three axes
(pitch, roll yaw). If we had flight board with a magnetometer (compass), there would be three additional
sensor values that could be fused with the IMU values, to get a better estimation of the vehicle's
heading (yaw). (When you see the term DOF, or Degrees Of Freedom used to describe an
IMU or other sensor, it refers to the total number of such values that can be fused. Hence we have a 6 DOF
Part 5: Set up your transmitter and receiver
To fly the vehicle from our transmitter, we will need a radio receiver onboard, to which we will send commands from
our transmitter. Each team will get one such receiver, numbered the same as the transmitter, which you can
plug into the little white three-wire connector that sticks up from the board. Team 5 will use Spektrum DX8
transmitter, but the other teams will need to change the setup on their Devo 7R transmitter to work with the receiver
instead of the simulator:
Once your receiver is plugged into the board and your transmitter is showing the Vehicle model, you should
see a solid red LED on the receiver, indicating a connection between it and the transmitter. Turning the
transmitter off and back on may be necessary. Re-connect the FTDI cable to the board, re-launch the Python
Hackflight program from a terminal window, and turn the board a little to make sure it's talking to the program
(onscreen vehicle should move appropriately). Then click the Receiver button in the Hackflight program.
Now, manipulating the transmitter sticks should result in a changing display of signal values in the program.
Make sure to show me what you've got before moving on to the next step!
- Power up the transmitter.
- Hit the plastic ENT button at upper-right to enter the Main menu.
- Hit the ENT button again to enter the Model menu.
- Hit the ENT button again to enter the Model setup.
The Load item will be highlighted. If it's not, use the UP+ and DOWN-
buttons at left to highlight the Load item.
- Hit the ENT button again, and you'll see that the Simulator model is current. Use the
Up+ button at left to choose the vehicle model corresponding to your team number (Team 2 will
see Vehicle2, etc.), then ENT again to select this model.
- Repeatedly hit the EXT button at upper-let to exit out of these setup levels, until you see the
name of your vehicle and the little hexacopter icon, as when you started.
Part 6: Assemble your vehicle and test the motors, without propellers
Finally, we've reached the actual “maker” part! After detaching the board from the FTDI adapter,
follow these steps below for the assembly of your vehicle with the battery, frame, motors, tape, and heat-shrink
tubing I will give you:
- Using your battery as a guide, snip off a length of Velcro hook (rigid plastic) tape,
and an approximately equal length of loop (soft-n-fuzzy, which may already be on the battery.)
Peel off the backing, and center
the hook tape on the bottom of the frame, and the loop tape on the battery. (It'll work the other way,
too, but this is how I do it.) Put the battery aside for later.
- Using the gray 3M VHB double-side foam tape, snip off two lengths of tape adequate for making
a little two-layer sandwich that will cover the middle (X) section of the top side of the vehicle.
(We use two layers to allow access to the exposed two-pin header on the board, which can be
useful for re-flashing the firmware if it has a bug.)
Then, orienting the flight board's arrow along the forward/backward axis of the vehicle, gently press the
board into the tape for a snug fit. Your vehicle now has a front and back. Even if you can't see the
tiny arrow on the board, remember that the big red/black battery cable hangs off the back. The VHB
tape is really strong, so if you're unsure about the orientation, check with me before you
complete this step.
- Warning, this step requires a delicate touch: Using this photo
of a fully-assembled vehicle as a guide, insert two clockwise motors (red and blue wires) and
two counter-clockwise motors (black and white wires) into the corresponding slotted circular holders in
the frame, being careful to slide the wires down through the slot so as not to snap or tangle them.
Then, carefully connect the motors to the the board. (Like a traditional USB cable, the motor
connectors have an orientation, so you may need to rotate the connector from the motor to make it
fit into the connector on the board.)
Part 7: Test the motors without propellers, and secure them to the frame
Now we need to test each motor to make sure it's connected and spinning in the right direction. Affix the
battery to the bottom of the frame, pressing gently to make sure the Velcro is working. Then connect the battery
to the battery cable. The board should go through its startup/calibration phase again. Re-attach the
FTDI adapter to the board using the jumpers, re-launch the Hackflight program from a terminal window, and
connect to the board. As before, gently wield the vehicle to make sure that the IMU is working as expected.
Then set the vehicle down and click the Motors button in the program.
You should see a little image of a quadcopter, along with a checkbox to verify
that you've removed the propellers and are ready to spin-test the motors. Once
clicked in the checkbox, you should see motor #1 (lower-right) highlighted, as well as a slider allowing you
to power up the motor. Gently power the motor up using the slider. Once it's spinning, you can test that
its direction is correct by licking one of your fingers (if you have dry skin like mine) and placing it along the
motor shaft. You can click directly on each of the other four motors to repeat the test for them. When you're
done, disconnect the battery.
Once you've tested all four motors, let me know, and we'll use our heat gun and some clear heat-shrink tubing
to affix the motors firmly to the frame.
Part 8: Secure the wires and receiver, and attach the propellers
As shown in the photo of the completed vehicle, you'll need to secure the battery
and motor cables with zip-ties, to keep them from snagging the propellers during flight. The danger here
is accidentally cutting the wires after you've snipped off the excess zip tie. If you're concerned about
doing it right, I'll be happy to do this for you. You should also secure the receiver to the flight board, using another piece of the gray VHB tape. To avoid damaging the board, use gentle pressure to ensure that the receiver is securely attached.
Once the wires and receiver are secured, you can attach the propellers. As with the Velcro for the battery, I've adopted
an arbitrary convention that helps me avoid mistakes: I put the bright-colored (orange or red) props
on the back of the vehicle, and the black ones on the front. The other thing you need to attend to is the
directionality of the prop: the clockwise props go with the clockwise motors (back right, front left), and
the counter-clockwise props with the counter-clockwise motors (back left, right front).
The way you can tell which prop is which is by
looking at the leading edge (elevated part of the blade): the leading edge should face the same way
as the direction of motion, to create the airfoil that provides lift for the vehicle. (Again, if you're
unsure, check with me.) Once you've got the four props ready for their motors, gently press each prop onto its
Part 9: Final pre-flight check
This is a step that is relatively easy and safe to do, as compared to the risk entailed with larger vehicles.
For maximum safety, though, please let me help you with it the first time through.
Keeping the fully-assembled vehicle flat on the table, re-connect the battery. Let the board go through
its startup/calibration sequence. Making sure the transmitter is on, arm the vehicle by moving the
collective (left-hand) stick to its full lower-right position. The red
LED should light up, indicating that the vehicle is armed and ready to fly.
Disarm the vehicle by moving the stick firmly to the lower-left.
Now I will pick up the vehicle and hold it firmly After getting the okay from me, arm the vehicle again.
Then slowly raise the throttle to engage the motors. Once the motors are spinning, gently pitch the vehicle
left or right using the cyclic (right-hand) stick. You should observe and hear the motors on each
side doing the appropriate thing (roll left = increase right-side motors, pitch forward = increase rear
motors, etc.). Manually pitching and rolling the vehicle directly should also result in compensatory behavior
by the motors (the job of the IMU).
Part 10: Fly it!
Okay, enough warm-up. Once each of your teammates has had a chance to go through the final pre-flight
exercise, one of you will have to be brave enough to actually fly the vehicle. As with your first few times
drive a car, it'll be a balancing act between moving the controls too much or too little. Again, I recommend letting
me try it first, to get a sense of whether it's flying smoothly. I can also help you trim out the
vehicle, by adjusting the little tabs below and to the side of the sticks.