From c0b9ecdc823a8ed8e0a1b77cc25bcfe06af50c7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Thu, 7 Sep 2023 13:41:04 +0200 Subject: [PATCH] uxrce_dds_client: run session until we do not get data anymore Otherwise there can be significant delay for received data --- src/modules/uxrce_dds_client/uxrce_dds_client.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/modules/uxrce_dds_client/uxrce_dds_client.cpp b/src/modules/uxrce_dds_client/uxrce_dds_client.cpp index bf24fc97db..f53e8c42b9 100644 --- a/src/modules/uxrce_dds_client/uxrce_dds_client.cpp +++ b/src/modules/uxrce_dds_client/uxrce_dds_client.cpp @@ -420,7 +420,17 @@ void UxrceddsClient::run() _subs->update(&session, reliable_out, best_effort_out, participant_id, _client_namespace); - uxr_run_session_timeout(&session, 0); + // Run the session until we receive no more data or up to a maximum number of iterations. + // The maximum observed number of iterations was 6 (SITL). If we were to run only once, data starts to get + // delayed, causing registered flight modes to time out. + for (int i = 0; i < 10; ++i) { + const uint32_t prev_num_payload_received = _pubs->num_payload_received; + uxr_run_session_timeout(&session, 0); + + if (_pubs->num_payload_received == prev_num_payload_received) { + break; + } + } // time sync session if (_synchronize_timestamps && hrt_elapsed_time(&last_sync_session) > 1_s) {