Apollo 11.0
自动驾驶开放平台
yield_sign_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
21#include <string>
22
24
25#include "modules/common_msgs/perception_msgs/perception_obstacle.pb.h"
26#include "modules/planning/planning_base/proto/planning_config.pb.h"
27#include "cyber/common/log.h"
33
34namespace apollo {
35namespace planning {
36
38
40 std::unordered_map<std::string, std::vector<std::string>>;
41
42bool YieldSignScenario::Init(std::shared_ptr<DependencyInjector> injector,
43 const std::string& name) {
44 if (!Scenario::Init(injector, name)) {
45 AERROR << "failed to init scenario" << Name();
46 return false;
47 }
48
49 if (!Scenario::LoadConfig<ScenarioYieldSignConfig>(
50 &context_.scenario_config)) {
51 AERROR << "fail to get config of scenario" << Name();
52 return false;
53 }
54 return true;
55}
56
58 const Frame& frame) {
59 if (!frame.local_view().planning_command->has_lane_follow_command()) {
60 return false;
61 }
62 if (other_scenario == nullptr || frame.reference_line_info().empty()) {
63 return false;
64 }
65 const auto& reference_line_info = frame.reference_line_info().front();
66 const auto& first_encountered_overlaps =
67 reference_line_info.FirstEncounteredOverlaps();
68 hdmap::PathOverlap* yield_sign_overlap = nullptr;
69 for (const auto& overlap : first_encountered_overlaps) {
70 if (overlap.first == ReferenceLineInfo::SIGNAL ||
71 overlap.first == ReferenceLineInfo::STOP_SIGN) {
72 return false;
73 } else if (overlap.first == ReferenceLineInfo::YIELD_SIGN) {
74 yield_sign_overlap = const_cast<hdmap::PathOverlap*>(&overlap.second);
75 break;
76 }
77 }
78 if (yield_sign_overlap == nullptr) {
79 return false;
80 }
81 const double adc_front_edge_s = reference_line_info.AdcSlBoundary().end_s();
82 const double adc_distance_to_yield_sign =
83 yield_sign_overlap->start_s - adc_front_edge_s;
84 const bool yield_sign_scenario =
85 (adc_distance_to_yield_sign > 0.0 &&
86 adc_distance_to_yield_sign <=
88 return yield_sign_scenario;
89}
90
92 injector_->planning_context()
93 ->mutable_planning_status()
94 ->mutable_yield_sign()
95 ->Clear();
96 return true;
97}
98
100 // get first_encountered yield_sign
101 const auto& reference_line_info = frame->reference_line_info().front();
102 std::string current_yield_sign_overlap_id;
103 const auto& overlaps = reference_line_info.FirstEncounteredOverlaps();
104 for (auto overlap : overlaps) {
105 if (overlap.first == ReferenceLineInfo::YIELD_SIGN) {
106 current_yield_sign_overlap_id = overlap.second.object_id;
107 break;
108 }
109 }
110
111 if (current_yield_sign_overlap_id.empty()) {
112 injector_->planning_context()
113 ->mutable_planning_status()
114 ->mutable_yield_sign()
115 ->Clear();
116 AERROR << "Can not find yield sign overlap in reference line!";
117 return false;
118 }
119
120 // find all the yield_sign at/within the same location/group
121 const std::vector<hdmap::PathOverlap>& yield_sign_overlaps =
122 reference_line_info.reference_line().map_path().yield_sign_overlaps();
123 auto yield_sign_overlap_itr = std::find_if(
124 yield_sign_overlaps.begin(), yield_sign_overlaps.end(),
125 [&current_yield_sign_overlap_id](const hdmap::PathOverlap& overlap) {
126 return overlap.object_id == current_yield_sign_overlap_id;
127 });
128 if (yield_sign_overlap_itr == yield_sign_overlaps.end()) {
129 injector_->planning_context()
130 ->mutable_planning_status()
131 ->mutable_yield_sign()
132 ->Clear();
133 AERROR << "Can not find yield sign overlap "
134 << current_yield_sign_overlap_id;
135 return false;
136 }
137
138 static constexpr double kTrafficLightGroupingMaxDist = 2.0; // unit: m
139 const double current_yield_sign_overlap_start_s =
140 yield_sign_overlap_itr->start_s;
141 context_.current_yield_sign_overlap_ids.clear();
142 for (const auto& yield_sign_overlap : yield_sign_overlaps) {
143 const double dist =
144 yield_sign_overlap.start_s - current_yield_sign_overlap_start_s;
145 if (fabs(dist) <= kTrafficLightGroupingMaxDist) {
146 injector_->planning_context()
147 ->mutable_planning_status()
148 ->mutable_yield_sign()
149 ->add_current_yield_sign_overlap_id(yield_sign_overlap.object_id);
150 ADEBUG << "Update PlanningContext with first_encountered yield_sign["
151 << yield_sign_overlap.object_id << "] start_s["
152 << yield_sign_overlap.start_s << "]";
153 context_.current_yield_sign_overlap_ids.push_back(
154 yield_sign_overlap.object_id);
155 }
156 }
157 return true;
158}
159
160} // namespace planning
161} // namespace apollo
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 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...
bool Init(std::shared_ptr< DependencyInjector > injector, const std::string &name) override
Planning module main class.
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
std::unordered_map< std::string, std::vector< std::string > > StopSignLaneVehicles
class register implement
Definition arena_queue.h:37
std::shared_ptr< PlanningCommand > planning_command
Definition local_view.h:48
std::vector< std::string > current_yield_sign_overlap_ids
ScenarioYieldSignConfig scenario_config