21#include <lanelet2_routing/RoutingGraph.h>
22#include <lanelet2_traffic_rules/TrafficRulesFactory.h>
23#include <lanelet2_core/Attribute.h>
24#include <lanelet2_core/geometry/LineString.h>
25#include <lanelet2_core/primitives/Traits.h>
29#include <lanelet2_core/geometry/Polygon.h>
30#include <boost/geometry.hpp>
31#include <boost/geometry/geometries/polygon.hpp>
34#include <boost/math/special_functions/sign.hpp>
35#include <boost/date_time/posix_time/conversion.hpp>
45 throw std::invalid_argument(
"Route has not yet been loaded");
48 lanelet::ConstLineStrings3d outer_bound = area.outerBound();
50 if (outer_bound.empty())
52 throw std::invalid_argument(
"Provided area outer bound is invalid as it contains no points");
58 for (lanelet::ConstLineString3d sub_bound3d : outer_bound)
60 auto sub_bound = lanelet::utils::to2D(sub_bound3d);
61 for (lanelet::ConstPoint2d
point : sub_bound)
81 return std::make_pair(minPos, maxPos);
89 throw std::invalid_argument(
"Route has not yet been loaded");
92 lanelet::ConstLineString2d centerline = lanelet::utils::to2D(
lanelet.centerline());
93 if (centerline.empty())
95 throw std::invalid_argument(
"Provided lanelet has invalid centerline containing no points");
97 auto front = centerline.front();
106 RCLCPP_ERROR_STREAM(rclcpp::get_logger(
"carma_wm"),
"Map is not set or does not contain lanelets");
112 RCLCPP_ERROR_STREAM(rclcpp::get_logger(
"carma_wm"),
"Route has not yet been loaded");
115 std::vector<lanelet::BusStopRulePtr> bus_stop_list;
119 for (
const auto &ll :
route_->shortestPath())
121 auto bus_stops =
semantic_map_->laneletLayer.get(ll.id()).regulatoryElementsAs<lanelet::BusStopRule>();
122 if (bus_stops.empty())
127 for (
auto bus_stop : bus_stops)
129 auto stop_line = bus_stop->stopAndWaitLine();
130 if (stop_line.empty())
132 RCLCPP_ERROR_STREAM(rclcpp::get_logger(
"carma_wm"),
"No stop line");
137 double bus_stop_downtrack =
routeTrackPos(stop_line.front().front().basicPoint2d()).downtrack;
138 double distance_remaining_to_bus_stop = bus_stop_downtrack - curr_downtrack;
140 if (distance_remaining_to_bus_stop < 0)
144 bus_stop_list.push_back(bus_stop);
148 return bus_stop_list;
156 throw std::invalid_argument(
"Route has not yet been loaded");
160 lanelet::Points3d near_points =
168 if (lineString_1.size() == 0)
170 throw std::invalid_argument(
"Invalid route loaded. Shortest path does not have proper references");
186 lanelet::Id bestRouteSegId;
191 size_t ls_i = indexes.first;
192 size_t p_i = indexes.second;
194 if (near_points[0].
id() == lineString_1.front().id())
197 auto next_point = lineString_1[1];
202 bestRouteSegId = lineString_1.id();
209 const size_t prev_ls_i = ls_i - 1;
213 prev_centerline[prev_centerline.size() - 1].basicPoint());
215 bestRouteSegId = prev_centerline.id();
218 else if (near_points[0].
id() == lineString_1.back().id())
222 auto prev_prev_point = lineString_1[lineString_1.size() - 2];
223 auto prev_point = lineString_1[lineString_1.size() - 1];
227 double last_seg_length =
233 bestRouteSegId = lineString_1.id();
242 bestRouteSegId = next_centerline.id();
251 lanelet::BasicLineString2d subSegment = lanelet::BasicLineString2d(
252 { lineString_1[p_i - 1].basicPoint(), lineString_1[p_i].basicPoint(), lineString_1[p_i + 1].basicPoint() });
258 bestRouteSegId = lineString_1.id();
288 bool bounds_inclusive)
const
293 throw std::invalid_argument(
"Route has not yet been loaded");
297 throw std::invalid_argument(
"Start distance is greater than end distance");
300 std::vector<lanelet::ConstLanelet> output;
301 std::priority_queue<LaneletDowntrackPair, std::vector<LaneletDowntrackPair>, std::greater<LaneletDowntrackPair>>
302 prioritized_lanelets;
304 auto lanelet_map =
route_->laneletMap();
305 for (lanelet::ConstLanelet
lanelet : lanelet_map->laneletLayer)
311 lanelet::ConstLineString2d centerline = lanelet::utils::to2D(
lanelet.centerline());
313 auto front = centerline.front();
314 auto back = centerline.back();
318 if (!bounds_inclusive)
338 prioritized_lanelets.push(pair);
341 output.reserve(prioritized_lanelets.size());
342 while (!prioritized_lanelets.empty())
344 auto pair = prioritized_lanelets.top();
345 prioritized_lanelets.pop();
346 output.push_back(pair.lanelet_);
349 if (!shortest_path_only)
355 std::vector<lanelet::ConstLanelet> sorted_output;
356 for (
auto llt :
route_->shortestPath())
358 for (
size_t i = 0;
i < output.size();
i++)
360 if (llt.id() == output[
i].id())
362 sorted_output.push_back(llt);
368 return sorted_output;
372 double step_size)
const
374 std::vector<lanelet::BasicPoint2d> output;
377 RCLCPP_WARN_STREAM(rclcpp::get_logger(
"carma_wm"),
"Route has not yet been loaded");
383 if (start_downtrack < 0 || start_downtrack > route_end || end_downtrack < 0 || end_downtrack > route_end ||
384 start_downtrack > end_downtrack)
386 RCLCPP_WARN_STREAM(rclcpp::get_logger(
"carma_wm"),
"Invalid input downtracks");
390 TrackPos route_pos(start_downtrack, 0);
392 if (end_downtrack == start_downtrack)
398 output.reserve(2 + (end_downtrack - start_downtrack) / step_size);
399 double downtrack = start_downtrack;
400 while (downtrack < end_downtrack)
404 downtrack += step_size;
419 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"carma_wm"),
"Route has not yet been loaded");
425 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"carma_wm"),
"Tried to convert a downtrack of: " << downtrack
426 <<
" to map point, but it did not fit in route bounds of "
433 size_t ls_i = std::get<0>(indices);
434 size_t pt_i = std::get<1>(indices);
438 if (pt_i >= linestring.size())
445 double relative_downtrack = downtrack - ls_downtrack;
447 size_t centerline_size = linestring.size();
449 size_t prior_idx = std::min(pt_i, centerline_size - 1);
451 size_t next_idx = std::min(pt_i + 1, centerline_size - 1);
454 if (prior_idx == next_idx)
459 auto prior_point = linestring[prior_idx];
461 return lanelet::BasicPoint2d(prior_point.x(), prior_point.y());
464 lanelet::BasicPoint2d prior_point, next_point;
466 if (prior_idx < centerline_size - 1)
468 prior_point = linestring[prior_idx].basicPoint2d();
469 next_point = linestring[prior_idx + 1].basicPoint2d();
475 prior_point = linestring[prior_idx - 1].basicPoint2d();
476 next_point = linestring[prior_idx].basicPoint2d();
483 double theta = sigma + M_PI_2;
485 double delta_x = cos(theta) * -crosstrack;
486 double delta_y = sin(theta) * -crosstrack;
488 return lanelet::BasicPoint2d(
x + delta_x,
y + delta_y);
494 double prior_to_next_dist = next_downtrack - prior_downtrack;
495 double prior_to_target_dist = relative_downtrack - prior_downtrack;
496 double interpolation_percentage = 0;
498 if (prior_to_next_dist < 0.000001)
500 interpolation_percentage = 0;
504 interpolation_percentage = prior_to_target_dist / prior_to_next_dist;
507 auto prior_point = linestring[prior_idx].basicPoint2d();
508 auto next_point = linestring[next_idx].basicPoint2d();
509 auto delta_vec = next_point - prior_point;
511 double x = prior_point.x() + interpolation_percentage * delta_vec.x();
512 double y = prior_point.y() + interpolation_percentage * delta_vec.y();
517 double theta = sigma + M_PI_2;
519 double delta_x = cos(theta) * -crosstrack;
520 double delta_y = sin(theta) * -crosstrack;
526 return lanelet::BasicPoint2d(
x,
y);
531 return std::static_pointer_cast<lanelet::LaneletMap const>(
semantic_map_);
536 return std::static_pointer_cast<const lanelet::routing::Route>(
route_);
551 RCLCPP_INFO_STREAM(rclcpp::get_logger(
"carma_wm"),
"First time map is set in carma_wm. Routing graph will be recomputed reguardless of method inputs.");
553 recompute_routing_graph =
true;
560 if (recompute_routing_graph)
563 RCLCPP_INFO_STREAM(rclcpp::get_logger(
"carma_wm"),
"Building routing graph");
569 throw std::invalid_argument(
"Could not construct traffic rules for participant");
574 lanelet::routing::RoutingGraphUPtr map_graph = lanelet::routing::RoutingGraph::build(*
semantic_map_, *traffic_rules);
577 RCLCPP_INFO_STREAM(rclcpp::get_logger(
"carma_wm"),
"Done building routing graph");
583 RCLCPP_INFO_STREAM(rclcpp::get_logger(
"carma_wm"),
"Setting the routing graph with user or listener provided graph");
611 lanelet::ConstLanelets path_lanelets(
route_->shortestPath().begin(),
route_->shortestPath().end());
623 throw std::invalid_argument(
"Route endpoint set before route was available.");
626 lanelet::ConstPoint3d const_end_point{ lanelet::utils::getId(), end_point.x(), end_point.y(), end_point.z() };
628 route_->setEndPoint(const_end_point);
646 std::vector<lanelet::Point3d> coppied_points;
647 coppied_points.reserve(line.size());
649 for (
auto basic_p : line.basicLineString())
651 coppied_points.push_back(lanelet::Point3d(lanelet::utils::getId(), basic_p));
654 return lanelet::LineString3d(lanelet::utils::getId(), coppied_points);
661 lanelet::routing::LaneletPath shortest_path =
route_->shortestPath();
665 lanelet::routing::RoutingGraphUPtr shortest_path_graph =
668 std::vector<lanelet::LineString3d> lineStrings;
672 size_t next_index = 0;
674 for (lanelet::ConstLanelet ll : shortest_path)
682 if (next_index < shortest_path.size())
684 auto nextLanelet = shortest_path[next_index];
686 size_t connectionCount = shortest_path_graph->possiblePaths(ll, (uint32_t)2,
false).size();
688 if (connectionCount == 1)
693 lineStrings.size() == 0 || lineStrings.back().size() == 0 ?
696 if ((nextCenterline.size() <= 1) || (nextCenterline.size() <= 2 && offset == 1))
698 throw std::invalid_argument(
"Cannot process route with lanelet containing very short centerline");
700 lineStrings.back().insert(lineStrings.back().end(), nextCenterline.begin() + offset, nextCenterline.end());
702 else if (connectionCount == 0)
706 if (lineStrings.back().size() == 0)
709 lanelet::LineString3d empty_linestring;
710 empty_linestring.setId(lanelet::utils::getId());
711 distance_map.
pushBack(lanelet::utils::to2D(lineStrings.back()));
712 lineStrings.push_back(empty_linestring);
721 while (lineStrings.back().size() == 0)
722 lineStrings.pop_back();
740 return std::static_pointer_cast<const lanelet::routing::RoutingGraph>(
map_routing_graph_);
746 lanelet::Optional<TrafficRulesConstPtr> optional_ptr;
750 lanelet::traffic_rules::TrafficRulesUPtr traffic_rules = lanelet::traffic_rules::TrafficRulesFactory::create(
751 lanelet::traffic_rules::CarmaUSTrafficRules::Location, participant);
753 auto carma_traffic_rules = std::make_shared<lanelet::traffic_rules::CarmaUSTrafficRules>();
755 carma_traffic_rules = std::static_pointer_cast<lanelet::traffic_rules::CarmaUSTrafficRules>(
756 lanelet::traffic_rules::TrafficRulesPtr(std::move(traffic_rules)));
759 optional_ptr = std::static_pointer_cast<const lanelet::traffic_rules::CarmaUSTrafficRules>(carma_traffic_rules);
761 catch (
const lanelet::InvalidInputError& e)
775 lanelet::Optional<carma_perception_msgs::msg::RoadwayObstacle>
780 throw std::invalid_argument(
"Map is not set or does not contain lanelets");
783 lanelet::BasicPoint2d object_center(
object.pose.pose.position.x,
object.pose.pose.position.y);
787 if (!nearestLaneletBoost)
790 lanelet::Lanelet nearestLanelet = nearestLaneletBoost.get();
792 carma_perception_msgs::msg::RoadwayObstacle obs;
794 obs.connected_vehicle_type.type =
795 carma_perception_msgs::msg::ConnectedVehicleType::NOT_CONNECTED;
796 obs.lanelet_id = nearestLanelet.id();
799 obs.down_track = obj_track_pos.
downtrack;
802 for (
auto prediction :
object.predictions)
805 lanelet::BasicPolygon2d prediction_polygon =
807 lanelet::BasicPoint2d prediction_center(prediction.predicted_position.position.x,
808 prediction.predicted_position.position.y);
810 auto predNearestLanelet =
semantic_map_->laneletLayer.nearest(prediction_center, 1)[0];
814 obs.predicted_lanelet_ids.emplace_back(predNearestLanelet.id());
815 obs.predicted_cross_tracks.emplace_back(pred_track_pos.
crosstrack);
816 obs.predicted_down_tracks.emplace_back(pred_track_pos.
downtrack);
820 obs.predicted_lanelet_id_confidences.emplace_back(0.9 * prediction.predicted_position_confidence);
821 obs.predicted_cross_track_confidences.emplace_back(0.9 * prediction.predicted_position_confidence);
822 obs.predicted_down_track_confidences.emplace_back(0.9 * prediction.predicted_position_confidence);
842 std::vector<lanelet::ConstLanelet> lane =
getLane(
lanelet, section);
847 return std::vector<carma_perception_msgs::msg::RoadwayObstacle>{};
851 std::vector<carma_perception_msgs::msg::RoadwayObstacle> lane_objects, roadway_objects_copy =
roadway_objects_;
859 std::queue<int> obj_idxs_queue;
863 for (
size_t i = 0;
i < roadway_objects_copy.size();
i++)
865 obj_idxs_queue.push((
int)
i);
869 for (
auto llt : lane)
871 int checked_queue_items = 0, to_check = obj_idxs_queue.size();
873 while (checked_queue_items < to_check)
875 curr_idx = obj_idxs_queue.front();
876 obj_idxs_queue.pop();
877 checked_queue_items++;
880 auto curr_obj = roadway_objects_copy[curr_idx];
881 if (curr_obj.lanelet_id == llt.id())
884 lane_objects.push_back(curr_obj);
890 boost::geometry::intersects(
891 llt.polygon2d().basicPolygon(),
895 lane_objects.push_back(curr_obj);
900 obj_idxs_queue.push(curr_idx);
908 lanelet::Optional<lanelet::Lanelet>
914 throw std::invalid_argument(
"Map is not set or does not contain lanelets");
917 lanelet::BasicPoint2d object_center(
object.pose.pose.position.x,
object.pose.pose.position.y);
921 object_center, 1)[0];
925 if (!boost::geometry::intersects(nearestLanelet.polygon2d().basicPolygon(), object_polygon))
929 return nearestLanelet;
937 throw std::invalid_argument(
"Map is not set or does not contain lanelets");
945 auto curr_lanelet =
semantic_map_->laneletLayer.nearest(object_center, 1)[0];
948 if (!boost::geometry::within(object_center, curr_lanelet.polygon2d().basicPolygon()))
949 throw std::invalid_argument(
"Given point is not within any lanelet");
951 std::vector<carma_perception_msgs::msg::RoadwayObstacle> lane_objects =
getInLaneObjects(curr_lanelet);
954 if (lane_objects.size() == 0)
958 double min_dist = INFINITY;
964 double curr_dist = lanelet::geometry::distance(object_center, object_polygon);
965 if (min_dist > curr_dist)
966 min_dist = curr_dist;
973 lanelet::Optional<std::tuple<TrackPos, carma_perception_msgs::msg::RoadwayObstacle>>
979 throw std::invalid_argument(
"Map is not set or does not contain lanelets");
987 auto curr_lanelet =
semantic_map_->laneletLayer.nearest(object_center, 1)[0];
990 if (!boost::geometry::within(object_center, curr_lanelet.polygon2d().basicPolygon()))
991 throw std::invalid_argument(
"Given point is not within any lanelet");
994 std::vector<carma_perception_msgs::msg::RoadwayObstacle> lane_objects =
getInLaneObjects(curr_lanelet, section);
997 if (lane_objects.size() == 0)
1001 std::vector<lanelet::ConstLanelet> lane_section =
getLane(curr_lanelet, section);
1003 std::vector<double> object_downtracks, object_crosstracks;
1004 std::vector<int> object_idxs;
1005 std::queue<int> obj_idxs_queue;
1006 double base_downtrack = 0;
1007 double input_obj_downtrack = 0;
1012 for (
size_t i = 0;
i < lane_objects.size();
i++)
1014 obj_idxs_queue.push((
int)
i);
1018 for (
auto llt : lane_section)
1020 int checked_queue_items = 0, to_check = obj_idxs_queue.size();
1023 while (checked_queue_items < to_check)
1025 curr_idx = obj_idxs_queue.front();
1026 obj_idxs_queue.pop();
1027 checked_queue_items++;
1030 if (lane_objects[curr_idx].lanelet_id == llt.id())
1032 object_downtracks.push_back(base_downtrack + lane_objects[curr_idx].down_track);
1033 object_crosstracks.push_back(lane_objects[curr_idx].cross_track);
1034 object_idxs.push_back(curr_idx);
1043 lanelet::BasicPoint2d obj_center(lane_objects[curr_idx].
object.pose.pose.position.x,
1044 lane_objects[curr_idx].object.pose.pose.position.y);
1046 object_downtracks.push_back(base_downtrack + new_tp.
downtrack);
1047 object_crosstracks.push_back(lane_objects[curr_idx].cross_track);
1048 object_idxs.push_back(curr_idx);
1053 obj_idxs_queue.push(curr_idx);
1057 if (curr_lanelet.id() == llt.id())
1062 geometry::trackPos(llt.centerline().back().basicPoint2d(), llt.centerline().front().basicPoint2d(),
1063 llt.centerline().back().basicPoint2d())
1069 double min_dist = INFINITY;
1070 for (
size_t idx = 0; idx < object_downtracks.size(); idx++)
1072 if (min_dist > std::fabs(object_downtracks[idx] - input_obj_downtrack))
1074 min_dist = std::fabs(object_downtracks[idx] - input_obj_downtrack);
1081 return std::tuple<TrackPos, carma_perception_msgs::msg::RoadwayObstacle>(
1082 TrackPos(object_downtracks[min_idx] - input_obj_downtrack,
1083 object_crosstracks[min_idx] -
geometry::trackPos(curr_lanelet, object_center).crosstrack),
1084 lane_objects[object_idxs[min_idx]]);
1087 lanelet::Optional<std::tuple<TrackPos, carma_perception_msgs::msg::RoadwayObstacle>>
1093 lanelet::Optional<std::tuple<TrackPos, carma_perception_msgs::msg::RoadwayObstacle>>
1104 throw std::invalid_argument(
"Map is not set or does not contain lanelets");
1110 throw std::invalid_argument(
"Lanelet is not on the map");
1116 throw std::invalid_argument(
"Undefined lane section is requested");
1119 std::vector<lanelet::ConstLanelet> following_lane = {
lanelet};
1120 std::stack<lanelet::ConstLanelet> prev_lane_helper;
1121 std::vector<lanelet::ConstLanelet> prev_lane;
1125 while (connecting_lanelet.size() != 0)
1127 following_lane.push_back(connecting_lanelet[0]);
1131 return following_lane;
1135 while (connecting_lanelet.size() != 0)
1137 prev_lane_helper.push(connecting_lanelet[0]);
1142 while (prev_lane_helper.size() != 0)
1144 prev_lane.push_back(prev_lane_helper.top());
1145 prev_lane_helper.pop();
1156 prev_lane.insert(prev_lane.end(), following_lane.begin(), following_lane.end());
1205 RCLCPP_ERROR_STREAM(rclcpp::get_logger(
"carma_wm"),
"Map is not set or does not contain lanelets");
1211 RCLCPP_ERROR_STREAM(rclcpp::get_logger(
"carma_wm"),
"Route has not yet been loaded");
1214 std::vector<lanelet::CarmaTrafficSignalPtr> light_list;
1218 for (
const auto &ll :
route_->shortestPath())
1220 auto lights =
semantic_map_->laneletLayer.get(ll.id()).regulatoryElementsAs<lanelet::CarmaTrafficSignal>();
1226 for (
auto light : lights)
1228 auto stop_line = light->getStopLine(ll);
1231 RCLCPP_ERROR_STREAM(rclcpp::get_logger(
"carma_wm"),
"No stop line");
1236 double light_downtrack =
routeTrackPos(stop_line.get().front().basicPoint2d()).downtrack;
1237 double distance_remaining_to_traffic_light = light_downtrack - curr_downtrack;
1239 if (distance_remaining_to_traffic_light < 0)
1243 light_list.push_back(light);
1252 if (!traffic_signal)
1254 throw std::invalid_argument(
"Empty traffic signal pointer has been passed!");
1257 std::pair<lanelet::ConstLanelet, lanelet::ConstLanelet> entry_exit;
1258 bool found_entry =
false;
1259 bool found_exit =
false;
1260 auto entry_lanelets = traffic_signal->getControlStartLanelets();
1261 auto exit_lanelets = traffic_signal->getControlEndLanelets();
1264 for (
const auto& ll:
route_->shortestPath())
1268 for (
const auto& entry: entry_lanelets)
1270 if (ll.id() == entry.id())
1272 entry_exit.first = entry;
1281 for (
const auto& exit: exit_lanelets)
1283 if (ll.id() == exit.id())
1285 entry_exit.second = exit;
1292 if (found_entry && found_exit)
1305 RCLCPP_ERROR_STREAM(rclcpp::get_logger(
"carma_wm"),
"Map is not set or does not contain lanelets");
1311 RCLCPP_ERROR_STREAM(rclcpp::get_logger(
"carma_wm"),
"Route has not yet been loaded");
1314 std::vector<std::shared_ptr<lanelet::AllWayStop>> intersection_list;
1317 for(
const auto& ll :
route_->shortestPath())
1319 auto intersections =
semantic_map_->laneletLayer.get(ll.id()).regulatoryElementsAs<lanelet::AllWayStop>();
1320 if (intersections.empty())
1324 for (
auto intersection : intersections)
1326 double intersection_downtrack =
routeTrackPos(intersection->stopLines().front().front().basicPoint2d()).downtrack;
1327 if (intersection_downtrack < curr_downtrack)
1331 intersection_list.push_back(intersection);
1334 return intersection_list;
1342 RCLCPP_ERROR_STREAM(rclcpp::get_logger(
"carma_wm"),
"Map is not set or does not contain lanelets");
1348 RCLCPP_ERROR_STREAM(rclcpp::get_logger(
"carma_wm"),
"Route has not yet been loaded");
1351 std::vector<lanelet::SignalizedIntersectionPtr> intersection_list;
1354 for (
const auto &ll :
route_->shortestPath())
1356 auto intersections =
semantic_map_->laneletLayer.get(ll.id()).regulatoryElementsAs<lanelet::SignalizedIntersection>();
1357 if (intersections.empty())
1361 for (
auto intersection : intersections)
1363 double intersection_downtrack =
routeTrackPos(ll.centerline().back().basicPoint2d()).downtrack;
1364 if (intersection_downtrack < curr_downtrack)
1368 intersection_list.push_back(intersection);
1371 return intersection_list;
1376 if (!
route_ || lanelets_to_filter.empty())
1378 return std::nullopt;
1382 for (
const auto& llt : lanelets_to_filter)
1384 auto shortest_path =
route_->shortestPath();
1385 if (std::find(shortest_path.begin(), shortest_path.end(), llt) != shortest_path.end())
1391 return std::nullopt;
IndexedDistanceMap shortest_path_distance_map_
std::vector< carma_perception_msgs::msg::RoadwayObstacle > roadway_objects_
void setTrafficLightIds(uint32_t id, lanelet::Id lanelet_id)
Sets the id mapping between intersection/signal group and lanelet::Id for traffic lights in the map.
lanelet::Optional< double > distToNearestObjInLane(const lanelet::BasicPoint2d &object_center) const override
Gets Cartesian distance to the closest object on the same lane as the given point.
std::pair< TrackPos, TrackPos > routeTrackPos(const lanelet::ConstArea &area) const override
Returns a pair of TrackPos, computed in 2d, of the provided area relative to the current route....
std::vector< carma_perception_msgs::msg::RoadwayObstacle > getInLaneObjects(const lanelet::ConstLanelet &lanelet, const LaneSection §ion=LANE_AHEAD) const override
Gets all roadway objects currently in the same lane as the given lanelet.
boost::optional< lanelet::BasicPoint2d > pointFromRouteTrackPos(const TrackPos &route_pos) const override
Converts a route track position into a map frame cartesian point.
lanelet::LineString3d copyConstructLineString(const lanelet::ConstLineString3d &line) const
Helper function to perform a deep copy of a LineString and assign new ids to all the elements....
boost::optional< std::pair< lanelet::ConstLanelet, lanelet::ConstLanelet > > getEntryExitOfSignalAlongRoute(const lanelet::CarmaTrafficSignalPtr &traffic_signal) const override
Returns the entry and exit lanelet of the signal along the SHORTEST PATH of route....
std::vector< lanelet::Lanelet > getLaneletsFromPoint(const lanelet::BasicPoint2d &point, const unsigned int n)
(non-const version) Gets the underlying lanelet, given the cartesian point on the map
lanelet::Optional< lanelet::Lanelet > getIntersectingLanelet(const carma_perception_msgs::msg::ExternalObject &object) const override
Gets the a lanelet the object is currently on determined by its position on the semantic map....
std::vector< lanelet::BusStopRulePtr > getBusStopsAlongRoute(const lanelet::BasicPoint2d &loc) const override
Return a list of bus stop along the current route. The bus stop along a route and the next bus stop a...
std::string participant_type_
void setVehicleParticipationType(const std::string &participant)
Set vehicle participation type.
void setConfigSpeedLimit(double config_lim)
std::optional< lanelet::ConstLanelet > getFirstLaneletOnShortestPath(const std::vector< lanelet::ConstLanelet > &lanelets_to_filter) const
Given the vector of lanelets, returns the lanelet that's on the shortest path. Returns earliest lanel...
lanelet::Optional< std::tuple< TrackPos, carma_perception_msgs::msg::RoadwayObstacle > > getNearestObjInLane(const lanelet::BasicPoint2d &object_center, const LaneSection §ion=LANE_AHEAD) const
This function is called by distanceToObjectBehindInLane or distanceToObjectAheadInLane....
lanelet::LaneletMapConstPtr getMap() const override
Get a pointer to the current map. If the underlying map has changed the pointer will also need to be ...
void setMap(lanelet::LaneletMapPtr map, size_t map_version=0, bool recompute_routing_graph=true)
Set the current map.
lanelet::LaneletSubmapConstUPtr shortest_path_view_
LaneletRouteConstPtr getRoute() const override
Get a pointer to the current route. If the underlying route has changed the pointer will also need to...
void setRoutingGraph(LaneletRoutingGraphPtr graph)
Set the routing graph for the participant type. This function may serve as an optimization to recompu...
lanelet::Optional< TrafficRulesConstPtr > getTrafficRules() const override
Get the Traffic Rules object.
void computeDowntrackReferenceLine()
Helper function to compute the geometry of the route downtrack/crosstrack reference line This functio...
LaneletRoutingGraphPtr map_routing_graph_
std::unordered_map< uint32_t, lanelet::Id > traffic_light_ids_
void setRouteName(const std::string &route_name)
Set the name of the route.
void setSimulationClock(const rclcpp::Time &time_now)
Set simulation clock clock (only used in simulation runs)
void setRouteEndPoint(const lanelet::BasicPoint3d &end_point)
Set endpoint of the route.
std::vector< lanelet::ConstLanelet > getLane(const lanelet::ConstLanelet &lanelet, const LaneSection §ion=LANE_AHEAD) const override
Gets the specified lane section achievable without lane change, sorted from the start,...
std::string getVehicleParticipationType()
Get vehicle participation type.
std::vector< lanelet::ConstLanelet > getLaneletsBetween(double start, double end, bool shortest_path_only=false, bool bounds_inclusive=true) const override
Returns a list of lanelets which are part of the route and whose downtrack bounds exist within the pr...
void setRos1Clock(const rclcpp::Time &time_now)
Set current Ros1 clock (only used in simulation runs)
lanelet::Optional< std::tuple< TrackPos, carma_perception_msgs::msg::RoadwayObstacle > > nearestObjectBehindInLane(const lanelet::BasicPoint2d &object_center) const override
Gets Downtrack distance to AND copy of the closest object BEHIND on the same lane as the given point....
double config_speed_limit_
lanelet::LaneletMapPtr getMutableMap() const
Get a mutable version of the current map.
carma_wm::SignalizedIntersectionManager sim_
TrackPos getRouteEndTrackPos() const override
Get trackpos of the end of route point relative to the route.
std::vector< lanelet::Lanelet > nonConnectedAdjacentLeft(const lanelet::BasicPoint2d &input_point, const unsigned int n=10)
(non-const version) Given the cartesian point on the map, tries to get the opposite direction lanelet...
lanelet::LaneletMapUPtr shortest_path_filtered_centerline_view_
std::vector< std::shared_ptr< lanelet::AllWayStop > > getIntersectionsAlongRoute(const lanelet::BasicPoint2d &loc) const override
Return a list of all way stop intersections along the current route. The tall way stop intersections ...
std::shared_ptr< lanelet::LaneletMap > semantic_map_
void setRoute(LaneletRoutePtr route)
Set the current route. This route must match the current map for this class to function properly.
LaneletRoutingGraphConstPtr getMapRoutingGraph() const override
Get a pointer to the routing graph for the current map. If the underlying map has changed the pointer...
size_t getMapVersion() const override
Returns a monotonically increasing version number which represents the version stamp of the map geome...
void setRoadwayObjects(const std::vector< carma_perception_msgs::msg::RoadwayObstacle > &rw_objs)
Update internal records of roadway objects. These objects MUST be guaranteed to be on the road.
std::vector< lanelet::LineString3d > shortest_path_centerlines_
std::vector< lanelet::CarmaTrafficSignalPtr > getSignalsAlongRoute(const lanelet::BasicPoint2d &loc) const override
Return a list of traffic lights/intersections along the current route. The traffic lights along a rou...
std::vector< carma_perception_msgs::msg::RoadwayObstacle > getRoadwayObjects() const override
Get most recent roadway objects - all objects on the road detected by perception stack.
lanelet::Optional< carma_perception_msgs::msg::RoadwayObstacle > toRoadwayObstacle(const carma_perception_msgs::msg::ExternalObject &object) const override
Converts an ExternalObject in a RoadwayObstacle by mapping its position onto the semantic map....
std::vector< lanelet::BasicPoint2d > sampleRoutePoints(double start_downtrack, double end_downtrack, double step_size) const override
Samples the route centerline between the provided downtracks with the provided step size....
std::vector< lanelet::SignalizedIntersectionPtr > getSignalizedIntersectionsAlongRoute(const lanelet::BasicPoint2d &loc) const
Return a list of signalized intersections along the current route. The signalized intersections along...
lanelet::Optional< std::tuple< TrackPos, carma_perception_msgs::msg::RoadwayObstacle > > nearestObjectAheadInLane(const lanelet::BasicPoint2d &object_center) const override
Gets Downtrack distance to AND copy of the closest object AHEAD on the same lane as the given point....
std::string getRouteName() const override
Get the current route name.
O(1) distance lookup structure for quickly accessing route distance information. NOTE: This structure...
std::pair< size_t, size_t > getIndexFromId(const lanelet::Id &id) const
Returns the indexes of the element identified by the provided Id NOTE: It is up to the user to know i...
void pushBack(const lanelet::LineString2d &ls)
Add a linestring to this structure. This function will iterate over the line string to compute distan...
std::pair< size_t, size_t > getElementIndexByDistance(double distance, bool get_point=true) const
Returns index of the linestring which the provided distance is within. NOTE: Unlike the rest of this ...
double distanceToPointAlongElement(size_t index, size_t point_index) const
Get the along-line distance to the point on the provided linestring.
double distanceToElement(size_t index) const
Get the distance to the start of the linestring at the specified index.
size_t size() const
Returns number of linestrings in this structure.
double distanceBetween(size_t index, size_t p1_index, size_t p2_index) const
Get the distance between two points on the same linestring.
bool operator>(const LaneletDowntrackPair &pair) const
lanelet::ConstLanelet lanelet_
LaneletDowntrackPair(lanelet::ConstLanelet lanelet, double downtrack)
bool operator<(const LaneletDowntrackPair &pair) const
std::optional< rclcpp::Time > simulation_clock_
std::optional< rclcpp::Time > ros1_clock_
Position in a track based coordinate system where the axis are downtrack and crosstrack....
auto to_string(const UtmZone &zone) -> std::string
lanelet::BasicPolygon2d objectToMapPolygon(const geometry_msgs::msg::Pose &pose, const geometry_msgs::msg::Vector3 &size)
Uses the provided pose and size vector of an ExternalObject to compute what the polygon would be of t...
double point_to_point_yaw(const lanelet::BasicPoint2d &cur_point, const lanelet::BasicPoint2d &next_point)
Computes the 2d orientation of the vector from the provided start point to end point.
std::tuple< TrackPos, lanelet::BasicSegment2d > matchSegment(const lanelet::BasicPoint2d &p, const lanelet::BasicLineString2d &line_string)
Get the TrackPos of the provided point along the linestring and the segment of the line string which ...
TrackPos trackPos(const lanelet::ConstLanelet &lanelet, const lanelet::BasicPoint2d &point)
Returns the TrackPos, computed in 2d, of the provided point relative to the centerline of the provide...
std::vector< lanelet::ConstLanelet > getLaneletsFromPoint(const lanelet::LaneletMapConstPtr &semantic_map, const lanelet::BasicPoint2d &point, const unsigned int n=10)
carma_wm::query namespace contains implementations for query functions (input and output read or writ...
std::shared_ptr< lanelet::routing::RoutingGraph > LaneletRoutingGraphPtr
std::shared_ptr< const lanelet::traffic_rules::TrafficRules > TrafficRulesConstPtr
std::shared_ptr< const lanelet::routing::Route > LaneletRouteConstPtr
std::shared_ptr< const lanelet::routing::RoutingGraph > LaneletRoutingGraphConstPtr
std::shared_ptr< lanelet::routing::Route > LaneletRoutePtr