Apollo  6.0
Open source self driving car software
scenario_manager.h
Go to the documentation of this file.
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 
17 #pragma once
18 
19 #include <memory>
20 #include <unordered_map>
21 
24 #include "modules/planning/proto/planning_config.pb.h"
26 
27 namespace apollo {
28 namespace planning {
29 namespace scenario {
30 
31 class ScenarioManager final {
32  public:
33  ScenarioManager() = delete;
34 
35  explicit ScenarioManager(const std::shared_ptr<DependencyInjector>& injector);
36 
37  bool Init(const PlanningConfig& planning_config);
38 
39  Scenario* mutable_scenario() { return current_scenario_.get(); }
40 
41  DependencyInjector* injector() { return injector_.get(); }
42 
43  void Update(const common::TrajectoryPoint& ego_point, const Frame& frame);
44 
45  private:
46  void Observe(const Frame& frame);
47 
48  std::unique_ptr<Scenario> CreateScenario(
49  ScenarioConfig::ScenarioType scenario_type);
50 
51  void RegisterScenarios();
52 
53  ScenarioConfig::ScenarioType SelectBareIntersectionScenario(
54  const Frame& frame, const hdmap::PathOverlap& pnc_junction_overlap);
55 
56  ScenarioConfig::ScenarioType SelectPullOverScenario(const Frame& frame);
57 
58  ScenarioConfig::ScenarioType SelectPadMsgScenario(const Frame& frame);
59 
60  ScenarioConfig::ScenarioType SelectIntersectionScenario(const Frame& frame);
61 
62  ScenarioConfig::ScenarioType SelectStopSignScenario(
63  const Frame& frame, const hdmap::PathOverlap& stop_sign_overlap);
64 
65  ScenarioConfig::ScenarioType SelectTrafficLightScenario(
66  const Frame& frame, const hdmap::PathOverlap& traffic_light_overlap);
67 
68  ScenarioConfig::ScenarioType SelectValetParkingScenario(const Frame& frame);
69 
70  ScenarioConfig::ScenarioType SelectYieldSignScenario(
71  const Frame& frame, const hdmap::PathOverlap& yield_sign_overlap);
72 
73  ScenarioConfig::ScenarioType SelectParkAndGoScenario(const Frame& frame);
74 
75  void ScenarioDispatch(const Frame& frame);
76  ScenarioConfig::ScenarioType ScenarioDispatchLearning();
77  ScenarioConfig::ScenarioType ScenarioDispatchNonLearning(const Frame& frame);
78 
79  bool IsBareIntersectionScenario(
80  const ScenarioConfig::ScenarioType& scenario_type);
81  bool IsStopSignScenario(const ScenarioConfig::ScenarioType& scenario_type);
82  bool IsTrafficLightScenario(
83  const ScenarioConfig::ScenarioType& scenario_type);
84  bool IsYieldSignScenario(const ScenarioConfig::ScenarioType& scenario_type);
85 
86  void UpdatePlanningContext(const Frame& frame,
87  const ScenarioConfig::ScenarioType& scenario_type);
88 
89  void UpdatePlanningContextBareIntersectionScenario(
90  const Frame& frame, const ScenarioConfig::ScenarioType& scenario_type);
91 
92  void UpdatePlanningContextEmergencyStopcenario(
93  const Frame& frame, const ScenarioConfig::ScenarioType& scenario_type);
94 
95  void UpdatePlanningContextPullOverScenario(
96  const Frame& frame, const ScenarioConfig::ScenarioType& scenario_type);
97 
98  void UpdatePlanningContextStopSignScenario(
99  const Frame& frame, const ScenarioConfig::ScenarioType& scenario_type);
100 
101  void UpdatePlanningContextTrafficLightScenario(
102  const Frame& frame, const ScenarioConfig::ScenarioType& scenario_type);
103 
104  void UpdatePlanningContextYieldSignScenario(
105  const Frame& frame, const ScenarioConfig::ScenarioType& scenario_type);
106 
107  private:
108  std::shared_ptr<DependencyInjector> injector_;
109  PlanningConfig planning_config_;
110  std::unordered_map<ScenarioConfig::ScenarioType, ScenarioConfig,
111  std::hash<int>>
112  config_map_;
113  std::unique_ptr<Scenario> current_scenario_;
114  ScenarioConfig::ScenarioType default_scenario_type_;
115  ScenarioContext scenario_context_;
117  std::hash<int>>
118  first_encountered_overlap_map_;
119 };
120 
121 } // namespace scenario
122 } // namespace planning
123 } // namespace apollo
Definition: path.h:91
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Planning module main class. It processes GPS and IMU as input, to generate planning info...
Frame holds all data for one planning cycle.
Definition: frame.h:61
Definition: dependency_injector.h:29
DependencyInjector * injector()
Definition: scenario_manager.h:41
Scenario * mutable_scenario()
Definition: scenario_manager.h:39
void Update(const common::TrajectoryPoint &ego_point, const Frame &frame)
Definition: scenario_manager.h:31
bool Init(const PlanningConfig &planning_config)
Definition: scenario.h:41
OverlapType
Definition: reference_line_info.h:222