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

#include <stage.h>

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

Public 成员函数

 Stage ()
 
virtual bool Init (const StagePipeline &config, const std::shared_ptr< DependencyInjector > &injector, const std::string &config_dir, void *context)
 
virtual ~Stage ()=default
 
virtual StageResult Process (const common::TrajectoryPoint &planning_init_point, Frame *frame)=0
 Each stage does its business logic inside Process function.
 
const std::string & Name () const
 
template<typename T >
T * GetContextAs () const
 
const std::string & NextStage () const
 

Protected 成员函数

StageResult ExecuteTaskOnReferenceLine (const common::TrajectoryPoint &planning_start_point, Frame *frame)
 
StageResult ExecuteTaskOnReferenceLineForOnlineLearning (const common::TrajectoryPoint &planning_start_point, Frame *frame)
 
StageResult ExecuteTaskOnOpenSpace (Frame *frame)
 
virtual StageResult FinishScenario ()
 
void RecordDebugInfo (ReferenceLineInfo *reference_line_info, const std::string &name, const double time_diff_ms)
 

Protected 属性

std::vector< std::shared_ptr< Task > > task_list_
 
std::shared_ptr< Taskfallback_task_
 
std::string next_stage_
 
void * context_
 
std::shared_ptr< DependencyInjectorinjector_
 
StagePipeline pipeline_config_
 

详细描述

在文件 stage.h46 行定义.

构造及析构函数说明

◆ Stage()

apollo::planning::Stage::Stage ( )

在文件 stage.cc40 行定义.

41 : next_stage_(""), context_(nullptr), injector_(nullptr), name_("") {}
std::string next_stage_
Definition stage.h:89
std::shared_ptr< DependencyInjector > injector_
Definition stage.h:91

◆ ~Stage()

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

成员函数说明

◆ ExecuteTaskOnOpenSpace()

StageResult apollo::planning::Stage::ExecuteTaskOnOpenSpace ( Frame frame)
protected

在文件 stage.cc206 行定义.

206 {
207 auto ret = common::Status::OK();
208 StageResult stage_result;
209 for (auto task : task_list_) {
210 const double start_timestamp = Clock::NowInSeconds();
211
212 ret = task->Execute(frame);
213
214 if (!ret.ok()) {
215 stage_result.SetTaskStatus(ret);
216 AERROR << "Failed to run tasks[" << task->Name()
217 << "], Error message: " << ret.error_message();
218 const double end_timestamp = Clock::NowInSeconds();
219 const double time_diff_ms = (end_timestamp - start_timestamp) * 1000;
220 AINFO << "Planning Perf: task name [" << task->Name() << "], "
221 << time_diff_ms << " ms.";
222 return stage_result;
223 }
224
225 const double end_timestamp = Clock::NowInSeconds();
226 const double time_diff_ms = (end_timestamp - start_timestamp) * 1000;
227 AINFO << "Planning Perf: task name [" << task->Name() << "], "
228 << time_diff_ms << " ms.";
229 }
230
231 if (frame->open_space_info().fallback_flag() ||
232 frame->open_space_info().stop_flag()) {
233 auto& trajectory = frame->open_space_info().fallback_trajectory().first;
234 auto& gear = frame->open_space_info().fallback_trajectory().second;
235 PublishableTrajectory publishable_trajectory(Clock::NowInSeconds(),
236 trajectory);
237 auto publishable_traj_and_gear =
238 std::make_pair(std::move(publishable_trajectory), gear);
239
240 *(frame->mutable_open_space_info()->mutable_publishable_trajectory_data()) =
241 std::move(publishable_traj_and_gear);
242 } else {
243 auto& trajectory =
244 frame->open_space_info().chosen_partitioned_trajectory().first;
245 auto& gear =
246 frame->open_space_info().chosen_partitioned_trajectory().second;
247 PublishableTrajectory publishable_trajectory(Clock::NowInSeconds(),
248 trajectory);
249 auto publishable_traj_and_gear =
250 std::make_pair(std::move(publishable_trajectory), gear);
251
252 *(frame->mutable_open_space_info()->mutable_publishable_trajectory_data()) =
253 std::move(publishable_traj_and_gear);
254 }
255 return stage_result;
256}
static Status OK()
generate a success status.
Definition status.h:60
static double NowInSeconds()
gets the current time in second.
Definition clock.cc:56
std::vector< std::shared_ptr< Task > > task_list_
Definition stage.h:87
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42

◆ ExecuteTaskOnReferenceLine()

StageResult apollo::planning::Stage::ExecuteTaskOnReferenceLine ( const common::TrajectoryPoint planning_start_point,
Frame frame 
)
protected

在文件 stage.cc101 行定义.

102 {
103 StageResult stage_result;
104 if (frame->reference_line_info().empty()) {
105 AERROR << "referenceline is empty in stage" << name_;
106 return stage_result.SetStageStatus(StageStatusType::ERROR);
107 }
108 for (auto& reference_line_info : *frame->mutable_reference_line_info()) {
109 if (!reference_line_info.IsDrivable()) {
110 AERROR << "The generated path is not drivable skip";
111 reference_line_info.SetDrivable(false);
112 continue;
113 }
114
115 if (reference_line_info.IsChangeLanePath()) {
116 AERROR << "The generated refline is change lane path, skip";
117 reference_line_info.SetDrivable(false);
118 continue;
119 }
120 common::Status ret = common::Status::OK();
121 for (auto task : task_list_) {
122 const double start_timestamp = Clock::NowInSeconds();
123
124 ret = task->Execute(frame, &reference_line_info);
125
126 const double end_timestamp = Clock::NowInSeconds();
127 const double time_diff_ms = (end_timestamp - start_timestamp) * 1000;
128 ADEBUG << "after task[" << task->Name()
129 << "]: " << reference_line_info.PathSpeedDebugString();
130 ADEBUG << task->Name() << " time spend: " << time_diff_ms << " ms.";
131 AINFO << "Planning Perf: task name [" << task->Name() << "], "
132 << time_diff_ms << " ms.";
133 RecordDebugInfo(&reference_line_info, task->Name(), time_diff_ms);
134
135 if (!ret.ok()) {
136 stage_result.SetTaskStatus(ret);
137 AERROR << "Failed to run tasks[" << task->Name()
138 << "], Error message: " << ret.error_message();
139 break;
140 }
141 }
142 // Generate fallback trajectory in case of task error.
143 if (!ret.ok()) {
144 fallback_task_->Execute(frame, &reference_line_info);
145 }
146 DiscretizedTrajectory trajectory;
147 if (!reference_line_info.CombinePathAndSpeedProfile(
148 planning_start_point.relative_time(),
149 planning_start_point.path_point().s(), &trajectory)) {
150 AERROR << "Fail to aggregate planning trajectory."
151 << reference_line_info.IsChangeLanePath();
152 reference_line_info.SetDrivable(false);
153 continue;
154 }
155 reference_line_info.SetTrajectory(trajectory);
156 reference_line_info.SetDrivable(true);
157 return stage_result;
158 }
159 return stage_result;
160}
void RecordDebugInfo(ReferenceLineInfo *reference_line_info, const std::string &name, const double time_diff_ms)
Definition stage.cc:263
std::shared_ptr< Task > fallback_task_
Definition stage.h:88
#define ADEBUG
Definition log.h:41

◆ ExecuteTaskOnReferenceLineForOnlineLearning()

StageResult apollo::planning::Stage::ExecuteTaskOnReferenceLineForOnlineLearning ( const common::TrajectoryPoint planning_start_point,
Frame frame 
)
protected

在文件 stage.cc162 行定义.

163 {
164 // online learning mode
165 for (auto& reference_line_info : *frame->mutable_reference_line_info()) {
166 reference_line_info.SetDrivable(false);
167 }
168
169 StageResult stage_result;
170 // FIXME(all): current only pick up the first reference line to use
171 // learning model trajectory
172 auto& picked_reference_line_info =
173 frame->mutable_reference_line_info()->front();
174 for (auto task : task_list_) {
175 const double start_timestamp = Clock::NowInSeconds();
176
177 const auto ret = task->Execute(frame, &picked_reference_line_info);
178
179 const double end_timestamp = Clock::NowInSeconds();
180 const double time_diff_ms = (end_timestamp - start_timestamp) * 1000;
181 ADEBUG << "task[" << task->Name() << "] time spent: " << time_diff_ms
182 << " ms.";
183 RecordDebugInfo(&picked_reference_line_info, task->Name(), time_diff_ms);
184
185 if (!ret.ok()) {
186 stage_result.SetTaskStatus(ret);
187 AERROR << "Failed to run tasks[" << task->Name()
188 << "], Error message: " << ret.error_message();
189 break;
190 }
191 }
192
193 const std::vector<common::TrajectoryPoint>& adc_future_trajectory_points =
194 picked_reference_line_info.trajectory();
195 DiscretizedTrajectory trajectory;
196 if (picked_reference_line_info.AdjustTrajectoryWhichStartsFromCurrentPos(
197 planning_start_point, adc_future_trajectory_points, &trajectory)) {
198 picked_reference_line_info.SetTrajectory(trajectory);
199 picked_reference_line_info.SetDrivable(true);
200 picked_reference_line_info.SetCost(0);
201 }
202
203 return stage_result;
204}

◆ FinishScenario()

StageResult apollo::planning::Stage::FinishScenario ( )
protectedvirtual

在文件 stage.cc258 行定义.

258 {
259 next_stage_ = "";
260 return StageResult(StageStatusType::FINISHED);
261}

◆ GetContextAs()

template<typename T >
T * apollo::planning::Stage::GetContextAs ( ) const
inline

在文件 stage.h67 行定义.

67 {
68 return static_cast<T*>(context_);
69 }

◆ Init()

bool apollo::planning::Stage::Init ( const StagePipeline config,
const std::shared_ptr< DependencyInjector > &  injector,
const std::string &  config_dir,
void *  context 
)
virtual

apollo::planning::StageApproachingParkingSpot, apollo::planning::StopSignUnprotectedStageCreep, apollo::planning::TrafficLightUnprotectedLeftTurnStageCreep, apollo::planning::TrafficLightUnprotectedRightTurnStageCreep , 以及 apollo::planning::YieldSignStageCreep 重载.

在文件 stage.cc43 行定义.

45 {
46 pipeline_config_ = config;
47 next_stage_ = config.name();
48 injector_ = injector;
49 name_ = config.name();
50 context_ = context;
51 injector_->planning_context()
52 ->mutable_planning_status()
53 ->mutable_scenario()
54 ->set_stage_type(name_);
55 std::string path_name = ConfigUtil::TransformToPathName(name_);
56 std::string task_config_dir = config_dir + "/" + path_name;
57 // Load task plugin.
58 for (int i = 0; i < pipeline_config_.task_size(); ++i) {
59 auto task = pipeline_config_.task(i);
60 auto task_type = task.type();
62 ->CreateInstance<Task>(
64 if (nullptr == task_ptr) {
65 AERROR << "Create task " << task.name() << " of " << name_ << " failed!";
66 return false;
67 }
68 if (task_ptr->Init(task_config_dir, task.name(), injector)) {
69 task_list_.push_back(task_ptr);
70 } else {
71 AERROR << task.name() << " init failed!";
72 return false;
73 }
74 }
75 // Load trajectory fallback task.
76 // If fallback task is not set, use "FastStopTrajectoryFallback" as default.
77 std::string fallback_task_type = "FastStopTrajectoryFallback";
78 std::string fallback_task_name = "FAST_STOP_TRAJECTORY_FALLBACK";
79 if (pipeline_config_.has_fallback_task()) {
80 fallback_task_type = pipeline_config_.fallback_task().type();
81 fallback_task_name = pipeline_config_.fallback_task().name();
82 }
85 ->CreateInstance<Task>(
86 ConfigUtil::GetFullPlanningClassName(fallback_task_type));
87 if (nullptr == fallback_task_) {
88 AERROR << "Create fallback task " << fallback_task_name << " of " << name_
89 << " failed!";
90 return false;
91 }
92 if (!fallback_task_->Init(task_config_dir, fallback_task_name, injector)) {
93 AERROR << fallback_task_name << " init failed!";
94 return false;
95 }
96 return true;
97}
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 TransformToPathName(const std::string &name)
Tranform the name to part of path.
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...
StagePipeline pipeline_config_
Definition stage.h:92
repeated PluginDeclareInfo task
optional PluginDeclareInfo fallback_task

◆ Name()

const std::string & apollo::planning::Stage::Name ( ) const

在文件 stage.cc99 行定义.

99{ return name_; }

◆ NextStage()

const std::string & apollo::planning::Stage::NextStage ( ) const
inline

在文件 stage.h71 行定义.

71{ return next_stage_; }

◆ Process()

virtual StageResult apollo::planning::Stage::Process ( const common::TrajectoryPoint planning_init_point,
Frame frame 
)
pure virtual

Each stage does its business logic inside Process function.

If the stage want to transit to a different stage after finish, it should set the type of 'next_stage_'.

apollo::planning::BareIntersectionUnprotectedStageApproach, apollo::planning::BareIntersectionUnprotectedStageIntersectionCruise, apollo::planning::EmergencyPullOverStageApproach, apollo::planning::EmergencyPullOverStageSlowDown, apollo::planning::EmergencyPullOverStageStandby, apollo::planning::EmergencyStopStageApproach, apollo::planning::EmergencyStopStageStandby, apollo::planning::LaneFollowStage, apollo::planning::ParkAndGoStageAdjust, apollo::planning::ParkAndGoStageCheck, apollo::planning::ParkAndGoStageCruise, apollo::planning::ParkAndGoStagePreCruise, apollo::planning::PullOverStageApproach, apollo::planning::PullOverStageRetryApproachParking, apollo::planning::PullOverStageRetryParking, apollo::planning::StopSignUnprotectedStageCreep, apollo::planning::StopSignUnprotectedStageIntersectionCruise, apollo::planning::StopSignUnprotectedStagePreStop, apollo::planning::StopSignUnprotectedStageStop, apollo::planning::TrafficLightProtectedStageApproach, apollo::planning::TrafficLightProtectedStageIntersectionCruise, apollo::planning::TrafficLightUnprotectedLeftTurnStageApproach, apollo::planning::TrafficLightUnprotectedLeftTurnStageCreep, apollo::planning::TrafficLightUnprotectedLeftTurnStageIntersectionCruise, apollo::planning::TrafficLightUnprotectedRightTurnStageCreep, apollo::planning::TrafficLightUnprotectedRightTurnStageIntersectionCruise, apollo::planning::TrafficLightUnprotectedRightTurnStageStop, apollo::planning::StageApproachingParkingSpot, apollo::planning::StageParking, apollo::planning::YieldSignStageApproach , 以及 apollo::planning::YieldSignStageCreep 内被实现.

◆ RecordDebugInfo()

void apollo::planning::Stage::RecordDebugInfo ( ReferenceLineInfo reference_line_info,
const std::string &  name,
const double  time_diff_ms 
)
protected

在文件 stage.cc263 行定义.

265 {
266 if (!FLAGS_enable_record_debug) {
267 ADEBUG << "Skip record debug info";
268 return;
269 }
270 if (reference_line_info == nullptr) {
271 AERROR << "Reference line info is null.";
272 return;
273 }
274
275 auto ptr_latency_stats = reference_line_info->mutable_latency_stats();
276
277 auto ptr_stats = ptr_latency_stats->add_task_stats();
278 ptr_stats->set_name(name);
279 ptr_stats->set_time_ms(time_diff_ms);
280}

类成员变量说明

◆ context_

void* apollo::planning::Stage::context_
protected

在文件 stage.h90 行定义.

◆ fallback_task_

std::shared_ptr<Task> apollo::planning::Stage::fallback_task_
protected

在文件 stage.h88 行定义.

◆ injector_

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

在文件 stage.h91 行定义.

◆ next_stage_

std::string apollo::planning::Stage::next_stage_
protected

在文件 stage.h89 行定义.

◆ pipeline_config_

StagePipeline apollo::planning::Stage::pipeline_config_
protected

在文件 stage.h92 行定义.

◆ task_list_

std::vector<std::shared_ptr<Task> > apollo::planning::Stage::task_list_
protected

在文件 stage.h87 行定义.


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