|
| 1 | +// Copyright 2024 The Autoware Contributors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#ifndef TRAFFIC_LIGHT_ARBITER__SIGNAL_MATCH_VALIDATOR_HPP_ |
| 16 | +#define TRAFFIC_LIGHT_ARBITER__SIGNAL_MATCH_VALIDATOR_HPP_ |
| 17 | + |
| 18 | +#include <lanelet2_extension/utility/query.hpp> |
| 19 | +#include <rclcpp/rclcpp.hpp> |
| 20 | + |
| 21 | +#include <autoware_perception_msgs/msg/traffic_signal_array.hpp> |
| 22 | + |
| 23 | +#include <lanelet2_core/LaneletMap.h> |
| 24 | + |
| 25 | +#include <memory> |
| 26 | +#include <optional> |
| 27 | +#include <unordered_set> |
| 28 | +#include <vector> |
| 29 | + |
| 30 | +/** |
| 31 | + * @class SignalMatchValidator |
| 32 | + * @brief Validates and compares traffic signal data from different sources. |
| 33 | + * |
| 34 | + * This class is designed to compare and validate traffic signal information |
| 35 | + * received from internal (e.g. camera perception) and external (e.g. V2I communication). |
| 36 | + * It aims to ensure that the traffic signal information from both sources is consistent. |
| 37 | + */ |
| 38 | +class SignalMatchValidator |
| 39 | +{ |
| 40 | +public: |
| 41 | + using TrafficSignalArray = autoware_perception_msgs::msg::TrafficSignalArray; |
| 42 | + using TrafficSignal = autoware_perception_msgs::msg::TrafficSignal; |
| 43 | + using TrafficSignalElement = autoware_perception_msgs::msg::TrafficSignalElement; |
| 44 | + using TrafficLightConstPtr = lanelet::TrafficLightConstPtr; |
| 45 | + |
| 46 | + /** |
| 47 | + * @brief Default constructor for SignalMatchValidator. |
| 48 | + */ |
| 49 | + SignalMatchValidator() = default; |
| 50 | + |
| 51 | + /** |
| 52 | + * @brief Validates and compares traffic signal data from perception and external sources. |
| 53 | + * |
| 54 | + * This method compares traffic signal data obtained from perception results |
| 55 | + * with data received from external source. It aims to find and return signals |
| 56 | + * that are present and consistent in both datasets. If signals are not consistent, |
| 57 | + * treat them as the unknown signal. |
| 58 | + * |
| 59 | + * @param perception_signals Traffic signal data from perception. |
| 60 | + * @param external_signals Traffic signal data from external source. |
| 61 | + * @return A validated TrafficSignalArray. |
| 62 | + */ |
| 63 | + TrafficSignalArray validateSignals( |
| 64 | + const TrafficSignalArray & perception_signals, const TrafficSignalArray & external_signals); |
| 65 | + |
| 66 | + /** |
| 67 | + * @brief Sets the pedestrian signals to be considered during validation. |
| 68 | + * |
| 69 | + * This method allows the specification of pedestrian signals, which are then |
| 70 | + * used to adjust the validation logic, acknowledging their unique characteristics |
| 71 | + * in traffic signal datasets. |
| 72 | + * |
| 73 | + * @param pedestrian_signals A vector of pedestrian signal pointers. |
| 74 | + */ |
| 75 | + void setPedestrianSignals(const std::vector<TrafficLightConstPtr> & pedestrian_signals); |
| 76 | + |
| 77 | + /** |
| 78 | + * @brief Sets the priority flag for using external signal data over perception data. |
| 79 | + * |
| 80 | + * When set to true, this flag indicates that in cases of discrepancy between |
| 81 | + * perception and external signal data, the external data should be prioritized. |
| 82 | + * |
| 83 | + * @param external_priority The priority flag for external signal data. |
| 84 | + */ |
| 85 | + void setExternalPriority(const bool external_priority); |
| 86 | + |
| 87 | +private: |
| 88 | + bool external_priority_; |
| 89 | + std::unordered_set<lanelet::Id> map_pedestrian_signal_regulatory_elements_set_; |
| 90 | + |
| 91 | + /** |
| 92 | + * @brief Checks if a given signal ID corresponds to a pedestrian signal. |
| 93 | + * |
| 94 | + * This method determines whether a signal, identified by its ID, is classified |
| 95 | + * as a pedestrian signal. |
| 96 | + * |
| 97 | + * @param signal_id The ID of the signal to check. |
| 98 | + * @return True if the signal is a pedestrian signal, false otherwise. |
| 99 | + */ |
| 100 | + bool isPedestrianSignal(const lanelet::Id & signal_id); |
| 101 | +}; |
| 102 | + |
| 103 | +#endif // TRAFFIC_LIGHT_ARBITER__SIGNAL_MATCH_VALIDATOR_HPP_ |
0 commit comments