Apollo 10.0
自动驾驶开放平台
apollo::planning::Scenario类 参考abstract

#include <scenario.h>

类 apollo::planning::Scenario 继承关系图:
apollo::planning::Scenario 的协作图:

Public 成员函数

 Scenario ()
 
virtual ~Scenario ()=default
 
virtual bool Init (std::shared_ptr< DependencyInjector > injector, const std::string &name)
 
virtual ScenarioContextGetContext ()=0
 Get the scenario context.
 
virtual bool IsTransferable (const Scenario *other_scenario, const Frame &frame)
 Each scenario should define its own transfer condition, i.e., when it should allow to transfer from other scenario to itself.
 
virtual ScenarioResult Process (const common::TrajectoryPoint &planning_init_point, Frame *frame)
 
virtual bool Exit (Frame *frame)
 
virtual bool Enter (Frame *frame)
 
std::shared_ptr< StageCreateStage (const StagePipeline &stage_pipeline)
 Each scenario should define its own stages object's creation scenario will call stage's Stage::Process function following a configured order, The return value of Stage::Process function determines the transition from one stage to another.
 
const ScenarioStatusTypeGetStatus () const
 
const std::string GetStage () const
 
const std::string & GetMsg () const
 
const std::string & Name () const
 
void Reset ()
 Reset the scenario, used before entering the scenario.
 

Protected 成员函数

template<typename T >
bool LoadConfig (T *config)
 

Protected 属性

ScenarioResult scenario_result_
 
std::shared_ptr< Stagecurrent_stage_
 
std::unordered_map< std::string, const StagePipeline * > stage_pipeline_map_
 
std::string msg_
 
std::shared_ptr< DependencyInjectorinjector_
 
std::string config_path_
 
std::string config_dir_
 
std::string name_
 
ScenarioPipeline scenario_pipeline_config_
 

详细描述

在文件 scenario.h52 行定义.

构造及析构函数说明

◆ Scenario()

apollo::planning::Scenario::Scenario ( )

在文件 scenario.cc34 行定义.

36 current_stage_(nullptr),
37 msg_(""),
38 injector_(nullptr),
39 config_path_(""),
40 config_dir_(""),
41 name_("") {}
std::shared_ptr< Stage > current_stage_
Definition scenario.h:110
ScenarioResult scenario_result_
Definition scenario.h:109
std::shared_ptr< DependencyInjector > injector_
Definition scenario.h:113

◆ ~Scenario()

virtual apollo::planning::Scenario::~Scenario ( )
virtualdefault

成员函数说明

◆ CreateStage()

std::shared_ptr< Stage > apollo::planning::Scenario::CreateStage ( const StagePipeline stage_pipeline)

Each scenario should define its own stages object's creation scenario will call stage's Stage::Process function following a configured order, The return value of Stage::Process function determines the transition from one stage to another.

在文件 scenario.cc155 行定义.

156 {
157 auto stage_ptr =
159 ->CreateInstance<Stage>(
160 ConfigUtil::GetFullPlanningClassName(stage_pipeline.type()));
161 if (nullptr == stage_ptr ||
162 !stage_ptr->Init(stage_pipeline, injector_, config_dir_, GetContext())) {
163 AERROR << "Create stage " << stage_pipeline.name() << " of " << name_
164 << " failed!";
165 return nullptr;
166 }
167 return stage_ptr;
168}
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...
virtual ScenarioContext * GetContext()=0
Get the scenario context.
#define AERROR
Definition log.h:44

◆ Enter()

◆ Exit()

◆ GetContext()

◆ GetMsg()

const std::string & apollo::planning::Scenario::GetMsg ( ) const
inline

在文件 scenario.h96 行定义.

96{ return msg_; }

◆ GetStage()

const std::string apollo::planning::Scenario::GetStage ( ) const

在文件 scenario.cc170 行定义.

170 {
171 return current_stage_ ? current_stage_->Name() : "";
172}

◆ GetStatus()

const ScenarioStatusType & apollo::planning::Scenario::GetStatus ( ) const
inline

在文件 scenario.h90 行定义.

90 {
92 }
const ScenarioStatusType & GetScenarioStatus() const
Get the scenario status.

◆ Init()

bool apollo::planning::Scenario::Init ( std::shared_ptr< DependencyInjector injector,
const std::string &  name 
)
virtual

apollo::planning::BareIntersectionUnprotectedScenario, apollo::planning::EmergencyPullOverScenario, apollo::planning::EmergencyStopScenario, apollo::planning::ParkAndGoScenario, apollo::planning::PullOverScenario, apollo::planning::StopSignUnprotectedScenario, apollo::planning::TrafficLightProtectedScenario, apollo::planning::TrafficLightUnprotectedLeftTurnScenario, apollo::planning::TrafficLightUnprotectedRightTurnScenario, apollo::planning::ValetParkingScenario , 以及 apollo::planning::YieldSignScenario 重载.

在文件 scenario.cc43 行定义.

44 {
45 name_ = name;
46 injector_ = injector;
47 // set scenario_type in PlanningContext
48 auto* scenario = injector_->planning_context()
49 ->mutable_planning_status()
50 ->mutable_scenario();
51 scenario->Clear();
52 scenario->set_scenario_type(name_);
53
54 // Generate the default config path.
55 int status;
56 // Get the name of this class.
57 std::string class_name =
58 abi::__cxa_demangle(typeid(*this).name(), 0, 0, &status);
59
61 ->GetPluginClassHomePath<Scenario>(class_name);
62 config_dir_ += "/conf";
63 AINFO << "config_dir : " << config_dir_;
64 // Generate the default task config path from PluginManager.
66 ->GetPluginConfPath<Scenario>(class_name,
67 "conf/scenario_conf.pb.txt");
68
69 // Load the pipeline config.
70 std::string pipeline_config_path =
72 ->GetPluginConfPath<Scenario>(class_name, "conf/pipeline.pb.txt");
73 AINFO << "Load config path:" << pipeline_config_path;
74 // Load the pipeline of scenario.
75 if (!apollo::cyber::common::GetProtoFromFile(pipeline_config_path,
77 AERROR << "Load pipeline of " << name_ << " failed!";
78 return false;
79 }
80 for (const auto& stage : scenario_pipeline_config_.stage()) {
81 stage_pipeline_map_[stage.name()] = &stage;
82 }
83 return true;
84}
std::string GetPluginConfPath(const std::string &class_name, const std::string &conf_name)
get plugin configuration file location
std::string GetPluginClassHomePath(const std::string &class_name)
@bried get plugin description file location that class belongs to
std::unordered_map< std::string, const StagePipeline * > stage_pipeline_map_
Definition scenario.h:111
ScenarioPipeline scenario_pipeline_config_
Definition scenario.h:118
#define AINFO
Definition log.h:42
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
Definition file.cc:132

◆ IsTransferable()

◆ LoadConfig()

template<typename T >
bool apollo::planning::Scenario::LoadConfig ( T *  config)
protected

在文件 scenario.h122 行定义.

122 {
123 return apollo::cyber::common::LoadConfig<T>(config_path_, config);
124}

◆ Name()

const std::string & apollo::planning::Scenario::Name ( ) const
inline

在文件 scenario.h98 行定义.

98{ return name_; }

◆ Process()

ScenarioResult apollo::planning::Scenario::Process ( const common::TrajectoryPoint planning_init_point,
Frame frame 
)
virtual

apollo::planning::EmergencyStopScenario 重载.

在文件 scenario.cc86 行定义.

87 {
88 if (current_stage_ == nullptr) {
91 if (nullptr == current_stage_) {
92 AERROR << "Create stage " << scenario_pipeline_config_.stage(0).name()
93 << " failed!";
95 return scenario_result_;
96 }
97 AINFO << "Create stage " << current_stage_->Name();
98 }
99 if (current_stage_->Name().empty()) {
101 return scenario_result_;
102 }
103 auto ret = current_stage_->Process(planning_init_point, frame);
105 switch (ret.GetStageStatus()) {
107 AERROR << "Stage '" << current_stage_->Name() << "' returns error";
109 break;
110 }
113 break;
114 }
116 auto next_stage = current_stage_->NextStage();
117 if (next_stage != current_stage_->Name()) {
118 AINFO << "switch stage from " << current_stage_->Name() << " to "
119 << next_stage;
120 if (next_stage.empty()) {
122 return scenario_result_;
123 }
124 if (stage_pipeline_map_.find(next_stage) == stage_pipeline_map_.end()) {
125 AERROR << "Failed to find config for stage: " << next_stage;
128 return scenario_result_;
129 }
131 if (current_stage_ == nullptr) {
132 AWARN << "Current stage is a null pointer.";
135 return scenario_result_;
136 }
137 }
138 if (current_stage_ != nullptr && !current_stage_->Name().empty()) {
141 } else {
143 }
144 break;
145 }
146 default: {
147 AWARN << "Unexpected Stage return value: "
148 << static_cast<int>(ret.GetStageStatus());
150 }
151 }
152 return scenario_result_;
153}
const ScenarioResult & SetScenarioStatus(const ScenarioStatusType &scenario_status)
Set the scenario status.
const ScenarioResult & SetStageResult(const StageResult &stage_result)
Set the stage status.
std::shared_ptr< Stage > CreateStage(const StagePipeline &stage_pipeline)
Each scenario should define its own stages object's creation scenario will call stage's Stage::Proces...
Definition scenario.cc:155
#define AWARN
Definition log.h:43

◆ Reset()

void apollo::planning::Scenario::Reset ( )

Reset the scenario, used before entering the scenario.

在文件 scenario.cc174 行定义.

174 {
176 current_stage_ = nullptr;
177}

类成员变量说明

◆ config_dir_

std::string apollo::planning::Scenario::config_dir_
protected

在文件 scenario.h116 行定义.

◆ config_path_

std::string apollo::planning::Scenario::config_path_
protected

在文件 scenario.h115 行定义.

◆ current_stage_

std::shared_ptr<Stage> apollo::planning::Scenario::current_stage_
protected

在文件 scenario.h110 行定义.

◆ injector_

std::shared_ptr<DependencyInjector> apollo::planning::Scenario::injector_
protected

在文件 scenario.h113 行定义.

◆ msg_

std::string apollo::planning::Scenario::msg_
protected

在文件 scenario.h112 行定义.

◆ name_

std::string apollo::planning::Scenario::name_
protected

在文件 scenario.h117 行定义.

◆ scenario_pipeline_config_

ScenarioPipeline apollo::planning::Scenario::scenario_pipeline_config_
protected

在文件 scenario.h118 行定义.

◆ scenario_result_

ScenarioResult apollo::planning::Scenario::scenario_result_
protected

在文件 scenario.h109 行定义.

◆ stage_pipeline_map_

std::unordered_map<std::string, const StagePipeline*> apollo::planning::Scenario::stage_pipeline_map_
protected

在文件 scenario.h111 行定义.


该类的文档由以下文件生成: