What is the difference between a 3-axis gyroscope, 3-axis accelerometer and 3-axis magnetometer? How do these sensors work? Why are all 3 used in some devices like smartphones, tablets, quadcopters etc.?
They are three sensors that are useful for determining position and orientation, but they measure different things.
- A magnetometer measures magnetic fields. Because the earth has a significant magnetic field, the magnetometer can be used as a compass. As such it is useful to determine absolute orientation in the NESW plane.
- An accelerometer measures accelerations. This is useful to measure changes in velocity (directly, as the acceleration is the first time derivative of the velocity) and changes in position (by integrating the signal). They are usually used for measuring small movements. Also note that gravity acts like a continuous acceleration upward (via Einstein's equivalency principle), so a multiple-axis accelerometer can also be used as an absolute orientation sensor in the UP-DOWN plane.
- A gyroscope measures either changes in orientation (regular gyro or integrating rate gyro) or changes in rotational velocity (rate gyro).
The reason these sensors are combined is because they excel at different things. For example, for orientation, a magnetometer has poor accuracy for fast movement, but pretty much zero drift over time. An integrating scheme using gyros on the other hand reacts quickly and accurately to changes, but accumulates vast error over time. It also requires to start from a known orientation, as it only reacts to changes.
Combining the inputs to these sensors allows for quick and accurate position and orientation determination with a low amount of drift over time.
Together, these sensors are also referred to as an Inertial Measurement Unit, or IMU. You can find more information on the wikipedia page for this term. Note that the unit is not strictly speaking purely inertial when you add magnetometers, but this nomenclature is widely used.