Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(autoware_traffic_light_arbiter): add current time validation #9747

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions perception/autoware_traffic_light_arbiter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ The table below outlines how the matching process determines the output based on

### Core Parameters

| Name | Type | Default Value | Description |
| --------------------------- | ------ | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `external_time_tolerance` | double | 5.0 | The duration in seconds an external message is considered valid for merging |
| `perception_time_tolerance` | double | 1.0 | The duration in seconds a perception message is considered valid for merging |
| `external_priority` | bool | false | Whether or not externals signals take precedence over perception-based ones. If false, the merging uses confidence as a criteria |
| `enable_signal_matching` | bool | false | Decide whether to validate the match between perception signals and external signals. If set to true, verify that the colors match and only publish them if they are identical |
| Name | Type | Default Value | Description |
| --------------------------------- | ------ | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `external_current_time_tolerance` | double | 5.0 | The duration in seconds an external message is considered valid for merging in comparison with current time |
| `external_time_tolerance` | double | 5.0 | The duration in seconds an external message is considered valid for merging in comparison with a timestamp of perception message |
| `perception_time_tolerance` | double | 1.0 | The duration in seconds a perception message is considered valid for merging in comparison with a timestamp of external message |
| `external_priority` | bool | false | Whether or not externals signals take precedence over perception-based ones. If false, the merging uses confidence as a criteria |
| `enable_signal_matching` | bool | false | Decide whether to validate the match between perception signals and external signals. If set to true, verify that the colors match and only publish them if they are identical |
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**:
ros__parameters:
external_current_time_tolerance: 5.0
YoshiRi marked this conversation as resolved.
Show resolved Hide resolved
external_time_tolerance: 5.0
perception_time_tolerance: 1.0
external_priority: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class TrafficLightArbiter : public rclcpp::Node

std::unique_ptr<std::unordered_set<lanelet::Id>> map_regulatory_elements_set_;

double external_current_time_tolerance_;
double external_time_tolerance_;
double perception_time_tolerance_;
bool external_priority_;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 The Autoware Contributors

Check notice on line 1 in perception/autoware_traffic_light_arbiter/src/traffic_light_arbiter.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ No longer an issue: Code Duplication

The module no longer contains too many functions with similar structure

Check notice on line 1 in perception/autoware_traffic_light_arbiter/src/traffic_light_arbiter.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Overall Code Complexity

The mean cyclomatic complexity increases from 4.14 to 4.43, threshold = 4. This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -70,6 +70,8 @@
TrafficLightArbiter::TrafficLightArbiter(const rclcpp::NodeOptions & options)
: Node("traffic_light_arbiter", options)
{
external_current_time_tolerance_ =
this->declare_parameter<double>("external_current_time_tolerance", 5.0);
external_time_tolerance_ = this->declare_parameter<double>("external_time_tolerance", 5.0);
perception_time_tolerance_ = this->declare_parameter<double>("perception_time_tolerance", 1.0);
external_priority_ = this->declare_parameter<bool>("external_priority", false);
Expand Down Expand Up @@ -129,6 +131,12 @@

void TrafficLightArbiter::onExternalMsg(const TrafficSignalArray::ConstSharedPtr msg)
{
if ((this->now() - rclcpp::Time(msg->stamp)).seconds() > external_current_time_tolerance_) {
RCLCPP_WARN_THROTTLE(
get_logger(), *get_clock(), 5000, "Received outdated V2X traffic signal messages");
return;
}

latest_external_msg_ = *msg;

if (
Expand Down Expand Up @@ -229,6 +237,13 @@
}

pub_->publish(output_signals_msg);

const auto latest_time =
std::max(rclcpp::Time(latest_perception_msg_.stamp), rclcpp::Time(latest_external_msg_.stamp));
if (rclcpp::Time(output_signals_msg.stamp) < latest_time) {
RCLCPP_WARN_THROTTLE(
get_logger(), *get_clock(), 5000, "Published traffic signal messages are not latest");
}

Check warning on line 246 in perception/autoware_traffic_light_arbiter/src/traffic_light_arbiter.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

TrafficLightArbiter::arbitrateAndPublish increases in cyclomatic complexity from 15 to 16, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
}
} // namespace autoware

Expand Down
Loading