Apollo 11.0
自动驾驶开放平台
traffic_decider.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 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 <limits>
24#include <memory>
25
30namespace apollo {
31namespace planning {
33
34bool TrafficDecider::Init(const std::shared_ptr<DependencyInjector> &injector) {
35 if (init_) return true;
36 // Load the pipeline config.
37 AINFO << "Load config path:" << FLAGS_traffic_rule_config_filename;
38 // Load the pipeline of scenario.
39 if (!apollo::cyber::common::LoadConfig(FLAGS_traffic_rule_config_filename,
40 &rule_pipeline_)) {
41 AERROR << "Load pipeline of Traffic decider"
42 << " failed!";
43 return false;
44 }
45 //-----------------------------------------------
46 for (int i = 0; i < rule_pipeline_.rule_size(); i++) {
47 auto rule =
50 rule_pipeline_.rule(i).type()));
51 if (!rule) {
52 AERROR << "Init of Traffic rule" << rule_pipeline_.rule(i).name()
53 << " failed!";
54 return false;
55 }
56 rule->Init(rule_pipeline_.rule(i).name(), injector);
57 rule_list_.push_back(rule);
58 }
59
60 init_ = true;
61 return true;
62}
63
64void TrafficDecider::BuildPlanningTarget(
65 ReferenceLineInfo *reference_line_info) {
66 double min_s = std::numeric_limits<double>::infinity();
67 StopPoint stop_point;
68 for (const auto *obstacle :
69 reference_line_info->path_decision()->obstacles().Items()) {
70 if (obstacle->IsVirtual() && obstacle->HasLongitudinalDecision() &&
71 obstacle->LongitudinalDecision().has_stop() &&
72 obstacle->PerceptionSLBoundary().start_s() < min_s) {
73 min_s = obstacle->PerceptionSLBoundary().start_s();
74 const auto &stop_code =
75 obstacle->LongitudinalDecision().stop().reason_code();
76 if (stop_code == StopReasonCode::STOP_REASON_DESTINATION ||
77 stop_code == StopReasonCode::STOP_REASON_CROSSWALK ||
78 stop_code == StopReasonCode::STOP_REASON_STOP_SIGN ||
79 stop_code == StopReasonCode::STOP_REASON_YIELD_SIGN ||
80 stop_code == StopReasonCode::STOP_REASON_CREEPER ||
81 stop_code == StopReasonCode::STOP_REASON_REFERENCE_END ||
82 stop_code == StopReasonCode::STOP_REASON_SIGNAL) {
83 stop_point.set_type(StopPoint::HARD);
84 ADEBUG << "Hard stop at: " << min_s
85 << "REASON: " << StopReasonCode_Name(stop_code);
86 } else if (stop_code == StopReasonCode::STOP_REASON_YELLOW_SIGNAL) {
87 stop_point.set_type(StopPoint::SOFT);
88 ADEBUG << "Soft stop at: " << min_s << " STOP_REASON_YELLOW_SIGNAL";
89 } else {
90 ADEBUG << "No planning target found at reference line.";
91 }
92 }
93 }
94 if (min_s != std::numeric_limits<double>::infinity()) {
95 const auto &vehicle_config =
96 common::VehicleConfigHelper::Instance()->GetConfig();
97 double front_edge_to_center =
98 vehicle_config.vehicle_param().front_edge_to_center();
99 stop_point.set_s(min_s - front_edge_to_center +
100 FLAGS_virtual_stop_wall_length / 2.0);
101 reference_line_info->SetLatticeStopPoint(stop_point);
102 }
103}
104
106 ReferenceLineInfo *reference_line_info) {
107 CHECK_NOTNULL(frame);
108 CHECK_NOTNULL(reference_line_info);
109
110 for (const auto &rule : rule_list_) {
111 if (!rule) {
112 AERROR << "Could not find rule ";
113 continue;
114 }
115 rule->Reset();
116 rule->ApplyRule(frame, reference_line_info);
117 ADEBUG << "Applied rule " << rule->Getname();
118 }
119
120 BuildPlanningTarget(reference_line_info);
121 return Status::OK();
122}
123
124} // namespace planning
125} // namespace apollo
A general class to denote the return status of an API call.
Definition status.h:43
static Status OK()
generate a success status.
Definition status.h:60
static PluginManager * Instance()
get singleton instance of PluginManager
std::shared_ptr< Base > CreateInstance(const std::string &derived_class)
create plugin instance of derived class based on Base
static std::string GetFullPlanningClassName(const std::string &class_name)
Given the class name of planning module, combine the namespace "apollo::planning::" with it to create...
Frame holds all data for one planning cycle.
Definition frame.h:62
ReferenceLineInfo holds all data for one reference line.
void SetLatticeStopPoint(const StopPoint &stop_point)
apollo::common::Status Execute(Frame *frame, ReferenceLineInfo *reference_line_info)
bool Init(const std::shared_ptr< DependencyInjector > &injector)
Planning module main class.
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
bool LoadConfig(const std::string &relative_path, T *config)
Definition file.h:265
class register implement
Definition arena_queue.h:37