How a gyroscope and an accelerometer work out where your head is pointing
A camera-free head tracker can't see your head. So how does it know where you're looking? The answer lies in two small sensors that are also in your phone and your game controller: a gyroscope and an accelerometer. This post explains what these sensors measure and how software turns their readings into the direction of your head. No formulas, just the idea.
Gyroscope: how fast you're turning
A gyroscope measures rotation speed, not angle. It doesn't say "the head is 30° to the right now"; it says "the head is turning right at 50° per second". It gives this speed separately for three axes.
To find the angle, the software has to add up these speeds over time. If you turned at 50° per second for half a second, you've turned 25°. The device does this hundreds of times per second, so it doesn't miss fast movements either. The Hz value at the top of the PiHead Tracker app shows how many readings per second the device sends.
This adding up is also the gyroscope's weak spot. Even when the sensor is still, it doesn't read exactly zero; there's a very small error. During the adding up, that error builds up too and over time makes the view drift to one side. We explain this in detail in our drift post.
Accelerometer: where gravity is
As the name says, an accelerometer measures acceleration. When the device is still, the only acceleration acting on it is gravity. So while the device is still, the accelerometer shows where "down" is. When you tilt your head forward, the direction of gravity relative to the sensor changes, and the software works out from this how far your head is tilted.
The accelerometer has a weak spot too. When you turn your head quickly, it measures the acceleration of the movement itself as well as gravity, so its instant readings are noisy. And gravity doesn't show left-right rotation. When you turn your head to the right, "down" stays in the same place.
Combining the two
The strengths and weaknesses of the two sensors complement each other:
| Gyroscope | Accelerometer | |
|---|---|---|
| Fast movements | Very good | Noisy |
| Long-term accuracy | Drifts over time | Doesn't drift |
| Left-right rotation | Measures it | Can't measure it |
That's why the software uses both together. This is called sensor fusion. It takes the instant movement from the gyroscope and uses the direction of gravity from the accelerometer to slowly correct the gyroscope's accumulated error. The result is direction information that's both fast and doesn't degrade over time.
This correction works very well for looking up and down and for tilt. For left-right rotation, gravity can't help, so the software needs other methods. The main ones are re-measuring the gyroscope's error when the device is still and very slowly correcting the center while you look near it.
Why no compass
Phones also use a magnetometer, an electronic compass, for left-right rotation. In head tracking it doesn't help much, because the device sits on a headset. The magnets in the headset's speakers, the speakers on your desk and the computer case all distort the magnetic field. A compass can't give a reliable direction in that environment. That's why PiHead Tracker doesn't use a compass and balances left-right rotation in software.
What calibration does
Two steps in the app are directly related to these sensors:
- Gyro calibration: measures the gyroscope's error while the device sits still on the desk and subtracts it. It helps when drift is noticeable.
- Setup wizard: measures the direction of gravity while you look straight ahead and while you tilt forward. From this it works out which way the device is mounted on the headset. That's why you can mount the device in any direction.
The bottom line
In a camera-free head tracker, quality is decided by the software as much as by the sensors. Two devices built on the same sensor can feel very different depending on their fusion and drift correction. For a general comparison of head tracking methods, see our head tracking guide.