103 {
104 bool enable_lane_borrow = false;
105 bool lane_follow_enough_space = false;
106 double check_s = reference_line_info.AdcSlBoundary().end_s();
107 auto ref_point = reference_line_info.reference_line().GetNearestReferencePoint(check_s);
108 const auto waypoint = ref_point.lane_waypoints().front();
110 auto ptr_lane_info = reference_line_info.LocateLaneInfo(check_s);
111 if (ptr_lane_info == nullptr) {
112 AWARN <<
"ptr_lane_info is null";
113 return false;
114 }
115 if (!ptr_lane_info->lane().left_neighbor_forward_lane_id().empty()
116 || !ptr_lane_info->lane().left_neighbor_reverse_lane_id().empty()) {
117 AERROR <<
"check_s: " << check_s;
122 AINFO <<
"cannot borrow left lane";
123 } else {
124 enable_lane_borrow = true;
125 }
126 }
127 AERROR <<
"check_s: " << check_s;
128 if (!ptr_lane_info->lane().right_neighbor_forward_lane_id().empty()
129 || !ptr_lane_info->lane().right_neighbor_reverse_lane_id().empty()) {
133 AINFO <<
"cannot borrow right lane";
134 } else {
135 enable_lane_borrow = true;
136 }
137 }
138
139 const Obstacle* block_obs = reference_line_info.path_decision().Find(blocking_obstacle_id);
140 double ego_width = common::VehicleConfigHelper::Instance()->GetConfig().vehicle_param().width();
141 const auto obstacle_sl = block_obs->PerceptionSLBoundary();
142 double obs_start_l = obstacle_sl.start_l();
143 double obs_end_l = obstacle_sl.end_l();
144 double check_start_s = obstacle_sl.start_s();
145 double check_end_s = obstacle_sl.end_s();
146 double obs_s = (check_start_s + check_end_s) / 2;
147 double left_lane_width = 0.0;
148 double right_lane_width = 0.0;
149 reference_line_info.reference_line().GetLaneWidth(obs_s, &left_lane_width, &right_lane_width);
150 const PathDecision& path_decision = reference_line_info.path_decision();
151
152 std::vector<std::pair<double, int>> obs_l_range;
153 for (const auto* ptr_obstacle_item : path_decision.obstacles().Items()) {
154 const Obstacle* ptr_obstacle = path_decision.Find(ptr_obstacle_item->Id());
155 if (ptr_obstacle == nullptr || !ptr_obstacle->IsStatic()
156 || ptr_obstacle->IsVirtual()) {
157 continue;
158 }
159 const SLBoundary& obs_sl_boundary = ptr_obstacle_item->PerceptionSLBoundary();
160 if (obs_sl_boundary.start_s() > check_end_s || obs_sl_boundary.end_s() < check_start_s) {
161 continue;
162 }
163 obs_l_range.emplace_back(std::make_pair(obs_sl_boundary.start_l(), 0));
164 obs_l_range.emplace_back(std::make_pair(obs_sl_boundary.end_l(), 1));
165 AINFO <<
"obstacle: " << ptr_obstacle->Id() <<
" " << obs_sl_boundary.start_l() <<
" "
166 << obs_sl_boundary.end_l();
167 AINFO << ptr_obstacle->DebugString();
168 }
169 std::sort(obs_l_range.begin(), obs_l_range.end(), [](std::pair<double, int>& p1, std::pair<double, int>& p2) {
170 return p1.first < p2.first;
171 });
172 int gap_count = 0;
173 std::vector<double> space_gap;
174 for (size_t i = 0; i < obs_l_range.size(); ++i) {
175 if (gap_count == 0) {
176 space_gap.push_back(obs_l_range.at(i).first);
177 AINFO <<
"space_gap: " << space_gap.back();
178 }
179 if (gap_count < 0) {
181 return false;
182 }
183 if (obs_l_range.at(i).second == 0) {
184 gap_count++;
185 } else if (obs_l_range.at(i).second == 1) {
186 gap_count--;
187 }
188 if (gap_count == 0) {
189 space_gap.push_back(obs_l_range.at(i).first);
190 AINFO <<
"space_gap: " << space_gap.back();
191 }
192 }
193 if (space_gap.empty()) {
194 AINFO <<
"space_gap is empty";
195 space_gap.push_back(left_lane_width);
196 }
197 double max_gap = right_lane_width + space_gap.front();
198 AINFO <<
"max_gap: " << max_gap;
199 for (int i = 2; i < space_gap.size(); i += 2) {
200 double temp_gap = space_gap[i] - space_gap[i - 1];
201 if (temp_gap > max_gap) {
202 max_gap = temp_gap;
203 AINFO <<
"max_gap: " << max_gap;
204 }
205 }
206 max_gap = std::max(max_gap, left_lane_width - space_gap.back());
207 double obs_reference_point_kappa = std::fabs(reference_line_info.reference_line().GetReferencePoint(obs_s).kappa());
208 AINFO <<
"max_gap: " << max_gap <<
" obs_reference_point_kappa: " << obs_reference_point_kappa;
209 if (max_gap - ego_width > passby_min_gap + obs_reference_point_kappa * passby_kappa_ratio) {
210 lane_follow_enough_space = true;
211 } else {
212 AINFO <<
"lane_follow_enough_space: false, max_gap: " << max_gap <<
" ego_width: " << ego_width;
213 }
214
215 if (enable_lane_borrow || lane_follow_enough_space) {
216 return true;
217 } else {
218 AINFO <<
"enable_lane_borrow: " << enable_lane_borrow
219 << ", lane_follow_enough_space: " << lane_follow_enough_space;
220 return false;
221 }
222}
LaneBoundaryType::Type LeftBoundaryType(const LaneWaypoint &waypoint)
get left boundary type at a waypoint.
LaneBoundaryType::Type RightBoundaryType(const LaneWaypoint &waypoint)
get left boundary type at a waypoint.