Apollo 11.0
自动驾驶开放平台
stop_sign_unprotected_scenario.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 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 "modules/common_msgs/perception_msgs/perception_obstacle.pb.h"
24#include "modules/planning/planning_base/proto/planning_config.pb.h"
25#include "cyber/common/log.h"
33
34namespace apollo {
35namespace planning {
36
40
42 std::unordered_map<std::string, std::vector<std::string>>;
43
45 std::shared_ptr<DependencyInjector> injector, const std::string& name) {
46 if (!Scenario::Init(injector, name)) {
47 AERROR << "Failed to init scenario" << Name();
48 return false;
49 }
50
51 if (!Scenario::LoadConfig<ScenarioStopSignUnprotectedConfig>(
52 &context_.scenario_config)) {
53 AERROR << "Fail to get config of scenario " << Name();
54 return false;
55 }
56 return true;
57}
58
59/*
60 * get all the lanes associated/guarded by a stop sign
61 */
62int StopSignUnprotectedScenario::GetAssociatedLanes(
63 const StopSignInfo& stop_sign_info) {
64 context_.associated_lanes.clear();
65
66 std::vector<StopSignInfoConstPtr> associated_stop_signs;
68 &associated_stop_signs);
69
70 for (const auto stop_sign : associated_stop_signs) {
71 if (stop_sign == nullptr) {
72 continue;
73 }
74
75 const auto& associated_lane_ids = stop_sign->OverlapLaneIds();
76 for (const auto& lane_id : associated_lane_ids) {
77 const auto lane = HDMapUtil::BaseMap().GetLaneById(lane_id);
78 if (lane == nullptr) {
79 continue;
80 }
81 for (const auto& stop_sign_overlap : lane->stop_signs()) {
82 auto over_lap_info =
83 stop_sign_overlap->GetObjectOverlapInfo(stop_sign.get()->id());
84 if (over_lap_info != nullptr) {
85 context_.associated_lanes.push_back(
86 std::make_pair(lane, stop_sign_overlap));
87 ADEBUG << "stop_sign: " << stop_sign_info.id().id()
88 << "; associated_lane: " << lane_id.id()
89 << "; associated_stop_sign: " << stop_sign.get()->id().id();
90 }
91 }
92 }
93 }
94
95 return 0;
96}
97
99 const Scenario* const other_scenario, const Frame& frame) {
100 if (!frame.local_view().planning_command->has_lane_follow_command()) {
101 return false;
102 }
103 if (other_scenario == nullptr || frame.reference_line_info().empty()) {
104 return false;
105 }
106 const auto& reference_line_info = frame.reference_line_info().front();
107 const auto& first_encountered_overlaps =
108 reference_line_info.FirstEncounteredOverlaps();
109 // note: first_encountered_overlaps already sorted
110 hdmap::PathOverlap* stop_sign_overlap = nullptr;
111 for (const auto& overlap : first_encountered_overlaps) {
112 if (overlap.first == ReferenceLineInfo::SIGNAL ||
113 overlap.first == ReferenceLineInfo::YIELD_SIGN) {
114 return false;
115 } else if (overlap.first == ReferenceLineInfo::STOP_SIGN) {
116 stop_sign_overlap = const_cast<hdmap::PathOverlap*>(&overlap.second);
117 break;
118 }
119 }
120 if (stop_sign_overlap == nullptr) {
121 return false;
122 }
123 const double adc_front_edge_s = reference_line_info.AdcSlBoundary().end_s();
124 const double adc_distance_to_stop_sign =
125 stop_sign_overlap->start_s - adc_front_edge_s;
126 ADEBUG << "adc_distance_to_stop_sign[" << adc_distance_to_stop_sign
127 << "] stop_sign[" << stop_sign_overlap->object_id
128 << "] stop_sign_overlap_start_s[" << stop_sign_overlap->start_s << "]";
129 const bool stop_sign_scenario =
130 (adc_distance_to_stop_sign > 0.0 &&
131 adc_distance_to_stop_sign <=
133
134 return stop_sign_scenario;
135}
136
138 injector_->planning_context()
139 ->mutable_planning_status()
140 ->mutable_stop_sign()
141 ->Clear();
142 return true;
143}
144
146 const auto& reference_line_info = frame->reference_line_info().front();
147 std::string current_stop_sign_overlap_id;
148 const auto& overlaps = reference_line_info.FirstEncounteredOverlaps();
149 for (auto overlap : overlaps) {
150 if (overlap.first == ReferenceLineInfo::STOP_SIGN) {
151 current_stop_sign_overlap_id = overlap.second.object_id;
152 break;
153 }
154 }
155
156 if (current_stop_sign_overlap_id.empty()) {
157 injector_->planning_context()
158 ->mutable_planning_status()
159 ->mutable_stop_sign()
160 ->Clear();
161 AERROR << "Can not find stop sign overlap in refline";
162 return false;
163 }
164
165 const std::vector<hdmap::PathOverlap>& stop_sign_overlaps =
166 reference_line_info.reference_line().map_path().stop_sign_overlaps();
167 auto stop_sign_overlap_itr = std::find_if(
168 stop_sign_overlaps.begin(), stop_sign_overlaps.end(),
169 [&current_stop_sign_overlap_id](const hdmap::PathOverlap& overlap) {
170 return overlap.object_id == current_stop_sign_overlap_id;
171 });
172
173 if (stop_sign_overlap_itr != stop_sign_overlaps.end()) {
174 injector_->planning_context()
175 ->mutable_planning_status()
176 ->mutable_stop_sign()
177 ->set_current_stop_sign_overlap_id(current_stop_sign_overlap_id);
178 ADEBUG << "Update PlanningContext with first_encountered stop sign["
179 << current_stop_sign_overlap_id << "] start_s["
180 << stop_sign_overlap_itr->start_s << "]";
181 } else {
182 AERROR << "Can not find stop sign overlap " << current_stop_sign_overlap_id;
183 return false;
184 }
185
187 hdmap::MakeMapId(current_stop_sign_overlap_id));
188 if (!stop_sign) {
189 AERROR << "Could not find stop sign: " << current_stop_sign_overlap_id;
190 return false;
191 }
192 context_.current_stop_sign_overlap_id = current_stop_sign_overlap_id;
193 context_.watch_vehicles.clear();
194
195 GetAssociatedLanes(*stop_sign);
196 return true;
197}
198
199} // namespace planning
200} // namespace apollo
static const HDMap & BaseMap()
StopSignInfoConstPtr GetStopSignById(const Id &id) const
Definition hdmap.cc:58
LaneInfoConstPtr GetLaneById(const Id &id) const
Definition hdmap.cc:34
int GetStopSignAssociatedStopSigns(const Id &id, std::vector< StopSignInfoConstPtr > *stop_signs) const
get all other stop signs associated with a stop sign in the same junction
Definition hdmap.cc:229
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
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
bool Init(std::shared_ptr< DependencyInjector > injector, const std::string &name) override
bool IsTransferable(const Scenario *const other_scenario, const Frame &frame) override
Each scenario should define its own transfer condition, i.e., when it should allow to transfer from o...
Planning module main class.
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
apollo::hdmap::Id MakeMapId(const std::string &id)
create a Map ID given a string.
Definition hdmap_util.h:85
std::shared_ptr< const StopSignInfo > StopSignInfoConstPtr
std::unordered_map< std::string, std::vector< std::string > > StopSignLaneVehicles
class register implement
Definition arena_queue.h:37
optional string id
Definition map_id.proto:7
std::string object_id
Definition path.h:95
std::shared_ptr< PlanningCommand > planning_command
Definition local_view.h:48
std::vector< std::pair< hdmap::LaneInfoConstPtr, hdmap::OverlapInfoConstPtr > > associated_lanes
Definition context.h:42
std::unordered_map< std::string, std::vector< std::string > > watch_vehicles
Definition context.h:40
ScenarioStopSignUnprotectedConfig scenario_config
Definition context.h:35