Skip to content

Commit 18a61da

Browse files
eriksandgrenhermabe
authored andcommitted
samples: bluetooth: Improve update frequency of distance estimates
Improves the update frequency of distance estimates in channel_sounding_ras_initiator. This is accomplished by the following changes: - Add another sem `sem_distance_estimate_updated` which is given each time the distance estimates are updated. The main thread will take `sem_distance_estimate_updated` and print the new estimate. - Use `channel_map_repetition = 1` to make the CS procedure length shorter. I believe the benefit of having multiple measurements of th same channel in each procedure is less than having a faster procedure interval. - Lower the `subevent_len` to 16000 us. This is enough to fit all the steps of the CS procedure in a single subevent. - Lower the connection interval to 20 ms (from 50). With a CS procedure interval of 5 (or 10) this effectively means that there should be a new CS procedure and thus a new distance estimate every ~100 ms (or ~200 ms). Depending on if realtime ranging data is supported or not. Signed-off-by: Erik Sandgren <[email protected]>
1 parent 14f4ea6 commit 18a61da

File tree

1 file changed

+12
-11
lines changed
  • samples/bluetooth/channel_sounding_ras_initiator/src

1 file changed

+12
-11
lines changed

samples/bluetooth/channel_sounding_ras_initiator/src/main.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static K_SEM_DEFINE(sem_mtu_exchange_done, 0, 1);
4747
static K_SEM_DEFINE(sem_security, 0, 1);
4848
static K_SEM_DEFINE(sem_ras_features, 0, 1);
4949
static K_SEM_DEFINE(sem_local_steps, 1, 1);
50+
static K_SEM_DEFINE(sem_distance_estimate_updated, 0, 1);
5051

5152
static K_MUTEX_DEFINE(distance_estimate_buffer_mutex);
5253

@@ -199,6 +200,7 @@ static void ranging_data_cb(struct bt_conn *conn, uint16_t ranging_counter, int
199200
store_distance_estimates(&cs_de_report);
200201
}
201202
}
203+
k_sem_give(&sem_distance_estimate_updated);
202204
}
203205
}
204206

@@ -500,7 +502,9 @@ static int scan_init(void)
500502
int err;
501503

502504
struct bt_scan_init_param param = {
503-
.scan_param = NULL, .conn_param = BT_LE_CONN_PARAM_DEFAULT, .connect_if_match = 1};
505+
.scan_param = NULL,
506+
.conn_param = BT_LE_CONN_PARAM(0x10, 0x10, 0, BT_GAP_MS_TO_CONN_TIMEOUT(4000)),
507+
.connect_if_match = 1};
504508

505509
bt_scan_init(&param);
506510
bt_scan_cb_register(&scan_cb);
@@ -658,7 +662,7 @@ int main(void)
658662
.role = BT_CONN_LE_CS_ROLE_INITIATOR,
659663
.rtt_type = BT_CONN_LE_CS_RTT_TYPE_AA_ONLY,
660664
.cs_sync_phy = BT_CONN_LE_CS_SYNC_1M_PHY,
661-
.channel_map_repetition = 3,
665+
.channel_map_repetition = 1,
662666
.channel_selection_type = BT_CONN_LE_CS_CHSEL_TYPE_3B,
663667
.ch3c_shape = BT_CONN_LE_CS_CH3C_SHAPE_HAT,
664668
.ch3c_jump = 2,
@@ -689,8 +693,8 @@ int main(void)
689693
.min_procedure_interval = realtime_rd ? 5 : 10,
690694
.max_procedure_interval = realtime_rd ? 5 : 10,
691695
.max_procedure_count = 0,
692-
.min_subevent_len = 60000,
693-
.max_subevent_len = 60000,
696+
.min_subevent_len = 16000,
697+
.max_subevent_len = 16000,
694698
.tone_antenna_config_selection = BT_LE_CS_TONE_ANTENNA_CONFIGURATION_A1_B1,
695699
.phy = BT_LE_CS_PROCEDURE_PHY_2M,
696700
.tx_power_delta = 0x80,
@@ -717,21 +721,18 @@ int main(void)
717721
}
718722

719723
while (true) {
720-
k_sleep(K_MSEC(5000));
721-
724+
k_sem_take(&sem_distance_estimate_updated, K_FOREVER);
722725
if (buffer_num_valid != 0) {
723726
for (uint8_t ap = 0; ap < MAX_AP; ap++) {
724727
cs_de_dist_estimates_t distance_on_ap = get_distance(ap);
725728

726-
LOG_INF("Latest distance estimates on antenna path %u: ifft: %f, "
727-
"phase_slope: %f, rtt: %f meters",
729+
LOG_INF("Latest distance estimates on antenna path %u: ifft: %.2f, "
730+
"phase_slope: %.2f, rtt: %.2f meters",
728731
ap, (double)distance_on_ap.ifft,
729732
(double)distance_on_ap.phase_slope,
730733
(double)distance_on_ap.rtt);
734+
}
731735
}
732-
}
733-
734-
LOG_INF("Sleeping for a few seconds...");
735736
}
736737

737738
return 0;

0 commit comments

Comments
 (0)