Apollo 11.0
自动驾驶开放平台
pull_over_scenario.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2019 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
22
23#include "cyber/common/log.h"
28
29namespace apollo {
30namespace planning {
31
33
34bool PullOverScenario::Init(std::shared_ptr<DependencyInjector> injector,
35 const std::string& name) {
36 if (init_) {
37 return true;
38 }
39
40 if (!Scenario::Init(injector, name)) {
41 AERROR << "failed to init scenario" << Name();
42 return false;
43 }
44
45 if (!Scenario::LoadConfig<ScenarioPullOverConfig>(
46 &context_.scenario_config)) {
47 AERROR << "fail to get config of scenario" << Name();
48 return false;
49 }
50
51 init_ = true;
52 return true;
53}
54
55bool PullOverScenario::IsTransferable(const Scenario* const other_scenario,
56 const Frame& frame) {
57 if (!frame.local_view().planning_command->has_lane_follow_command()) {
58 return false;
59 }
60 if (other_scenario == nullptr || frame.reference_line_info().empty()) {
61 return false;
62 }
63 if (!FLAGS_enable_pull_over_at_destination) {
64 return false;
65 }
66 const auto routing_end = frame.local_view().end_lane_way_point;
67 if (nullptr == routing_end) {
68 return false;
69 }
70 common::SLPoint dest_sl;
71 const auto& reference_line_info = frame.reference_line_info().front();
72 const auto& reference_line = reference_line_info.reference_line();
73 reference_line.XYToSL(routing_end->pose(), &dest_sl);
74 if (!reference_line.IsOnLane(dest_sl)) {
75 return false;
76 }
77 const double adc_front_edge_s = reference_line_info.AdcSlBoundary().end_s();
78
79 const double adc_distance_to_dest = dest_sl.s() - adc_front_edge_s;
80 ADEBUG << "adc_distance_to_dest[" << adc_distance_to_dest
81 << "] destination_s[" << dest_sl.s() << "] adc_front_edge_s["
82 << adc_front_edge_s << "]";
83
84 bool pull_over_scenario =
85 (frame.reference_line_info().size() == 1 && // NO, while changing lane
86 adc_distance_to_dest >=
88 adc_distance_to_dest <=
90 // too close to destination + not found pull-over position
91 if (pull_over_scenario) {
92 if (adc_distance_to_dest <
94 pull_over_scenario = false;
95 }
96 }
97 // check around junction
98 auto first_encountered_overlaps =
99 frame.reference_line_info().front().FirstEncounteredOverlaps();
100 if (pull_over_scenario) {
101 static constexpr double kDistanceToAvoidJunction = 8.0; // meter
102 for (const auto& overlap : first_encountered_overlaps) {
103 if (overlap.first == ReferenceLineInfo::PNC_JUNCTION ||
104 overlap.first == ReferenceLineInfo::SIGNAL ||
105 overlap.first == ReferenceLineInfo::STOP_SIGN ||
106 overlap.first == ReferenceLineInfo::YIELD_SIGN) {
107 const double distance_to = overlap.second.start_s - dest_sl.s();
108 const double distance_passed = dest_sl.s() - overlap.second.end_s;
109 if ((distance_to > 0.0 && distance_to < kDistanceToAvoidJunction) ||
110 (distance_passed > 0.0 &&
111 distance_passed < kDistanceToAvoidJunction)) {
112 pull_over_scenario = false;
113 break;
114 }
115 }
116 }
117 }
118
119 // check rightmost driving lane along pull-over path
120 if (pull_over_scenario) {
121 double check_s = adc_front_edge_s;
122 static constexpr double kDistanceUnit = 5.0;
123 while (check_s < dest_sl.s()) {
124 check_s += kDistanceUnit;
125
126 std::vector<hdmap::LaneInfoConstPtr> lanes;
127 reference_line.GetLaneFromS(check_s, &lanes);
128 if (lanes.empty()) {
129 ADEBUG << "check_s[" << check_s << "] can't find a lane";
130 continue;
131 }
132 const hdmap::LaneInfoConstPtr lane = lanes[0];
133 const std::string lane_id = lane->lane().id().id();
134 ADEBUG << "check_s[" << check_s << "] lane[" << lane_id << "]";
135
136 // check neighbor lanes type: NONE/CITY_DRIVING/BIKING/SIDEWALK/PARKING
137 bool rightmost_driving_lane = true;
138 for (const auto& neighbor_lane_id :
139 lane->lane().right_neighbor_forward_lane_id()) {
140 const auto hdmap_ptr = HDMapUtil::BaseMapPtr();
141 CHECK_NOTNULL(hdmap_ptr);
142 const auto neighbor_lane = hdmap_ptr->GetLaneById(neighbor_lane_id);
143 if (neighbor_lane == nullptr) {
144 AWARN << "Failed to find neighbor lane[" << neighbor_lane_id.id()
145 << "]";
146 continue;
147 }
148 const auto& lane_type = neighbor_lane->lane().type();
149 if (lane_type == hdmap::Lane::CITY_DRIVING) {
150 AWARN << "lane[" << lane_id << "]'s right neighbor forward lane["
151 << neighbor_lane_id.id() << "] type["
152 << Lane_LaneType_Name(lane_type) << "] can't pull over";
153 rightmost_driving_lane = false;
154 break;
155 }
156 }
157 if (!rightmost_driving_lane) {
158 pull_over_scenario = false;
159 break;
160 }
161 }
162 }
163 return pull_over_scenario;
164}
165
167 injector_->planning_context()->mutable_planning_status()->clear_pull_over();
168 return true;
169}
170
172 auto* pull_over = injector_->planning_context()
173 ->mutable_planning_status()
174 ->mutable_pull_over();
175 pull_over->set_pull_over_type(PullOverStatus::PULL_OVER);
176 pull_over->set_plan_pull_over_path(true);
177 return true;
178}
179
180} // namespace planning
181} // namespace apollo
static const HDMap * BaseMapPtr()
Frame holds all data for one planning cycle.
Definition frame.h:62
const LocalView & local_view() const
Definition frame.h:163
const std::list< ReferenceLineInfo > & reference_line_info() const
Definition frame.cc:123
bool IsTransferable(const Scenario *other_scenario, const Frame &frame) override
Each scenario should define its own transfer condition, i.e., when it should allow to transfer from o...
bool Enter(Frame *frame) override
bool Init(std::shared_ptr< DependencyInjector > injector, const std::string &name) override
virtual bool Init(std::shared_ptr< DependencyInjector > injector, const std::string &name)
Definition scenario.cc:43
std::shared_ptr< DependencyInjector > injector_
Definition scenario.h:113
const std::string & Name() const
Definition scenario.h:98
Planning module main class.
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
#define AWARN
Definition log.h:43
std::shared_ptr< const LaneInfo > LaneInfoConstPtr
class register implement
Definition arena_queue.h:37
std::shared_ptr< routing::LaneWaypoint > end_lane_way_point
Definition local_view.h:49
std::shared_ptr< PlanningCommand > planning_command
Definition local_view.h:48
ScenarioPullOverConfig scenario_config
Definition context.h:29