23namespace waypoint_generation
26 const carma_planning_msgs::msg::VehicleState& state)
28 lanelet::BasicPoint2d veh_point(state.x_pos_global, state.y_pos_global);
29 double min_distance = std::numeric_limits<double>::max();
32 for (
const auto& p : points)
34 double distance = lanelet::geometry::distance2d(p, veh_point);
35 if (distance < min_distance)
38 min_distance = distance;
46 const carma_planning_msgs::msg::VehicleState& state)
48 lanelet::BasicPoint2d veh_point(state.x_pos_global, state.y_pos_global);
49 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
BASIC_AUTONOMY_LOGGER),
"veh_point: " << veh_point.x() <<
", " << veh_point.y());
50 double min_distance = std::numeric_limits<double>::max();
53 for (
const auto& p : points)
55 double distance = lanelet::geometry::distance2d(p.point, veh_point);
56 if (distance < min_distance)
59 min_distance = distance;
68 if(std::empty(points)){
69 RCLCPP_WARN_STREAM(rclcpp::get_logger(
BASIC_AUTONOMY_LOGGER),
"Empty points vector received, returning -1");
74 const auto itr = std::find_if(std::cbegin(points), std::cend(points),
75 [&wm = std::as_const(wm), target_downtrack](
const auto &
point) {
return wm->routeTrackPos(
point).downtrack > target_downtrack; });
77 int best_index = std::size(points) - 1;
80 if(itr != std::cbegin(points)){
81 best_index = std::distance(std::cbegin(points), std::prev(itr));
87 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
BASIC_AUTONOMY_LOGGER),
"get_nearest_index_by_downtrack>> Found best_index: " << best_index<<
", points[i].x(): " << points.at(best_index).x() <<
", points[i].y(): " << points.at(best_index).y());
93 std::vector<lanelet::BasicPoint2d>* basic_points,
94 std::vector<double>* speeds)
96 basic_points->reserve(points.size());
97 speeds->reserve(points.size());
99 for (
const auto& p : points)
101 basic_points->push_back(p.point);
102 speeds->push_back(p.speed);
107 const carma_planning_msgs::msg::VehicleState& state)
109 lanelet::BasicPoint2d state_pos(state.x_pos_global, state.y_pos_global);
110 double ending_downtrack = wm->routeTrackPos(state_pos).downtrack;
111 std::vector<lanelet::BasicPoint2d> basic_points;
112 std::vector<double> speeds;
118 const carma_planning_msgs::msg::VehicleState& state)
120 lanelet::BasicPoint2d state_pos(state.x_pos_global, state.y_pos_global);
121 double ending_downtrack = wm->routeTrackPos(state_pos).downtrack;
void split_point_speed_pairs(const std::vector< PointSpeedPair > &points, std::vector< lanelet::BasicPoint2d > *basic_points, std::vector< double > *speeds)
Helper method to split a list of PointSpeedPair into separate point and speed lists.
static const std::string BASIC_AUTONOMY_LOGGER
int get_nearest_point_index(const std::vector< lanelet::BasicPoint2d > &points, const carma_planning_msgs::msg::VehicleState &state)
Returns the nearest point (in terms of cartesian 2d distance) to the provided vehicle pose in the pro...
int get_nearest_index_by_downtrack(const std::vector< lanelet::BasicPoint2d > &points, const carma_wm::WorldModelConstPtr &wm, double target_downtrack)
Returns the nearest "less than" point to the provided vehicle pose in the provided list by utilizing ...
std::shared_ptr< const WorldModel > WorldModelConstPtr