@@ -21,21 +21,21 @@ using TrafficSignal = autoware_perception_msgs::msg::TrafficSignal;
21
21
using Element = autoware_perception_msgs::msg::TrafficSignalElement;
22
22
using Time = builtin_interfaces::msg::Time;
23
23
24
- // Finds a signal by its ID within a TrafficSignalArray.
24
+ // Finds a signal by its ID within a TrafficSignalArray
25
25
std::optional<TrafficSignal> find_signal_by_id (
26
26
const TrafficSignalArray & signals, int64_t signal_id)
27
27
{
28
28
auto it = std::find_if (
29
29
signals.signals .begin (), signals.signals .end (),
30
30
[signal_id](const TrafficSignal & signal ) { return signal .traffic_signal_id == signal_id; });
31
31
if (it != signals.signals .end ()) {
32
- return *it; // Return the found signal.
32
+ return *it; // Return the found signal
33
33
} else {
34
- return std::nullopt; // Return an empty optional if not found.
34
+ return std::nullopt; // Return an empty optional if not found
35
35
}
36
36
}
37
37
38
- // Creates a TrafficSignalElement with specified attributes.
38
+ // Creates a TrafficSignalElement with specified attributes
39
39
Element create_element (
40
40
const Element::_color_type & color, const Element::_shape_type & shape,
41
41
const Element::_status_type & status, const Element::_confidence_type & confidence)
@@ -49,7 +49,7 @@ Element create_element(
49
49
return signal_element;
50
50
}
51
51
52
- // Creates unknown elements for each unique shape from two element vectors.
52
+ // Creates unknown elements for each unique shape from two element vectors
53
53
std::vector<Element> create_unknown_elements (
54
54
const std::vector<Element> & elements1, const std::vector<Element> & elements2)
55
55
{
@@ -63,21 +63,21 @@ std::vector<Element> create_unknown_elements(
63
63
64
64
std::vector<Element> unknown_elements;
65
65
for (const auto & shape : shape_set) {
66
- // Confidence is set to a default value as it is not relevant for unknown signals.
66
+ // Confidence is set to a default value as it is not relevant for unknown signals
67
67
unknown_elements.emplace_back (
68
68
create_element (Element::UNKNOWN, shape, Element::UNKNOWN, /* confidence */ 1.0 ));
69
69
}
70
70
71
71
return unknown_elements;
72
72
}
73
73
74
- // Creates a 'unknown' signal with elements matching the shapes of a given signal's elements.
74
+ // Creates a 'unknown' signal with elements matching the shapes of a given signal's elements
75
75
TrafficSignal create_unknown_signal (const TrafficSignal & signal)
76
76
{
77
77
TrafficSignal unknown_signal;
78
78
unknown_signal.traffic_signal_id = signal .traffic_signal_id ;
79
79
for (const auto & element : signal .elements ) {
80
- // Confidence is set to a default value as it is not relevant for unknown signals.
80
+ // Confidence is set to a default value as it is not relevant for unknown signals
81
81
const auto unknown_element =
82
82
create_element (Element::UNKNOWN, element.shape , Element::UNKNOWN, /* confidence */ 1.0 );
83
83
unknown_signal.elements .emplace_back (unknown_element);
@@ -86,12 +86,12 @@ TrafficSignal create_unknown_signal(const TrafficSignal & signal)
86
86
return unknown_signal;
87
87
}
88
88
89
- // Creates an 'unknown' signal by combining unique shapes from two signals' elements.
89
+ // Creates an 'unknown' signal by combining unique shapes from two signals' elements
90
90
TrafficSignal create_unknown_signal (const TrafficSignal & signal1, const TrafficSignal & signal2)
91
91
{
92
92
TrafficSignal unknown_signal;
93
93
94
- // Assumes that both signals have the same traffic_signal_id.
94
+ // Assumes that both signals have the same traffic_signal_id
95
95
unknown_signal.traffic_signal_id = signal1.traffic_signal_id ;
96
96
97
97
const auto unknown_elements = create_unknown_elements (signal1.elements , signal2.elements );
@@ -106,25 +106,25 @@ TrafficSignal create_unknown_signal(const TrafficSignal & signal1, const Traffic
106
106
bool are_all_elements_equivalent (
107
107
const std::vector<Element> & signal1, const std::vector<Element> & signal2)
108
108
{
109
- // Returns false if vectors have different sizes.
109
+ // Returns false if vectors have different sizes
110
110
if (signal1.size () != signal2.size ()) {
111
111
return false ;
112
112
}
113
113
114
- // Sorts copies of the vectors by shape for comparison.
114
+ // Sorts copies of the vectors by shape for comparison
115
115
std::vector<Element> sorted_signal1 = signal1;
116
116
std::vector<Element> sorted_signal2 = signal2;
117
117
auto compare_by_shape = [](const Element & a, const Element & b) { return a.shape < b.shape ; };
118
118
std::sort (sorted_signal1.begin (), sorted_signal1.end (), compare_by_shape);
119
119
std::sort (sorted_signal2.begin (), sorted_signal2.end (), compare_by_shape);
120
120
121
- // Returns true if sorted vectors are equal.
121
+ // Returns true if sorted vectors are equal
122
122
return std::equal (
123
123
sorted_signal1.begin (), sorted_signal1.end (), sorted_signal2.begin (), sorted_signal2.end (),
124
124
[](const Element & a, const Element & b) { return a.color == b.color && a.shape == b.shape ; });
125
125
}
126
126
127
- // Creates a set of unique signal IDs from two vectors of TrafficSignals.
127
+ // Creates a set of unique signal IDs from two vectors of TrafficSignals
128
128
std::unordered_set<lanelet::Id> create_signal_id_set (
129
129
const std::vector<TrafficSignal> & signals1, const std::vector<TrafficSignal> & signals2)
130
130
{
@@ -139,25 +139,25 @@ std::unordered_set<lanelet::Id> create_signal_id_set(
139
139
return signal_id_set;
140
140
}
141
141
142
- // Returns the signal with the highest confidence elements, considering a external priority.
142
+ // Returns the signal with the highest confidence elements, considering a external priority
143
143
TrafficSignal get_highest_confidence_signal (
144
144
const std::optional<TrafficSignal> & perception_signal,
145
145
const std::optional<TrafficSignal> & external_signal, const bool external_priority)
146
146
{
147
- // Returns the existing signal if only one of them exists.
147
+ // Returns the existing signal if only one of them exists
148
148
if (!perception_signal) {
149
149
return *external_signal;
150
150
}
151
151
if (!external_signal) {
152
152
return *perception_signal;
153
153
}
154
154
155
- // Gives priority to the external signal if external_priority is true.
155
+ // Gives priority to the external signal if external_priority is true
156
156
if (external_priority) {
157
157
return *external_signal;
158
158
}
159
159
160
- // Compiles elements into a map by shape, to compare their confidences.
160
+ // Compiles elements into a map by shape, to compare their confidences
161
161
using Key = Element::_shape_type;
162
162
std::map<Key, std::vector<Element>> shape_element_map;
163
163
for (const auto & element : perception_signal->elements ) {
@@ -169,10 +169,10 @@ TrafficSignal get_highest_confidence_signal(
169
169
170
170
TrafficSignal highest_confidence_signal;
171
171
172
- // Assumes that both signals have the same traffic_signal_id.
172
+ // Assumes that both signals have the same traffic_signal_id
173
173
highest_confidence_signal.traffic_signal_id = perception_signal->traffic_signal_id ;
174
174
175
- // For each shape, finds the element with the highest confidence and adds it to the signal.
175
+ // For each shape, finds the element with the highest confidence and adds it to the signal
176
176
for (const auto & [shape, elements] : shape_element_map) {
177
177
const auto highest_confidence_element = std::max_element (
178
178
elements.begin (), elements.end (),
@@ -183,10 +183,10 @@ TrafficSignal get_highest_confidence_signal(
183
183
return highest_confidence_signal;
184
184
}
185
185
186
- // Determines the newer of two Time stamps.
186
+ // Determines the newer of two Time stamps
187
187
Time get_newer_stamp (const Time & stamp1, const Time & stamp2)
188
188
{
189
- // Returns stamp1 if it is newer than stamp2, otherwise returns stamp2.
189
+ // Returns stamp1 if it is newer than stamp2, otherwise returns stamp2
190
190
if (stamp1.sec > stamp2.sec || (stamp1.sec == stamp2.sec && stamp1.nanosec > stamp2.nanosec )) {
191
191
return stamp1;
192
192
} else {
@@ -242,15 +242,12 @@ autoware_perception_msgs::msg::TrafficSignalArray SignalMatchValidator::validate
242
242
// Check if they have the same elements
243
243
if (!util::are_all_elements_equivalent (
244
244
perception_result->elements , external_result->elements )) {
245
- // RCLCPP_WARN_STREAM(rclcpp::get_logger("debug"), "Not the same signal");
246
-
247
245
const auto unknown_signal = util::create_unknown_signal (*perception_result, *external_result);
248
246
validated_signals.signals .emplace_back (unknown_signal);
249
247
continue ;
250
248
}
251
249
252
250
// Both results are same, then insert the received color
253
- // RCLCPP_WARN_STREAM(rclcpp::get_logger("debug"), "Both results are same");
254
251
validated_signals.signals .emplace_back (*perception_result);
255
252
}
256
253
0 commit comments