From 623713b981cf5ce270eecd62b3ae7704841598ba Mon Sep 17 00:00:00 2001 From: paulbourelly999 <77466294+paulbourelly999@users.noreply.github.com> Date: Tue, 6 Feb 2024 14:20:55 -0500 Subject: [PATCH] CDAR-756: Update UDPSockets to listen at higher frequency (#579) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # PR Details ## Description When running a simulation with CARMA Streets, the position data in the SDSMs appear to lag the ground truth significantly. In the included image, the square inside the blue circle indicates the VRU’s reported position in the SDSM. The blue square is its actual position. They yellow circle shows CARMA’s reported SDSM position with the green rectangle showing its actual position. ![image](https://github.com/usdot-fhwa-OPS/V2X-Hub/assets/77466294/72627660-d8ab-4a4e-8c37-db73c3bd919c) Based on a visualization of carla-sensor-lib’s logs for the pedestrian (actor 221), it appears that the position data does get updated at some point. The image below is a timestamp vs. x position graph. After further investigation, there is a difference in time stamps between the SDSMs and external objects. ![image](https://github.com/usdot-fhwa-OPS/V2X-Hub/assets/77466294/3ddcf1ae-8429-4d3b-82c4-66f2fc646200) It was found that is was largely due to the CDASimAdapter only consuming detection data at 10 hz (wall time). When running at real-time speed, the simulation can generate detection data at significantly higher frequency. This PR updates the consuming frequency to 200 Hz. This fix should be sufficient until the number of simultaneous detection exceeds 10 objects of 100Hz frequency. Improved delay shown below: ![screenshot](https://github.com/usdot-fhwa-OPS/V2X-Hub/assets/77466294/1d03c6c0-bbf2-4318-86ad-583e2b1ae6a6) ## Related Issue ## Motivation and Context Fix detection data delay for SDSM data ## How Has This Been Tested? CDASim Deployment ## Types of changes - [x] Defect fix (non-breaking change that fixes an issue) - [ ] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that cause existing functionality to change) ## Checklist: - [ ] I have added any new packages to the sonar-scanner.properties file - [ ] My change requires a change to the documentation. - [ ] I have updated the documentation accordingly. - [x] I have read the **CONTRIBUTING** document. [V2XHUB Contributing Guide](https://github.com/usdot-fhwa-OPS/V2X-Hub/blob/develop/Contributing.md) - [ ] I have added tests to cover my changes. - [ ] All new and existing tests passed. --- .github/workflows/sonar-scanner.yml | 2 +- src/v2i-hub/CDASimAdapter/src/CDASimAdapter.cpp | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/sonar-scanner.yml b/.github/workflows/sonar-scanner.yml index af844164c..6df6b7812 100644 --- a/.github/workflows/sonar-scanner.yml +++ b/.github/workflows/sonar-scanner.yml @@ -21,7 +21,7 @@ jobs: fetch-depth: 0 submodules: recursive - name: Install sonar-scanner and build-wrapper - uses: sonarsource/sonarcloud-github-c-cpp@v1 + uses: sonarsource/sonarcloud-github-c-cpp@v2 - name: Run install_dependencies.sh script run: | scripts/install_dependencies.sh diff --git a/src/v2i-hub/CDASimAdapter/src/CDASimAdapter.cpp b/src/v2i-hub/CDASimAdapter/src/CDASimAdapter.cpp index c662e6e9c..b9665bcee 100644 --- a/src/v2i-hub/CDASimAdapter/src/CDASimAdapter.cpp +++ b/src/v2i-hub/CDASimAdapter/src/CDASimAdapter.cpp @@ -126,13 +126,13 @@ namespace CDASimAdapter{ void CDASimAdapter::start_immediate_forward_thread() { if ( !immediate_forward_timer ) { - immediate_forward_timer = std::make_unique(); + immediate_forward_timer = std::make_unique(std::chrono::milliseconds(5)); } immediate_forward_tick_id = immediate_forward_timer->AddPeriodicTick([this]() { this->attempt_message_from_v2xhub(); } // end of lambda expression - , std::chrono::milliseconds(100) ); + , std::chrono::milliseconds(5) ); immediate_forward_timer->Start(); @@ -140,13 +140,13 @@ namespace CDASimAdapter{ void CDASimAdapter::start_message_receiver_thread() { if ( !message_receiver_timer ) { - message_receiver_timer = std::make_unique(); + message_receiver_timer = std::make_unique(std::chrono::milliseconds(5)); } message_receiver_tick_id = message_receiver_timer->AddPeriodicTick([this]() { this->attempt_message_from_simulation(); } // end of lambda expression - , std::chrono::milliseconds(100) ); + , std::chrono::milliseconds(5) ); message_receiver_timer->Start(); } @@ -174,7 +174,7 @@ namespace CDASimAdapter{ { if(!external_object_detection_thread_timer) { - external_object_detection_thread_timer = std::make_unique(); + external_object_detection_thread_timer = std::make_unique(std::chrono::milliseconds(5)); } external_object_detection_thread_timer->AddPeriodicTick([this](){ PLOG(logDEBUG1) << "Listening for Sensor Detected Message from CDASim." << std::endl; @@ -187,7 +187,7 @@ namespace CDASimAdapter{ PLOG(logDEBUG1) << "CDASim connection has not yet received an simulated sensor detected message!" << std::endl; } }//End lambda - , std::chrono::milliseconds(100)); + , std::chrono::milliseconds(5)); external_object_detection_thread_timer->Start(); } catch ( const UdpServerRuntimeError &e ) @@ -216,13 +216,13 @@ namespace CDASimAdapter{ void CDASimAdapter::start_time_sync_thread_timer() { PLOG(logDEBUG) << "Creating Thread Timer for time sync" << std::endl; if ( !time_sync_timer ) { - time_sync_timer = std::make_unique(); + time_sync_timer = std::make_unique(std::chrono::milliseconds(5)); } time_sync_tick_id = time_sync_timer->AddPeriodicTick([this]() { PLOG(logDEBUG1) << "Listening for time sync messages from CDASim." << std::endl; this->attempt_time_sync(); } // end of lambda expression - , std::chrono::milliseconds(100)); + , std::chrono::milliseconds(5)); time_sync_timer->Start(); }