15 #ifndef TRAFFIC_SIMULATOR__HDMAP_UTILS__HDMAP_UTILS_HPP_
16 #define TRAFFIC_SIMULATOR__HDMAP_UTILS__HDMAP_UTILS_HPP_
18 #include <geometry_msgs/msg/vector3.h>
19 #include <lanelet2_core/LaneletMap.h>
20 #include <lanelet2_core/geometry/Lanelet.h>
21 #include <lanelet2_core/primitives/BasicRegulatoryElements.h>
22 #include <lanelet2_core/primitives/LaneletSequence.h>
23 #include <lanelet2_matching/LaneletMatching.h>
24 #include <lanelet2_routing/Route.h>
25 #include <lanelet2_routing/RoutingCost.h>
26 #include <lanelet2_routing/RoutingGraph.h>
27 #include <lanelet2_routing/RoutingGraphContainer.h>
28 #include <lanelet2_traffic_rules/TrafficRulesFactory.h>
29 #include <tf2/LinearMath/Matrix3x3.h>
31 #include <autoware_lanelet2_extension/utility/message_conversion.hpp>
32 #include <autoware_lanelet2_extension/utility/query.hpp>
33 #include <autoware_lanelet2_extension/utility/utilities.hpp>
34 #include <autoware_map_msgs/msg/lanelet_map_bin.hpp>
35 #include <boost/filesystem.hpp>
36 #include <geographic_msgs/msg/geo_point.hpp>
40 #include <geometry_msgs/msg/pose_stamped.hpp>
44 #include <rclcpp/rclcpp.hpp>
46 #include <tf2_geometry_msgs/tf2_geometry_msgs.hpp>
51 #include <traffic_simulator_msgs/msg/bounding_box.hpp>
52 #include <traffic_simulator_msgs/msg/entity_status.hpp>
54 #include <unordered_map>
57 #include <visualization_msgs/msg/marker_array.hpp>
66 explicit HdMapUtils(
const boost::filesystem::path &,
const geographic_msgs::msg::GeoPoint &);
69 const lanelet::Id from,
const lanelet::Id to,
74 const lanelet::Id,
const double s,
const lanelet::Ids &,
75 const double forward_distance = 20)
const -> std::vector<geometry_msgs::msg::Point>;
83 auto filterLaneletIds(
const lanelet::Ids &,
const char subtype[])
const -> lanelet::Ids;
85 auto generateMarker()
const -> visualization_msgs::msg::MarkerArray;
87 auto getCenterPoints(
const lanelet::Ids &)
const -> std::vector<geometry_msgs::msg::Point>;
89 auto getCenterPoints(
const lanelet::Id)
const -> std::vector<geometry_msgs::msg::Point>;
92 -> std::shared_ptr<math::geometry::CatmullRomSpline>;
96 const bool include_crosswalk =
false)
const -> std::optional<lanelet::Id>;
99 const lanelet::Id lanelet_id,
const lanelet::Id crossing_lanelet_id)
const
100 -> std::optional<double>;
110 const lanelet::Id current_lanelet_id,
const lanelet::Ids &
route,
const double horizon = 100,
111 const bool include_current_lanelet_id =
true,
116 const lanelet::Id,
const double distance = 100,
const bool include_self =
true,
123 const double maximum_curvature_threshold,
const double target_trajectory_length,
124 const double forward_distance_threshold)
const
125 -> std::optional<std::pair<math::geometry::HermiteCurve, double>>;
130 -> std::optional<std::pair<math::geometry::HermiteCurve, double>>;
136 -> std::optional<lanelet::Id>;
142 -> std::optional<lanelet::Id>;
146 auto getLaneletPolygon(
const lanelet::Id)
const -> std::vector<geometry_msgs::msg::Point>;
148 auto getLanelets(
const lanelet::Ids &)
const -> lanelet::Lanelets;
152 const bool include_crosswalk,
const std::size_t search_count = 5)
const -> lanelet::Ids;
156 const std::size_t search_count = 5)
const -> lanelet::Ids;
159 const lanelet::Id,
const double backward_horizon = 100,
164 -> std::unordered_map<lanelet::Id, lanelet::Ids>;
169 const lanelet::Id from,
const lanelet::Id to,
179 -> std::optional<geometry_msgs::msg::Vector3>;
182 const lanelet::Id traffic_light_id,
const std::string &,
183 const bool allow_infer_position =
false)
const -> std::optional<geometry_msgs::msg::Point>;
196 -> std::vector<std::vector<geometry_msgs::msg::Point>>;
199 visualization_msgs::msg::MarkerArray &,
const visualization_msgs::msg::MarkerArray &)
const
204 auto isInLanelet(
const lanelet::Id,
const double s)
const -> bool;
206 auto isInRoute(
const lanelet::Id,
const lanelet::Ids &
route)
const -> bool;
215 constexpr
static double DEFAULT_MATCH_TO_LANE_REDUCTION_RATIO = 0.8;
218 auto toMapBin()
const -> autoware_map_msgs::msg::LaneletMapBin;
220 auto toMapPoints(
const lanelet::Id,
const std::vector<double> & s)
const
221 -> std::vector<geometry_msgs::msg::Point>;
232 lanelet::LaneletMapPtr lanelet_map_ptr_;
237 explicit RoutingGraphs(
const lanelet::LaneletMapPtr & lanelet_map);
241 lanelet::traffic_rules::TrafficRulesPtr
rules;
242 lanelet::routing::RoutingGraphPtr
graph;
246 [[nodiscard]] lanelet::routing::RoutingGraphPtr routing_graph(
249 [[nodiscard]] lanelet::traffic_rules::TrafficRulesPtr traffic_rule(
253 const lanelet::Id from_lanelet_id,
const lanelet::Id to_lanelet_id,
254 lanelet::LaneletMapPtr lanelet_map_ptr,
268 std::unique_ptr<RoutingGraphs> routing_graphs_;
270 template <
typename Lanelet>
271 auto getLaneletIds(
const std::vector<Lanelet> & lanelets)
const -> lanelet::Ids
275 lanelets.begin(), lanelets.end(), std::back_inserter(ids),
276 [](
const auto & lanelet) { return lanelet.id(); });
281 const lanelet::BasicPolygon2d & relative_hull,
const lanelet::matching::Pose2d &)
const
282 -> lanelet::BasicPolygon2d;
285 const std::vector<double> & x,
const std::vector<double> & y,
286 const std::vector<double> & z)
const -> std::vector<double>;
288 auto calculateAccumulatedLengths(
const lanelet::ConstLineString3d &)
const -> std::vector<double>;
290 auto calculateSegmentDistances(
const lanelet::ConstLineString3d &)
const -> std::vector<double>;
292 auto excludeSubtypeLanelets(
293 const std::vector<std::pair<double, lanelet::Lanelet>> &,
const char subtype[])
const
294 -> std::vector<std::pair<double, lanelet::Lanelet>>;
296 auto filterLanelets(
const lanelet::Lanelets &,
const char subtype[])
const -> lanelet::Lanelets;
298 auto findNearestIndexPair(
299 const std::vector<double> & accumulated_lengths,
const double target_length)
const
300 -> std::pair<std::size_t, std::size_t>;
302 auto generateFineCenterline(
const lanelet::ConstLanelet &,
const double resolution)
const
303 -> lanelet::LineString3d;
308 const double tangent_vector_size = 100) const ->
math::geometry::HermiteCurve;
310 auto getTrafficLightRegulatoryElementsOnPath(const lanelet::Ids &) const
311 ->
std::vector<
std::shared_ptr<const lanelet::
autoware::AutowareTrafficLight>>;
313 auto getTrafficLights(const lanelet::Id traffic_light_id) const
314 ->
std::vector<lanelet::AutowareTrafficLightConstPtr>;
316 auto getTrafficSignRegulatoryElementsOnPath(const lanelet::Ids &) const
317 ->
std::vector<
std::shared_ptr<const lanelet::TrafficSign>>;
319 auto getTrafficSignRegulatoryElements() const
320 ->
std::vector<
std::shared_ptr<const lanelet::TrafficSign>>;
322 auto getVectorFromPose(const geometry_msgs::msg::
Pose &, const
double magnitude) const
323 -> geometry_msgs::msg::
Vector3;
325 auto mapCallback(const autoware_map_msgs::msg::LaneletMapBin &) const ->
void;
327 auto resamplePoints(const lanelet::ConstLineString3d &, const
std::int32_t num_segments) const
328 -> lanelet::BasicPoints3d;
330 auto toPoint2d(const geometry_msgs::msg::
Point &) const -> lanelet::BasicPoint2d;
332 auto toPolygon(const lanelet::ConstLineString3d &) const
333 ->
std::vector<geometry_msgs::msg::
Point>;
Definition: hdmap_utils.hpp:64
auto getTangentVector(const lanelet::Id, const double s) const -> std::optional< geometry_msgs::msg::Vector3 >
Definition: hdmap_utils.cpp:895
auto getRoute(const lanelet::Id from, const lanelet::Id to, const traffic_simulator::RoutingConfiguration &routing_configuration=traffic_simulator::RoutingConfiguration()) const -> lanelet::Ids
Definition: hdmap_utils.cpp:572
auto toMapPoints(const lanelet::Id, const std::vector< double > &s) const -> std::vector< geometry_msgs::msg::Point >
Definition: hdmap_utils.cpp:884
HdMapUtils(const boost::filesystem::path &, const geographic_msgs::msg::GeoPoint &)
Definition: hdmap_utils.cpp:65
auto isInIntersection(const lanelet::Id) const -> bool
Definition: hdmap_utils.cpp:874
auto getCenterPointsSpline(const lanelet::Id) const -> std::shared_ptr< math::geometry::CatmullRomSpline >
Definition: hdmap_utils.cpp:580
auto getTrafficLightStopLinesPoints(const lanelet::Id traffic_light_id) const -> std::vector< std::vector< geometry_msgs::msg::Point >>
Definition: hdmap_utils.cpp:1122
auto getCollisionPointInLaneCoordinate(const lanelet::Id lanelet_id, const lanelet::Id crossing_lanelet_id) const -> std::optional< double >
Definition: hdmap_utils.cpp:204
auto getTrafficLightIds() const -> lanelet::Ids
Definition: hdmap_utils.cpp:640
auto getSpeedLimit(const lanelet::Ids &, const traffic_simulator::RoutingGraphType type=traffic_simulator::RoutingConfiguration().routing_graph_type) const -> double
Definition: hdmap_utils.cpp:395
auto getConflictingLaneIds(const lanelet::Ids &, const traffic_simulator::RoutingGraphType type=traffic_simulator::RoutingConfiguration().routing_graph_type) const -> lanelet::Ids
Definition: hdmap_utils.cpp:253
auto isInRoute(const lanelet::Id, const lanelet::Ids &route) const -> bool
Definition: hdmap_utils.cpp:485
auto canChangeLane(const lanelet::Id from, const lanelet::Id to, const traffic_simulator::RoutingGraphType type=traffic_simulator::RoutingConfiguration().routing_graph_type) const -> bool
Definition: hdmap_utils.cpp:901
auto getRightOfWayLaneletIds(const lanelet::Ids &) const -> std::unordered_map< lanelet::Id, lanelet::Ids >
Definition: hdmap_utils.cpp:1021
auto filterLaneletIds(const lanelet::Ids &, const char subtype[]) const -> lanelet::Ids
Definition: hdmap_utils.cpp:131
auto getLaneChangeTrajectory(const geometry_msgs::msg::Pose &from, const traffic_simulator::lane_change::Parameter &lane_change_parameter, const double maximum_curvature_threshold, const double target_trajectory_length, const double forward_distance_threshold) const -> std::optional< std::pair< math::geometry::HermiteCurve, double >>
Definition: hdmap_utils.cpp:782
auto getTrafficLightRegulatoryElement(const lanelet::Id) const -> lanelet::TrafficLight::Ptr
Definition: hdmap_utils.cpp:1294
auto isTrafficLightRegulatoryElement(const lanelet::Id) const -> bool
Definition: hdmap_utils.cpp:1287
auto clipTrajectoryFromLaneletIds(const lanelet::Id, const double s, const lanelet::Ids &, const double forward_distance=20) const -> std::vector< geometry_msgs::msg::Point >
Definition: hdmap_utils.cpp:265
auto getTrafficLightBulbPosition(const lanelet::Id traffic_light_id, const std::string &, const bool allow_infer_position=false) const -> std::optional< geometry_msgs::msg::Point >
Definition: hdmap_utils.cpp:659
auto getTrafficLightRegulatoryElementIDsFromTrafficLight(const lanelet::Id) const -> lanelet::Ids
Definition: hdmap_utils.cpp:1302
auto getTrafficLightIdsOnPath(const lanelet::Ids &route_lanelets) const -> lanelet::Ids
Definition: hdmap_utils.cpp:1144
auto isTrafficLight(const lanelet::Id) const -> bool
Definition: hdmap_utils.cpp:1273
auto getLaneletIds() const -> lanelet::Ids
Definition: hdmap_utils.cpp:106
auto getFollowingLanelets(const lanelet::Id current_lanelet_id, const lanelet::Ids &route, const double horizon=100, const bool include_current_lanelet_id=true, const traffic_simulator::RoutingGraphType type=traffic_simulator::RoutingConfiguration().routing_graph_type) const -> lanelet::Ids
Definition: hdmap_utils.cpp:490
auto generateMarker() const -> visualization_msgs::msg::MarkerArray
Definition: hdmap_utils.cpp:933
auto getClosestLaneletId(const geometry_msgs::msg::Pose &, const double distance_thresh=30.0, const bool include_crosswalk=false) const -> std::optional< lanelet::Id >
Definition: hdmap_utils.cpp:363
auto getTrafficLightStopLineIds(const lanelet::Id traffic_light_id) const -> lanelet::Ids
Definition: hdmap_utils.cpp:1110
auto getCenterPoints(const lanelet::Ids &) const -> std::vector< geometry_msgs::msg::Point >
Definition: hdmap_utils.cpp:587
auto getLaneletPolygon(const lanelet::Id) const -> std::vector< geometry_msgs::msg::Point >
Definition: hdmap_utils.cpp:115
auto toMapBin() const -> autoware_map_msgs::msg::LaneletMapBin
Definition: hdmap_utils.cpp:910
auto getLaneChangeableLaneletId(const lanelet::Id, const traffic_simulator::lane_change::Direction, const traffic_simulator::RoutingGraphType type=traffic_simulator::RoutingConfiguration().routing_graph_type) const -> std::optional< lanelet::Id >
Definition: hdmap_utils.cpp:435
auto getPreviousLanelets(const lanelet::Id, const double backward_horizon=100, const traffic_simulator::RoutingGraphType type=traffic_simulator::RoutingConfiguration().routing_graph_type) const -> lanelet::Ids
Definition: hdmap_utils.cpp:459
auto getLanelets(const lanelet::Ids &) const -> lanelet::Lanelets
Definition: hdmap_utils.cpp:1264
auto isInLanelet(const lanelet::Id, const double s) const -> bool
Definition: hdmap_utils.cpp:879
auto getConflictingCrosswalkIds(const lanelet::Ids &) const -> lanelet::Ids
Definition: hdmap_utils.cpp:260
auto getNearbyLaneletIds(const geometry_msgs::msg::Point &, const double distance_threshold, const bool include_crosswalk, const std::size_t search_count=5) const -> lanelet::Ids
Definition: hdmap_utils.cpp:166
auto insertMarkerArray(visualization_msgs::msg::MarkerArray &, const visualization_msgs::msg::MarkerArray &) const -> void
Definition: hdmap_utils.cpp:926
auto countLaneChanges(const traffic_simulator_msgs::msg::LaneletPose &from, const traffic_simulator_msgs::msg::LaneletPose &to, const traffic_simulator::RoutingConfiguration &routing_configuration=traffic_simulator::RoutingConfiguration()) const -> std::optional< std::pair< int, int >>
Definition: hdmap_utils.cpp:72
Definition: cache.hpp:109
Definition: sim_model_delay_steer_acc_geared_wo_fall_guard.hpp:26
LaneletType
Definition: hdmap_utils.hpp:61
Definition: bounding_box.hpp:32
auto distance(const geometry_msgs::Pose &pose1, const geometry_msgs::Pose &pose2)
Definition: detection_sensor.cpp:45
Definition: lanelet_wrapper.hpp:40
TrajectoryShape
Definition: lane_change.hpp:31
Direction
Definition: lane_change.hpp:29
auto route(const lanelet::Id from_lanelet_id, const lanelet::Id to_lanelet_id, const RoutingConfiguration &routing_configuration=RoutingConfiguration()) -> lanelet::Ids
Definition: route.cpp:33
geometry_msgs::msg::Pose Pose
Definition: lanelet_wrapper.hpp:66
geometry_msgs::msg::Point Point
Definition: lanelet_wrapper.hpp:65
geometry_msgs::msg::Vector3 Vector3
Definition: lanelet_wrapper.hpp:70
RoutingGraphType
Definition: routing_graph_type.hpp:24
traffic_simulator_msgs::msg::LaneletPose LaneletPose
Definition: lanelet_pose.hpp:23
std::string string
Definition: junit5.hpp:26
Definition: hdmap_utils.hpp:240
lanelet::traffic_rules::TrafficRulesPtr rules
Definition: hdmap_utils.hpp:241
RouteCache route_cache
Definition: hdmap_utils.hpp:243
lanelet::routing::RoutingGraphPtr graph
Definition: hdmap_utils.hpp:242
Definition: routing_configuration.hpp:24
parameters for behavior plugin
Definition: lane_change.hpp:75