Apollo  6.0
Open source self driving car software
scenario.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 
21 #pragma once
22 
23 #include <memory>
24 #include <string>
25 #include <unordered_map>
26 
31 #include "modules/planning/proto/planning_config.pb.h"
34 
35 namespace apollo {
36 namespace planning {
37 namespace scenario {
38 
39 struct ScenarioContext {};
40 
41 class Scenario {
42  public:
44  STATUS_UNKNOWN = 0,
45  STATUS_PROCESSING = 1,
46  STATUS_DONE = 2,
47  };
48 
49  Scenario(const ScenarioConfig& config, const ScenarioContext* context,
50  const std::shared_ptr<DependencyInjector>& injector);
51 
52  static bool LoadConfig(const std::string& config_file,
53  ScenarioConfig* config);
54 
55  virtual ~Scenario() = default;
56 
57  ScenarioConfig::ScenarioType scenario_type() const {
58  return config_.scenario_type();
59  }
60 
67  virtual std::unique_ptr<Stage> CreateStage(
68  const ScenarioConfig::StageConfig& stage_config,
69  const std::shared_ptr<DependencyInjector>& injector) = 0;
70 
71  // Each scenario should define its own transfer condition, i.e., when it
72  // should allow to transfer from other scenario to itself.
73  virtual bool IsTransferable(const Scenario& other_scenario,
74  const Frame& frame) {
75  return true;
76  }
77 
78  virtual ScenarioStatus Process(
79  const common::TrajectoryPoint& planning_init_point, Frame* frame);
80 
81  const ScenarioStatus& GetStatus() const { return scenario_status_; }
82 
83  const ScenarioConfig::StageType GetStage() const {
84  return current_stage_ ? current_stage_->stage_type()
85  : ScenarioConfig::NO_STAGE;
86  }
87 
88  virtual void Init();
89 
90  const std::string& Name() const;
91  const std::string& GetMsg() const { return msg_; }
92 
93  protected:
94  ScenarioStatus scenario_status_ = STATUS_UNKNOWN;
95  std::unique_ptr<Stage> current_stage_;
96  ScenarioConfig config_;
97  std::unordered_map<ScenarioConfig::StageType,
98  const ScenarioConfig::StageConfig*, std::hash<int>>
100  const ScenarioContext* scenario_context_ = nullptr;
101  std::string name_;
102  std::string msg_; // debug msg
103  std::shared_ptr<DependencyInjector> injector_;
104 };
105 
106 } // namespace scenario
107 } // namespace planning
108 } // namespace apollo
const ScenarioStatus & GetStatus() const
Definition: scenario.h:81
std::string msg_
Definition: scenario.h:102
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...
ScenarioStatus
Definition: scenario.h:43
std::unordered_map< ScenarioConfig::StageType, const ScenarioConfig::StageConfig *, std::hash< int > > stage_config_map_
Definition: scenario.h:99
Frame holds all data for one planning cycle.
Definition: frame.h:61
const std::string & GetMsg() const
Definition: scenario.h:91
Defines the Factory class.
std::shared_ptr< DependencyInjector > injector_
Definition: scenario.h:103
bool Init(const char *binary_name)
ScenarioConfig::ScenarioType scenario_type() const
Definition: scenario.h:57
const ScenarioConfig::StageType GetStage() const
Definition: scenario.h:83
virtual bool IsTransferable(const Scenario &other_scenario, const Frame &frame)
Definition: scenario.h:73
Definition: scenario.h:41
std::unique_ptr< Stage > current_stage_
Definition: scenario.h:95
std::string name_
Definition: scenario.h:101
ScenarioConfig config_
Definition: scenario.h:96