Skip to content

Commit cc64cfd

Browse files
eriksandgrennordicjm
authored andcommitted
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 <[email protected]>
1 parent ee53fb7 commit cc64cfd

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
@@ -281,7 +281,7 @@ static void calculate_dist_rtt(cs_de_report_t *p_report)
281281
float rtt_avg_measured_ns =
282282
(p_report->rtt_accumulated_half_ns * 0.5f) / p_report->rtt_count;
283283
float tof_ns = rtt_avg_measured_ns / 2.0f;
284-
float rtt_distance_m = tof_ns * (SPEED_OF_LIGHT_M_PER_S / 1e9f);
284+
float rtt_distance_m = fmaxf(tof_ns * (SPEED_OF_LIGHT_M_PER_S / 1e9f), 0.0f);
285285

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

0 commit comments

Comments
 (0)