Quadcopters have four rotors (quad=4, copter=flying thingy). Two of the rotors rotate clockwise, and the other two rotate counterclockwise (we'll need this later). The quadcopter is controlled by changing the speed of one or more of the motors.
There are four basic ways that a quadcopter can be controlled.
Throttle:
Throttle is exactly like your car's gas pedal. The more throttle, the faster all four motors will turn, and the higher the quadcopter will go. Think throttle = elevation.
Pitch:
Pitch is the rotation front to rear. If you are hovering at a specific height, and want to go forward, you pitch forward. This decreases the front motors speed and increases the rear speed. This causes a moment about the center of mass. Now, the thrust vector is not pointing straight down, bu rather at an angle. The quadcopter will move forward.
Roll:
Roll is like pitch, but in the left, right direction. Think of a plane. When a plane rolls left, the left wing drops down. The same is true of a quadcopter, but the left propeller dips.
Yaw:
Yaw is the rotation about the relative z-axis. A merry-go-round spinning is an example of yaw. With quadcopter's, the yaw comes from decreasing the spin of either the clockwise or counteclockwise propellers.
Image showing pitch, roll, and yaw. Image from Purdue.
The angle and magnitude of the thrust vector from the propellers determine the direction and how fast the quadcopter flys. Thrust is a force (kg*m/s^2). If we assume that the mass of the quadcopter does not change throughout flight, we can treat it as a constant. Therefore, the only thing that can change the attitude of the quadcopter is the acceleration vector. If you know the angle of acceleration, you know the angle of thrust. It is for this reason, I am using a three-axis acclerometer. I simply take the acceleration in the x, y, and z direction, and use trig to find the angle of acceleration. In a perfect environment (no wind and at sea level), the quadcopter will hover when the pitch and roll angle are zero, and the acceleration is equal to 9.8m/s^2.
But what about the yaw? Right now, I am using a gyroscope to determine how fast the quadcopter is rotating about the z-axis. If the yaw is zero, the quadcotper is not rotating at all. The problem with this is that you do not know the angle with respect to an origin. It is possible to use a magnometer to get your angle, however I have not done this because I do not have one at the current time.
The sensors I am using are a MPU-6050 6-axis accelerometer/gyro, a sonar for altitude, and 4 IR distance sensors.