42constexpr double kEpislon = 1e-6;
52double NaviObstacleDecider::GetMinLaneWidth(
53 const std::vector<common::PathPoint>& path_data_points,
55 double min_lane_width = std::numeric_limits<double>::max();
56 double lane_left_width = 0.0;
57 double lane_right_width = 0.0;
58 for (
const auto& path_data_point : path_data_points) {
59 bool ret = reference_line.
GetLaneWidth(path_data_point.s(),
60 &lane_left_width, &lane_right_width);
62 double lane_width = lane_left_width + lane_right_width;
63 if (lane_width < min_lane_width) {
64 min_lane_width = lane_width;
68 return min_lane_width;
71void NaviObstacleDecider::AddObstacleOffsetDirection(
72 const common::PathPoint& projection_point,
73 const std::vector<common::PathPoint>& path_data_points,
74 const Obstacle* current_obstacle,
const double proj_len,
double* dist) {
75 Vec2d p1(projection_point.x(), projection_point.y());
77 if ((proj_len + 1) > path_data_points.back().s()) {
78 p2.set_x(path_data_points.back().x());
79 p2.set_y(path_data_points.back().y());
85 auto d = ((current_obstacle->Perception().position().x() - p1.x()) *
87 ((current_obstacle->Perception().position().y() - p1.y()) *
94bool NaviObstacleDecider::IsNeedFilterObstacle(
95 const Obstacle* current_obstacle,
const PathPoint& vehicle_projection_point,
96 const std::vector<common::PathPoint>& path_data_points,
97 const common::VehicleState& vehicle_state,
98 PathPoint* projection_point_ptr) {
99 bool is_filter =
true;
101 path_data_points, current_obstacle->Perception().position().x(),
102 current_obstacle->Perception().position().y());
103 ADEBUG <<
"obstacle distance : " << projection_point_ptr->s()
104 <<
"vehicle distance : " << vehicle_projection_point.s();
105 if ((projection_point_ptr->s() - vehicle_projection_point.s()) >
110 double vehicle_frontedge_position =
111 vehicle_projection_point.s() + VehicleParam().
length();
112 double vehicle_backedge_position = vehicle_projection_point.s();
114 double obstacle_start_position =
115 projection_point_ptr->s() - current_obstacle->Perception().length() / 2.0;
116 double obstacle_end_position =
117 projection_point_ptr->s() + current_obstacle->Perception().length() / 2.0;
118 if ((vehicle_backedge_position - obstacle_end_position) >
122 if ((obstacle_start_position - vehicle_frontedge_position) >
124 if (!current_obstacle->IsStatic()) {
125 if (current_obstacle->Perception().velocity().x() > 0.0) {
134void NaviObstacleDecider::ProcessObstacle(
135 const std::vector<const Obstacle*>& obstacles,
136 const std::vector<common::PathPoint>& path_data_points,
137 const PathDecision& path_decision,
const double min_lane_width,
138 const common::VehicleState& vehicle_state) {
139 auto func_distance = [](
const PathPoint& point,
const double x,
141 double dx = point.x() - x;
142 double dy = point.y() - y;
143 return sqrt(dx * dx + dy * dy);
146 PathPoint projection_point;
147 PathPoint vehicle_projection_point =
149 for (
const auto& current_obstacle : obstacles) {
150 bool is_continue = IsNeedFilterObstacle(
151 current_obstacle, vehicle_projection_point, path_data_points,
152 vehicle_state, &projection_point);
156 auto dist = func_distance(projection_point,
157 current_obstacle->Perception().position().x(),
158 current_obstacle->Perception().position().y());
162 VehicleParam().left_edge_to_center())) {
163 auto proj_len = projection_point.s();
164 if (std::fabs(proj_len) <= kEpislon ||
165 proj_len >= path_data_points.back().s()) {
168 AddObstacleOffsetDirection(projection_point, path_data_points,
169 current_obstacle, proj_len, &dist);
170 obstacle_lat_dist_.emplace(std::pair<double, double>(
171 current_obstacle->Perception().width(), dist));
176double NaviObstacleDecider::GetObstacleActualOffsetDistance(
177 std::map<double, double>::iterator iter,
const double right_nudge_lane,
178 const double left_nudge_lane,
int* lane_obstacles_num) {
179 auto obs_width = iter->first;
180 auto lat_dist = iter->second;
181 ADEBUG <<
"get obstacle width : " << obs_width
182 <<
"get latitude distance : " << lat_dist;
183 auto actual_dist = std::fabs(lat_dist) - obs_width / 2.0 -
186 if (last_nudge_dist_ > 0) {
188 if (actual_dist < std::fabs(right_nudge_lane) + config_.
safe_distance()) {
189 *lane_obstacles_num = *lane_obstacles_num + 1;
192 }
else if (last_nudge_dist_ < 0) {
194 if (actual_dist < std::fabs(left_nudge_lane) + config_.
safe_distance()) {
195 *lane_obstacles_num = *lane_obstacles_num + 1;
200 if ((last_lane_obstacles_num_ != 0) && (*lane_obstacles_num == 0) &&
201 (!is_obstacle_stable_)) {
202 is_obstacle_stable_ =
true;
204 ADEBUG <<
"begin keep obstacles";
207 if (is_obstacle_stable_) {
210 is_obstacle_stable_ =
false;
212 *lane_obstacles_num = last_lane_obstacles_num_;
214 ADEBUG <<
"statist_count_ : " << statist_count_;
216 last_lane_obstacles_num_ = *lane_obstacles_num;
217 ADEBUG <<
"last_nudge_dist : " << last_nudge_dist_
218 <<
"lat_dist : " << lat_dist <<
"actual_dist : " << actual_dist;
222void NaviObstacleDecider::RecordLastNudgeDistance(
const double nudge_dist) {
225 if (std::fabs(nudge_dist) > tolerance) {
226 if (std::fabs(nudge_dist) > std::fabs(last_nudge_dist_)) {
227 last_nudge_dist_ = nudge_dist;
235 last_nudge_dist_ = 0.0;
239void NaviObstacleDecider::SmoothNudgeDistance(
240 const common::VehicleState& vehicle_state,
double* nudge_dist) {
241 CHECK_NOTNULL(nudge_dist);
245 limit_speed_num_ = 0;
251 ++eliminate_clutter_num_;
253 eliminate_clutter_num_ = 0;
258 ADEBUG <<
"eliminate_clutter_num_: " << eliminate_clutter_num_;
262 const std::vector<const Obstacle*>& obstacles,
264 const std::vector<common::PathPoint>& path_data_points,
266 CHECK_NOTNULL(lane_obstacles_num);
269 double left_nudge_lane = 0.0;
270 double right_nudge_lane = 0.0;
271 double routing_y = path_data_points[0].y();
272 double min_lane_width = GetMinLaneWidth(path_data_points, reference_line);
274 ADEBUG <<
"get min_lane_width: " << min_lane_width;
275 if (routing_y <= 0.0) {
276 left_nudge_lane = min_lane_width / 2.0 - std::fabs(routing_y) -
278 right_nudge_lane = -1.0 * (min_lane_width / 2.0 + std::fabs(routing_y) -
281 left_nudge_lane = min_lane_width / 2.0 + std::fabs(routing_y) -
283 right_nudge_lane = -1.0 * (min_lane_width / 2.0 - std::fabs(routing_y) -
289 double left_nudge_obstacle = 0.0;
290 double right_nudge_obstacle = 0.0;
293 obstacle_lat_dist_.clear();
294 ProcessObstacle(obstacles, path_data_points, path_decision, min_lane_width,
296 for (
auto iter = obstacle_lat_dist_.begin(); iter != obstacle_lat_dist_.end();
298 auto actual_dist = GetObstacleActualOffsetDistance(
299 iter, right_nudge_lane, left_nudge_lane, lane_obstacles_num);
300 auto lat_dist = iter->second;
304 if (lat_dist >= 0.0) {
305 right_nudge_obstacle =
306 -1.0 * std::max(std::fabs(right_nudge_obstacle), need_nudge_dist);
308 left_nudge_obstacle =
309 std::max(std::fabs(left_nudge_obstacle), need_nudge_dist);
313 ADEBUG <<
"get left_nudge_lane: " << left_nudge_lane
314 <<
"get right_nudge_lane : " << right_nudge_lane
315 <<
"get left_nudge_obstacle: " << left_nudge_obstacle
316 <<
"get right_nudge_obstacle : " << right_nudge_obstacle;
318 double nudge_dist = 0.0;
319 if (std::fabs(left_nudge_obstacle) > kEpislon &&
320 std::fabs(right_nudge_obstacle) <= kEpislon) {
321 nudge_dist = std::min(left_nudge_lane, left_nudge_obstacle);
322 }
else if (std::fabs(right_nudge_obstacle) > kEpislon &&
323 std::fabs(left_nudge_obstacle) <= kEpislon) {
324 nudge_dist = std::max(right_nudge_lane, right_nudge_obstacle);
327 ADEBUG <<
"get nudge distance : " << nudge_dist
328 <<
"get lane_obstacles_num : " << *lane_obstacles_num;
329 RecordLastNudgeDistance(nudge_dist);
330 SmoothNudgeDistance(vehicle_state, &nudge_dist);
331 KeepNudgePosition(nudge_dist, lane_obstacles_num);
332 ADEBUG <<
"last nudge distance : " << nudge_dist;
336void NaviObstacleDecider::KeepNudgePosition(
const double nudge_dist,
337 int* lane_obstacles_num) {
342 keep_nudge_flag_ =
true;
344 if (keep_nudge_flag_) {
347 *lane_obstacles_num = 0;
348 keep_nudge_flag_ =
false;
350 *lane_obstacles_num = 1;
353 ADEBUG <<
"get lane_obstacles_num : " << *lane_obstacles_num;
357 const std::vector<common::PathPoint>& path_data_points,
358 const std::vector<const Obstacle*>& obstacles) {
360 double reference_line_y = path_data_points[0].y();
363 double unsafe_refline_pos_y = 0.0;
364 double unsafe_car_pos_y = 0.0;
365 std::pair<double, double> unsafe_range;
366 if (reference_line_y < 0.0) {
367 unsafe_refline_pos_y = reference_line_y -
372 unsafe_range = std::make_pair(unsafe_refline_pos_y, unsafe_car_pos_y);
374 unsafe_refline_pos_y = reference_line_y +
379 unsafe_range = std::make_pair(unsafe_car_pos_y, unsafe_refline_pos_y);
382 unsafe_obstacle_info_.clear();
385 for (
const auto& iter : obstacles) {
386 const double obstacle_y = iter->Perception().position().y();
387 if ((obstacle_y > unsafe_range.first && obstacle_y < unsafe_range.second) ||
388 std::abs(iter->Perception().velocity().y()) >
391 path_data_points, iter->Perception().position().x(), obstacle_y);
392 if (vehicle_projection_point.
s() >= projection_point.s()) {
395 auto front_distance =
396 (projection_point.s() - iter->Perception().length() / 2.0) -
397 vehicle_projection_point.
s();
398 auto ref_theta = projection_point.theta();
399 auto project_velocity =
400 iter->Perception().velocity().x() * std::cos(ref_theta) +
401 iter->Perception().velocity().y() * std::sin(ref_theta);
402 ADEBUG <<
"Lateral speed : " << iter->Perception().velocity().y();
403 unsafe_obstacle_info_.emplace_back(iter->Id(), front_distance,
static PathPoint MatchToPath(const std::vector< PathPoint > &reference_line, const double x, const double y)
Implements a class of 2-dimensional vectors.
bool Init(const PlannerNaviConfig &config) override
Initialization parameters
void GetUnsafeObstaclesInfo(const std::vector< common::PathPoint > &path_data_points, const std::vector< const Obstacle * > &obstacles)
get the unsafe obstacles between trajectory and reference line.
double GetNudgeDistance(const std::vector< const Obstacle * > &obstacles, const ReferenceLine &reference_line, const PathDecision &path_decision, const std::vector< common::PathPoint > &path_data_points, const common::VehicleState &vehicle_state, int *lane_obstacles_num)
get the actual nudgable distance according to the position of the obstacle
PathDecision represents all obstacle decisions on one path.
bool GetLaneWidth(const double s, double *const lane_left_width, double *const lane_right_width) const
Planning module main class.
Define the LineSegment2d class.
Linear interpolation functions.
This file provides the declaration of the class "NaviSpeedDecider".
optional double left_edge_to_center
optional double right_edge_to_center
optional double max_nudge_distance
optional uint32 max_keep_nudge_cycles
optional uint32 cycles_number
optional double basis_dis_value
optional double nudge_allow_tolerance
optional double safe_distance
optional double speed_decider_detect_range
optional double max_allow_nudge_speed
optional double lateral_velocity_value
optional double judge_dis_coeff
optional double min_nudge_distance
optional NaviObstacleDeciderConfig navi_obstacle_decider_config