Apollo 11.0
自动驾驶开放平台
bare_intersection_unprotected_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 <memory>
24
25#include "modules/planning/planning_base/proto/planning_config.pb.h"
26#include "cyber/common/log.h"
31
32namespace apollo {
33namespace planning {
34
36 std::shared_ptr<DependencyInjector> injector, const std::string& name) {
37 if (init_) {
38 return true;
39 }
40
41 if (!Scenario::Init(injector, name)) {
42 AERROR << "failed to init scenario " << name;
43 return false;
44 }
45
46 if (!Scenario::LoadConfig<ScenarioBareIntersectionUnprotectedConfig>(
47 &context_.scenario_config)) {
48 AERROR << "fail to get scenario specific config in" << name;
49 return false;
50 }
51 init_ = true;
52 return true;
53}
54
55/*
56 * read scenario specific configs and set in context_ for stages to read
57 */
58
60 const Scenario* const other_scenario, const Frame& frame) {
61 if (!frame.local_view().planning_command->has_lane_follow_command()) {
62 return false;
63 }
64 if (other_scenario == nullptr || frame.reference_line_info().empty()) {
65 return false;
66 }
67 const auto& reference_line_info = frame.reference_line_info().front();
68 const auto& first_encountered_overlaps =
69 reference_line_info.FirstEncounteredOverlaps();
70 hdmap::PathOverlap* pnc_junction_overlap = nullptr;
71 hdmap::PathOverlap* traffic_sign_overlap = nullptr;
72 // note: first_encountered_overlaps already sorted
73 if (first_encountered_overlaps.empty()) {
74 return false;
75 }
76
77 for (const auto& overlap : first_encountered_overlaps) {
78 if ((overlap.first == ReferenceLineInfo::SIGNAL ||
79 overlap.first == ReferenceLineInfo::STOP_SIGN ||
80 overlap.first == ReferenceLineInfo::YIELD_SIGN) &&
81 traffic_sign_overlap == nullptr) {
82 traffic_sign_overlap = const_cast<hdmap::PathOverlap*>(&overlap.second);
83 break;
84 } else if (overlap.first == ReferenceLineInfo::PNC_JUNCTION &&
85 pnc_junction_overlap == nullptr) {
86 pnc_junction_overlap = const_cast<hdmap::PathOverlap*>(&overlap.second);
87 }
88 }
89
90 if (traffic_sign_overlap && pnc_junction_overlap) {
91 static constexpr double kJunctionDelta = 10.0;
92 double s_diff = std::fabs(traffic_sign_overlap->start_s -
93 pnc_junction_overlap->start_s);
94 if (s_diff >= kJunctionDelta) {
95 if (pnc_junction_overlap->start_s > traffic_sign_overlap->start_s) {
96 pnc_junction_overlap = nullptr;
97 } else {
98 traffic_sign_overlap = nullptr;
99 }
100 }
101 }
102
103 if (traffic_sign_overlap || !pnc_junction_overlap) {
104 return false;
105 }
106
107 if (reference_line_info.GetIntersectionRightofWayStatus(
108 *pnc_junction_overlap)) {
109 return false;
110 }
111
112 const double adc_front_edge_s = reference_line_info.AdcSlBoundary().end_s();
113 const double adc_distance_to_pnc_junction =
114 pnc_junction_overlap->start_s - adc_front_edge_s;
115 ADEBUG << "adc_distance_to_pnc_junction[" << adc_distance_to_pnc_junction
116 << "] pnc_junction[" << pnc_junction_overlap->object_id
117 << "] pnc_junction_overlap_start_s[" << pnc_junction_overlap->start_s
118 << "]";
119
120 const bool bare_junction_scenario =
121 (adc_distance_to_pnc_junction > 0.0 &&
122 adc_distance_to_pnc_junction <=
123 context_.scenario_config
125
126 return bare_junction_scenario;
127}
128
130 // set to first_encountered pnc_junction
131 const auto& first_encountered_overlaps =
132 frame->reference_line_info().front().FirstEncounteredOverlaps();
133 for (const auto& overlap : first_encountered_overlaps) {
134 if (overlap.first == ReferenceLineInfo::PNC_JUNCTION) {
135 context_.current_pnc_junction_overlap_id = overlap.second.object_id;
136 ADEBUG << "Update PlanningContext with first_encountered pnc_junction["
137 << overlap.second.object_id << "] start_s["
138 << overlap.second.start_s << "]";
139 break;
140 }
141 }
142 return true;
143}
144
145} // namespace planning
146} // namespace apollo
bool Init(std::shared_ptr< DependencyInjector > injector, const std::string &name) override
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...
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
Planning module main class.
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
class register implement
Definition arena_queue.h:37
std::string object_id
Definition path.h:95
std::shared_ptr< PlanningCommand > planning_command
Definition local_view.h:48