Two Way Ranging, a straightforward principle…
Accurately measuring the distance between two transceivers (circuits doing both transmission and reception) is dead simple and can be performed in four steps:
- The first chip (the Master) starts a chronometer and sends a message to its remote party (the Slave). This is time T0.
- When the Slave receives the message, it starts its own chronometer. This is time T1.
- The Slave then processes the message and sends the answer. The Slave stops its chronometer. This is time T2.
- When the Master eventually receives the answer, it stops it own chronometer. This is time T3.
The Master can compute the time of a round trip by reading its chronometer. The equation δt=T3-T0 represents the time it took to complete the overall transaction. If you divide this total time by 2, you get δt/2, which is the time it took for a one way trip. Multiply the result by the speed of light, which is a good approximation of the speed of electromagnetic transmissions, and you end up with the distance between the Master and the Slave.
… not so simple to implement…
Of course in reality things are not exactly that simple. For example, there is a processing delay between the reception of the message on the Slave side, and the transmission of the answer. This delay should be taken into account. This is the reason why the Slave runs its own chronometer. It measures the return delay, which is D=T2-T1, and embeds D into the signal sent back to the master.
This way, the Master can remove D from its own time measurement (Δt=T3-T0–D), to get a much more realistic measurement of the actual time the signals spent traveling.
… and pretty complex timing operations.
This all sounds pretty simple, but difficulties always arise when you push the limits. In our case, measuring distance with an accuracy of a few cm requires chronometers that have nanosecond precision, that is less than a billionth of a second.
Once such a chronometer is built, working with very precise measurements raises unsuspected issues. As an example, the chronometer of the Master and the Slave both have a very high precision, but not exactly the same precision. One beats slightly faster than the other one. It is a very small difference, perhaps one tick difference every million ticks, but it is sufficient to introduce a tiny error that will be magnified and would eventually ruin our wonderful accuracy…
So we need to add mechanisms to handle unsynchronized chronometers. One possible way of doing this is to get the Slave to send two messages, each with what the slave thinks is the current time. Then the master can use those times with the delay between the messages to compare the 2 chronometers. However, there is a simpler technique. If the Slave, instead of inserting the return delay into its response message, waits again for exactly the same time and sends a second response message, then it provides the Master with an accurate measurement of the return delay, without introducing a different time scale.
Of course, this is only a quick description of what it takes to measure distances accurately, and there are plenty of other challenges…