Skip to content

Commit 9df0709

Browse files
committed
bluetooth: cs_de: Set RTT estimate to 0.0 if ToF is negative
It might happen that the ToF is negative because the RTT measurements are in CS are not perfectly accurate and may have a statisical distribution around its true value. It might also happen that the ToF is negative because the devices involved in the CS RTT measurements are not perfectly calibrated for internal delays. In these cases it makes more sense to just set the estimated distance to 0.0f, since it is the best estimate we can make, given that we do not want to use negative distances. Signed-off-by: Erik Sandgren <erik.sandgren@nordicsemi.no>
1 parent f6121cc commit 9df0709

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

subsys/bluetooth/cs_de/cs_de.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ static void calculate_dist_rtt(cs_de_report_t *p_report)
269269
float rtt_avg_measured_ns =
270270
(p_report->rtt_accumulated_half_ns * 0.5f) / p_report->rtt_count;
271271
float tof_ns = rtt_avg_measured_ns / 2.0f;
272-
float rtt_distance_m = tof_ns * (SPEED_OF_LIGHT_M_PER_S / 1e9f);
272+
float rtt_distance_m = fmaxf(tof_ns * (SPEED_OF_LIGHT_M_PER_S / 1e9f), 0.0f);
273273

274274
for (uint8_t ap = 0; ap < p_report->n_ap; ap++) {
275275
if (rtt_distance_m >= 0.0f) {

0 commit comments

Comments
 (0)