Skip to content

Commit

Permalink
CDAR-756: Update UDPSockets to listen at higher frequency (#579)
Browse files Browse the repository at this point in the history
<!-- Thanks for the contribution, this is awesome. -->

# 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)

<!--- Describe your changes in detail -->

## Related Issue

<!--- This project only accepts pull requests related to open issues -->
<!--- If suggesting a new feature or change, please discuss it in an
issue first -->
<!--- If fixing a bug, there should be an issue describing it with steps
to reproduce -->
<!--- Please link to the issue here: -->

## Motivation and Context
Fix detection data delay for SDSM data
<!--- Why is this change required? What problem does it solve? -->

## How Has This Been Tested?
CDASim Deployment
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->

## Types of changes

<!--- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [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:

<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->

- [ ] 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.
  • Loading branch information
paulbourelly999 authored Feb 6, 2024
1 parent 136439a commit 623713b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/sonar-scanner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions src/v2i-hub/CDASimAdapter/src/CDASimAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,27 +126,27 @@ namespace CDASimAdapter{

void CDASimAdapter::start_immediate_forward_thread() {
if ( !immediate_forward_timer ) {
immediate_forward_timer = std::make_unique<tmx::utils::ThreadTimer>();
immediate_forward_timer = std::make_unique<tmx::utils::ThreadTimer>(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();

}

void CDASimAdapter::start_message_receiver_thread() {
if ( !message_receiver_timer ) {
message_receiver_timer = std::make_unique<tmx::utils::ThreadTimer>();
message_receiver_timer = std::make_unique<tmx::utils::ThreadTimer>(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();

}
Expand Down Expand Up @@ -174,7 +174,7 @@ namespace CDASimAdapter{
{
if(!external_object_detection_thread_timer)
{
external_object_detection_thread_timer = std::make_unique<tmx::utils::ThreadTimer>();
external_object_detection_thread_timer = std::make_unique<tmx::utils::ThreadTimer>(std::chrono::milliseconds(5));
}
external_object_detection_thread_timer->AddPeriodicTick([this](){
PLOG(logDEBUG1) << "Listening for Sensor Detected Message from CDASim." << std::endl;
Expand All @@ -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 )
Expand Down Expand Up @@ -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<tmx::utils::ThreadTimer>();
time_sync_timer = std::make_unique<tmx::utils::ThreadTimer>(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();
}

Expand Down

0 comments on commit 623713b

Please sign in to comment.