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

fix(crosswalk_traffic_light_estimator): add operation to remove traffic signals with duplicated ids #5653

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class CrosswalkTrafficLightEstimatorNode : public rclcpp::Node
boost::optional<uint8_t> getHighestConfidenceTrafficSignal(
const lanelet::Id & id, const TrafficLightIdMap & traffic_light_id_map) const;

void removeDuplicateIds(TrafficSignalArray & signal_array) const;

// Node param
bool use_last_detect_color_;
double last_detect_color_hold_time_;
Expand Down
17 changes: 17 additions & 0 deletions perception/crosswalk_traffic_light_estimator/src/node.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022-2023 UCI SORA Lab, TIER IV, Inc.

Check notice on line 1 in perception/crosswalk_traffic_light_estimator/src/node.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ Getting better: Overall Code Complexity

The mean cyclomatic complexity decreases from 6.83 to 6.38, 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 @@ -174,6 +174,8 @@
setCrosswalkTrafficSignal(crosswalk, crosswalk_tl_color, output);
}

removeDuplicateIds(output);

Check warning on line 177 in perception/crosswalk_traffic_light_estimator/src/node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/crosswalk_traffic_light_estimator/src/node.cpp#L177

Added line #L177 was not covered by tests

updateLastDetectedSignal(traffic_light_id_map);

pub_traffic_light_array_->publish(output);
Expand Down Expand Up @@ -383,6 +385,21 @@

return ret;
}

void CrosswalkTrafficLightEstimatorNode::removeDuplicateIds(TrafficSignalArray & signal_array) const

Check warning on line 389 in perception/crosswalk_traffic_light_estimator/src/node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/crosswalk_traffic_light_estimator/src/node.cpp#L389

Added line #L389 was not covered by tests
{
auto & signals = signal_array.signals;
std::sort(signals.begin(), signals.end(), [](const auto & s1, const auto & s2) {
return s1.traffic_signal_id < s2.traffic_signal_id;

Check warning on line 393 in perception/crosswalk_traffic_light_estimator/src/node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/crosswalk_traffic_light_estimator/src/node.cpp#L391-L393

Added lines #L391 - L393 were not covered by tests
});

signals.erase(
std::unique(

Check warning on line 397 in perception/crosswalk_traffic_light_estimator/src/node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/crosswalk_traffic_light_estimator/src/node.cpp#L397

Added line #L397 was not covered by tests
signals.begin(), signals.end(),
[](const auto & s1, const auto s2) { return s1.traffic_signal_id == s2.traffic_signal_id; }),

Check warning on line 399 in perception/crosswalk_traffic_light_estimator/src/node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/crosswalk_traffic_light_estimator/src/node.cpp#L399

Added line #L399 was not covered by tests
signals.end());
}

Check warning on line 401 in perception/crosswalk_traffic_light_estimator/src/node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/crosswalk_traffic_light_estimator/src/node.cpp#L401

Added line #L401 was not covered by tests

} // namespace traffic_light

#include <rclcpp_components/register_node_macro.hpp>
Expand Down
Loading