# Two-way ranging results don't change with distance or anything

Hi,

I tried to implement two-way ranging (for the beginning I am only using the 2-message method).
I have two DW1000 modules connected to a Raspberry Pi each which are 3 meters apart (I also tried it with 1m apart or directly next to each other), both are connected to my network and I am monitoring the console outputs via a laptop.

One Raspberry is the sender (ranging initiator), the other the receiver.
First, the initiator sends a message, stores the tx-timestamp and switches into the receiver-state.
The receiver waits until the message is received, stores the rx-timestamp, switches into sender-mode and sends a message while storing the tx-timestamp.
The receiver (formerly the initiator) now waits for this message and stores the rx timestamp while switching into the “final”-mode.
The sender (formerly the receiver) switches into the “final”-mode where it sends both, its rx- and tx-timestamp to the initiator.
The initiator decodes the two timestamps and computes “Treply” (according to the DW1000 User Manual) and “Tround” (from its own timestamps).

So basically I get “Tprop” via (Tround - Treply) * 0.5. I then multiply Tprop with the speed of light (299_792_458 m/s) to get the final result.

Unfortunately, this result is basically always something like 10^5 meters and it doesn’t even change with distance of the two DW1000 modules.

For example, for the initial receiver I get:

• RX-Timestamp = reg:15 content times 1.0 / (128.0 * 499.2 * 10e6) = 0.2273639747392703
• TX-Timestamp = reg:17 content times 1.0 / (128.0 * 499.2 * 10e6) = 0.22743633573874447

For the initial sender (the initiator) I get:

• RX-Timestamp = 0.10160775131616837
• TX-Timestamp = 0.10146660833583733
=> Tround = 0.00014114298033103545

Tprop = 6.878198085687182e-05 * 0.5 = 3.439099042843591e-05
Distance = 3.439099042843591e-05 * 299_792_458 m/s = 10310.159m

Anybody here who has an idea what I am doing wrong? I also tried to change the antenna delay (reg:18) but this literally changes nothing.

Hey Max,
did I get you correctly that the PI’s return around 1 metre every time? Even when you would put them 3m apart and then start both programs?

Kind regards
Fhilb

So you send 3 messages:
Message 1 - A to B timed
Message 2 - B to A timed
Message 3 - B to A containing timestamps from B

This gives you 4 times - TxA1, RxB1, TxB2, RxA2
T reply = (TxB2 - RxB1)
T round = (TxA1 - RxA2)

Distance = c * (Tround - Treply) / 2

One issue with this is Treply is timed on the internal clock of B while Tround is timed on the internal clock of A. These clocks will be running at very slightly different rates. Only a tiny amount but enough that the error caused by the difference in clock rates is far larger than the time taken for the signal to travel. That is why you get the same range all the time, you’re in effect measuring the clock differences not the distance. If you switched the roles of the two units you would probably get a large negative range,

Register 0x27 sub register 0x28 DRX_CAR_INT can be used to estimate this clock difference. If you read that and apply the correct scale factor (the user manual gives how to calculate this) to the Treply value you can cancel out the error and get the range.

You will still have an offset due to antenna delays but this should be a constant range error in the 50-100m region that can be calibrated out.

The alternative is to you use double sided two way ranging, you repeat the process switching the roles of the two units and take the average. That way the clock differences cancel out and you get the correct range. This is slower but very slightly more accurate (as in the range noise is a few mm less).

@AndyA Thank you for your detailed reply. I was aware of the clock error but the user manual states that this can be at most 20ppm which results in a few 10 centimeters at most.

I ran the approch of setting the transmit antenna delay on both DW1000 to 0 and then repeating the two way ranging process, adding a specific value to the antenna delay each time (like 25 or so, on BOTH devices) until the calculated distance is round about accurate (for me this means setting the antenna delay to around 32.000).

Is this approach with the antenna delay accurate? With antenna delay = 0 I had a distance of over 300 meter, with 32.000 its around 1 meter (which is accureate). I have yet to test this antenna delay while I move the receiver around and see if the distance changes.

Since the measurement system is symmetrical you with 2 devices it’s impossible to tell how much of the delay is due to each antenna. You should be able to put it all on one device or split it evenly between both and get the same results. Generally splitting it evenly seems like is the most reasonable approach.

With 3 or more devices you can start to calculate how much of the delay is due to each unit.

Also we find that when we do this calibration you can get differences of up to 10cm going from an open field to a small room. Probably in part at least due to higher background noise levels resulting in a higher detection threshold.

For accurate results over a range of distance you also need to correct for the signal strength effects, weaker signals tend to give longer ranges than stronger ones.