Apollo 11.0
自动驾驶开放平台
scenario_manager.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
18
19#include <algorithm>
20#include <string>
21#include <vector>
22
27
28namespace apollo {
29namespace planning {
30
32
33bool ScenarioManager::Init(const std::shared_ptr<DependencyInjector>& injector,
34 const PlannerPublicRoadConfig& planner_config) {
35 if (init_) {
36 return true;
37 }
38 injector_ = injector;
39 for (int i = 0; i < planner_config.scenario_size(); i++) {
42 planner_config.scenario(i).type()));
43 ACHECK(scenario->Init(injector_, planner_config.scenario(i).name()))
44 << "Can not init scenario" << planner_config.scenario(i).name();
45 scenario_list_.push_back(scenario);
46 if (planner_config.scenario(i).name() == "LANE_FOLLOW") {
47 default_scenario_type_ = scenario;
48 }
49 }
50 AINFO << "Load scenario list:" << planner_config.DebugString();
51 current_scenario_ = default_scenario_type_;
52 init_ = true;
53 return true;
54}
55
57 Frame* frame) {
58 CHECK_NOTNULL(frame);
59 for (auto scenario : scenario_list_) {
60 if (current_scenario_.get() == scenario.get() &&
61 current_scenario_->GetStatus() ==
63 // The previous scenario has higher priority
64 return;
65 }
66 if (scenario->IsTransferable(current_scenario_.get(), *frame)) {
67 current_scenario_->Exit(frame);
68 AINFO << "switch scenario from " << current_scenario_->Name() << " to "
69 << scenario->Name();
70 current_scenario_ = scenario;
71 current_scenario_->Reset();
72 current_scenario_->Enter(frame);
73 return;
74 }
75 }
76}
77
79 if (current_scenario_) {
80 current_scenario_->Exit(frame);
81 }
82 AINFO << "Reset to default scenario:" << default_scenario_type_->Name();
83 default_scenario_type_->Reset();
84 current_scenario_ = default_scenario_type_;
85}
86} // namespace planning
87} // namespace apollo
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
bool Init(const std::shared_ptr< DependencyInjector > &injector, const PlannerPublicRoadConfig &planner_config)
void Update(const common::TrajectoryPoint &ego_point, Frame *frame)
Planning module main class.
#define ACHECK(cond)
Definition log.h:80
#define AINFO
Definition log.h:42
class register implement
Definition arena_queue.h:37