Carma-platform v4.2.0
CARMA Platform is built on robot operating system (ROS) and utilizes open source software (OSS) that enables Cooperative Driving Automation (CDA) features to allow Automated Driving Systems to interact and cooperate with infrastructure and other vehicles through communication.
SignalizedIntersectionManager.hpp
Go to the documentation of this file.
1#pragma once
2
3/*
4 * Copyright (C) 2022 LEIDOS.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
7 * use this file except in compliance with the License. You may obtain a copy of
8 * the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 * License for the specific language governing permissions and limitations under
16 * the License.
17 */
18
19#include <rclcpp/rclcpp.hpp>
20#include <boost/uuid/uuid.hpp>
21#include <boost/uuid/uuid_io.hpp>
22#include <boost/uuid/uuid_generators.hpp>
23#include <lanelet2_core/LaneletMap.h>
24#include <lanelet2_core/primitives/Point.h>
25#include <lanelet2_extension/regulatory_elements/StopRule.h>
26#include <lanelet2_extension/regulatory_elements/CarmaTrafficSignal.h>
27#include <lanelet2_core/primitives/LaneletOrArea.h>
28#include <lanelet2_extension/projection/local_frame_projector.h>
30#include <carma_v2x_msgs/msg/map_data.hpp>
31#include <carma_v2x_msgs/msg/spat.hpp>
32#include <lanelet2_core/Forward.h>
33#include <lanelet2_extension/regulatory_elements/SignalizedIntersection.h>
34#include <lanelet2_core/geometry/LaneletMap.h>
35#include <carma_ros2_utils/carma_lifecycle_node.hpp>
36
37
38namespace carma_wm
39{
40
42{
43 static const uint8_t INGRESS = 2;
44 static const uint8_t EGRESS = 1;
45};
46
47enum class SIGNAL_PHASE_PROCESSING : uint8_t
48{
49 OFF = 0,
50 ON = 1,
51};
52
53using namespace lanelet::units::literals;
54
60{
61public:
62
64
73
81
89
99 void createIntersectionFromMapMsg(std::vector<lanelet::SignalizedIntersectionPtr>& intersections, std::vector<lanelet::CarmaTrafficSignalPtr>& traffic_signals, const carma_v2x_msgs::msg::MapData& map_msg,
100 const std::shared_ptr<lanelet::LaneletMap>& map, std::shared_ptr<const lanelet::routing::RoutingGraph> routing_graph);
101
113 void convertLaneToLaneletId(std::unordered_map<uint8_t, lanelet::Id>& entry, std::unordered_map<uint8_t, lanelet::Id>& exit, const carma_v2x_msgs::msg::IntersectionGeometry& intersection,
114 const std::shared_ptr<lanelet::LaneletMap>& map, std::shared_ptr<const lanelet::routing::RoutingGraph> current_routing_graph);
115
120 void setMaxLaneWidth(double max_lane_width);
121
128 lanelet::Id matchSignalizedIntersection(const lanelet::Lanelets& entry_llts, const lanelet::Lanelets& exit_llts);
129
134 void setTargetFrame(const std::string& target_frame);
135
143 std::shared_ptr<lanelet::CarmaTrafficSignal> createTrafficSignalUsingSGID(uint8_t signal_group_id, const lanelet::Lanelets& entry_lanelets, const lanelet::Lanelets& exit_lanelets);
144
152 lanelet::Lanelets identifyInteriorLanelets(const lanelet::Lanelets& entry_llts, const std::shared_ptr<lanelet::LaneletMap>& map);
153
160 void processSpatFromMsg(const carma_v2x_msgs::msg::SPAT& spat_msg,
161 const std::shared_ptr<lanelet::LaneletMap>& semantic_map);
162
171 std::tuple<std::vector<std::pair<boost::posix_time::ptime, lanelet::CarmaTrafficSignalState>>,
172 std::vector<boost::posix_time::ptime>>
174 const carma_v2x_msgs::msg::IntersectionState& curr_intersection,
175 const carma_v2x_msgs::msg::MovementState& current_movement_state);
176
185 boost::posix_time::ptime min_end_time_converter_minute_of_year(
186 boost::posix_time::ptime min_end_time,bool moy_exists,uint32_t moy=0,
187 bool is_simulation = true, bool use_real_time_spat_in_sim=false);
188
191 lanelet::Id getTrafficSignalId(uint16_t intersection_id,uint8_t signal_id);
192
195 lanelet::CarmaTrafficSignalPtr getTrafficSignal(const lanelet::Id& id,
196 const std::shared_ptr<lanelet::LaneletMap>& semantic_map) const;
197
198 // SignalizedIntersection's geometry points from MAP Msg
199 std::unordered_map<uint16_t, std::vector<lanelet::Point3d>> intersection_nodes_;
200
201 // SignalizedIntersection's reference point correction pair of (x, y) for each intersection_id
202 std::unordered_map<uint16_t, std::pair<double, double>> intersection_coord_correction_;
203
204 // SignalizedIntersection quick id lookup
205 std::unordered_map<uint16_t, lanelet::Id> intersection_id_to_regem_id_;
206
207 // SignalizedIntersection reverse quick id lookup
208 std::unordered_map<lanelet::Id, uint16_t> regem_id_to_intersection_id_;
209
210 // CarmaTrafficSignal quick id lookup
211 std::unordered_map<uint8_t, lanelet::Id> signal_group_to_traffic_light_id_;
212
213 // CarmaTrafficSignal exit lanelets ids quick lookup
214 std::unordered_map<uint8_t, std::unordered_set<lanelet::Id>> signal_group_to_exit_lanelet_ids_;
215
216 // CarmaTrafficSignal entry lanelets ids quick lookup
217 std::unordered_map<uint8_t, std::unordered_set<lanelet::Id>> signal_group_to_entry_lanelet_ids_;
218
219 std::optional<rclcpp::Time> ros1_clock_ = std::nullopt;
220 std::optional<rclcpp::Time> simulation_clock_ = std::nullopt;
221
225
226private:
227 // PROJ string of current map
228 std::string target_frame_ = "";
229
230 // Max width of lane in meters
231 double max_lane_width_ = 4;
232
233};
234
235} // namespace carma_wm
This class manages and keeps track of all signalized intersections in the map. All of the SPAT and MA...
lanelet::Lanelets identifyInteriorLanelets(const lanelet::Lanelets &entry_llts, const std::shared_ptr< lanelet::LaneletMap > &map)
Returns carma traffic signal and saves all id relevant id mappings (signal group to lanelet id) inter...
lanelet::Id matchSignalizedIntersection(const lanelet::Lanelets &entry_llts, const lanelet::Lanelets &exit_llts)
Returns existing signalized intersection with same entry and exit llts if exists.
std::unordered_map< uint16_t, std::vector< lanelet::Point3d > > intersection_nodes_
std::tuple< std::vector< std::pair< boost::posix_time::ptime, lanelet::CarmaTrafficSignalState > >, std::vector< boost::posix_time::ptime > > extract_signal_states_from_movement_state(const carma_v2x_msgs::msg::IntersectionState &curr_intersection, const carma_v2x_msgs::msg::MovementState &current_movement_state)
Extract tuple of 1) vector of pair of traffic signal states' min_end_time and their states,...
std::unordered_map< uint16_t, std::pair< double, double > > intersection_coord_correction_
void setTargetFrame(const std::string &target_frame)
Saves the georeference string to be used for converting MAP.msg coordinates.
std::unordered_map< uint8_t, std::unordered_set< lanelet::Id > > signal_group_to_entry_lanelet_ids_
std::unordered_map< lanelet::Id, uint16_t > regem_id_to_intersection_id_
std::unordered_map< uint16_t, lanelet::Id > intersection_id_to_regem_id_
lanelet::Id getTrafficSignalId(uint16_t intersection_id, uint8_t signal_id)
helper for traffic signal Id
std::shared_ptr< lanelet::CarmaTrafficSignal > createTrafficSignalUsingSGID(uint8_t signal_group_id, const lanelet::Lanelets &entry_lanelets, const lanelet::Lanelets &exit_lanelets)
Returns carma traffic signal and saves all id relevant id mappings (signal group to lanelet id) inter...
lanelet::CarmaTrafficSignalPtr getTrafficSignal(const lanelet::Id &id, const std::shared_ptr< lanelet::LaneletMap > &semantic_map) const
helper for getting traffic signal with given lanelet::Id
SignalizedIntersectionManager & operator=(SignalizedIntersectionManager other)
Assignment operator that copies everything except the traffic signal states. This is to keep the stat...
bool operator==(const SignalizedIntersectionManager &rhs)
Equality operator that checks if every mapping are same except the traffic signal states....
std::unordered_map< uint8_t, std::unordered_set< lanelet::Id > > signal_group_to_exit_lanelet_ids_
void processSpatFromMsg(const carma_v2x_msgs::msg::SPAT &spat_msg, const std::shared_ptr< lanelet::LaneletMap > &semantic_map)
processSpatFromMsg update map's traffic light states with SPAT msg NOTE: This is enabled in the indiv...
std::unordered_map< uint8_t, lanelet::Id > signal_group_to_traffic_light_id_
void convertLaneToLaneletId(std::unordered_map< uint8_t, lanelet::Id > &entry, std::unordered_map< uint8_t, lanelet::Id > &exit, const carma_v2x_msgs::msg::IntersectionGeometry &intersection, const std::shared_ptr< lanelet::LaneletMap > &map, std::shared_ptr< const lanelet::routing::RoutingGraph > current_routing_graph)
Returns mapping of MAP lane id to lanelet id for the given map and intersection.msg in the MAP....
boost::posix_time::ptime min_end_time_converter_minute_of_year(boost::posix_time::ptime min_end_time, bool moy_exists, uint32_t moy=0, bool is_simulation=true, bool use_real_time_spat_in_sim=false)
update minimum end time to account for minute of the year
void setMaxLaneWidth(double max_lane_width)
Sets the max lane width in meters. Map msg points are associated to a lanelet if they are within this...
void createIntersectionFromMapMsg(std::vector< lanelet::SignalizedIntersectionPtr > &intersections, std::vector< lanelet::CarmaTrafficSignalPtr > &traffic_signals, const carma_v2x_msgs::msg::MapData &map_msg, const std::shared_ptr< lanelet::LaneletMap > &map, std::shared_ptr< const lanelet::routing::RoutingGraph > routing_graph)
Create relevant signalized intersection and carma traffic signals based on the MAP....