diff --git a/src/modules/uxrce_dds_client/uxrce_dds_client.cpp b/src/modules/uxrce_dds_client/uxrce_dds_client.cpp index f76c15011b..9f25d439eb 100644 --- a/src/modules/uxrce_dds_client/uxrce_dds_client.cpp +++ b/src/modules/uxrce_dds_client/uxrce_dds_client.cpp @@ -456,7 +456,17 @@ void UxrceddsClient::run() // check if there are available replies process_replies(); - 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) {