Apollo 11.0
自动驾驶开放平台
apollo::planning::LaneFollowParkStage类 参考

#include <lane_follow_park_stage.h>

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

Public 成员函数

bool Init (const StagePipeline &config, const std::shared_ptr< DependencyInjector > &injector, const std::string &config_dir, void *context)
 
StageResult Process (const common::TrajectoryPoint &planning_init_point, Frame *frame) override
 Each stage does its business logic inside Process function.
 
StageResult PlanOnReferenceLine (const common::TrajectoryPoint &planning_start_point, Frame *frame, ReferenceLineInfo *reference_line_info)
 
void PlanFallbackTrajectory (const common::TrajectoryPoint &planning_start_point, Frame *frame, ReferenceLineInfo *reference_line_info)
 
common::SLPoint GetStopSL (const ObjectStop &stop_decision, const ReferenceLine &reference_line) const
 
void RecordObstacleDebugInfo (ReferenceLineInfo *reference_line_info)
 
- Public 成员函数 继承自 apollo::planning::Stage
 Stage ()
 
virtual ~Stage ()=default
 
const std::string & Name () const
 
template<typename T >
T * GetContextAs () const
 
const std::string & NextStage () const
 

额外继承的成员函数

- Protected 成员函数 继承自 apollo::planning::Stage
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 属性 继承自 apollo::planning::Stage
std::vector< std::shared_ptr< Task > > task_list_
 
std::shared_ptr< Task > fallback_task_
 
std::string next_stage_
 
void * context_
 
std::shared_ptr< DependencyInjector > injector_
 
StagePipeline pipeline_config_
 

详细描述

在文件 lane_follow_park_stage.h 第 44 行定义.

成员函数说明

◆ GetStopSL()

SLPoint apollo::planning::LaneFollowParkStage::GetStopSL ( const ObjectStop &  stop_decision,
const ReferenceLine &  reference_line 
) const

在文件 lane_follow_park_stage.cc 第 271 行定义.

271 {
272 SLPoint sl_point;
273 reference_line.XYToSL(stop_decision.stop_point(), &sl_point);
274 return sl_point;
275}

◆ Init()

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

重载 apollo::planning::Stage .

在文件 lane_follow_park_stage.cc 第 54 行定义.

58 {
59 CHECK_NOTNULL(context);
60 bool ret = Stage::Init(config, injector, config_dir, context);
61 if (!ret) {
62 AERROR << Name() << "init failed!";
63 return false;
64 }
65 scenario_config_.CopyFrom(GetContextAs<LaneFollowParkContext>()->scenario_config);
66 return ret;
67}
virtual bool Init(const StagePipeline &config, const std::shared_ptr< DependencyInjector > &injector, const std::string &config_dir, void *context)
Definition stage.cc:43
const std::string & Name() const
Definition stage.cc:99
#define AERROR
Definition log.h:44

◆ PlanFallbackTrajectory()

void apollo::planning::LaneFollowParkStage::PlanFallbackTrajectory ( const common::TrajectoryPoint &  planning_start_point,
Frame *  frame,
ReferenceLineInfo *  reference_line_info 
)

◆ PlanOnReferenceLine()

StageResult apollo::planning::LaneFollowParkStage::PlanOnReferenceLine ( const common::TrajectoryPoint &  planning_start_point,
Frame *  frame,
ReferenceLineInfo *  reference_line_info 
)

在文件 lane_follow_park_stage.cc 第 163 行定义.

166 {
167 if (!reference_line_info->IsChangeLanePath()) {
168 reference_line_info->AddCost(kStraightForwardLineCost);
169 }
170 ADEBUG << "planning start point:" << planning_start_point.DebugString();
171 ADEBUG << "Current reference_line_info is IsChangeLanePath: " << reference_line_info->IsChangeLanePath();
172
173 StageResult ret;
174 for (auto task : task_list_) {
175 const double start_timestamp = Clock::NowInSeconds();
176 const auto start_planning_perf_timestamp
177 = std::chrono::duration<double>(std::chrono::system_clock::now().time_since_epoch()).count();
178
179 ret.SetTaskStatus(task->Execute(frame, reference_line_info));
180
181 const double end_timestamp = Clock::NowInSeconds();
182 const double time_diff_ms = (end_timestamp - start_timestamp) * 1000;
183 ADEBUG << "after task[" << task->Name() << "]:" << reference_line_info->PathSpeedDebugString();
184 ADEBUG << task->Name() << " time spend: " << time_diff_ms << " ms.";
185 RecordDebugInfo(reference_line_info, task->Name(), time_diff_ms);
186
187 const auto end_planning_perf_timestamp
188 = std::chrono::duration<double>(std::chrono::system_clock::now().time_since_epoch()).count();
189 const auto plnning_perf_ms = (end_planning_perf_timestamp - start_planning_perf_timestamp) * 1000;
190 AINFO << "Planning Perf: task name [" << task->Name() << "], " << plnning_perf_ms << " ms.";
191
192 if (ret.IsTaskError()) {
193 AERROR << "Failed to run tasks[" << task->Name()
194 << "], Error message: " << ret.GetTaskStatus().error_message();
195 break;
196 }
197
198 // TODO(SHU): disable reference line order changes for now
199 // updated reference_line_info, because it is changed in
200 // lane_change_decider by PrioritizeChangeLane().
201 // reference_line_info = &frame->mutable_reference_line_info()->front();
202 // ADEBUG << "Current reference_line_info is IsChangeLanePath: "
203 // << reference_line_info->IsChangeLanePath();
204 }
205
206 RecordObstacleDebugInfo(reference_line_info);
207
208 // check path and speed results for path or speed fallback
209 reference_line_info->set_trajectory_type(ADCTrajectory::NORMAL);
210 if (ret.IsTaskError()) {
211 fallback_task_->Execute(frame, reference_line_info);
212 }
213
214 DiscretizedTrajectory trajectory;
215 if (!reference_line_info->CombinePathAndSpeedProfile(
216 planning_start_point.relative_time(), planning_start_point.path_point().s(), &trajectory)) {
217 const std::string msg = "Fail to aggregate planning trajectory.";
218 AERROR << msg;
219 return ret.SetStageStatus(StageStatusType::ERROR, msg);
220 }
221
222 // determine if there is a destination on reference line.
223 double dest_stop_s = -1.0;
224 for (const auto* obstacle : reference_line_info->path_decision()->obstacles().Items()) {
225 if (obstacle->LongitudinalDecision().has_stop()
226 && obstacle->LongitudinalDecision().stop().reason_code() == STOP_REASON_DESTINATION) {
227 SLPoint dest_sl = GetStopSL(obstacle->LongitudinalDecision().stop(), reference_line_info->reference_line());
228 dest_stop_s = dest_sl.s();
229 }
230 }
231
232 for (const auto* obstacle : reference_line_info->path_decision()->obstacles().Items()) {
233 if (obstacle->IsVirtual()) {
234 continue;
235 }
236 if (!obstacle->IsStatic()) {
237 continue;
238 }
239 if (obstacle->LongitudinalDecision().has_stop()) {
240 bool add_stop_obstacle_cost = false;
241 if (dest_stop_s < 0.0) {
242 add_stop_obstacle_cost = true;
243 } else {
244 SLPoint stop_sl
245 = GetStopSL(obstacle->LongitudinalDecision().stop(), reference_line_info->reference_line());
246 if (stop_sl.s() < dest_stop_s && (dest_stop_s - reference_line_info->AdcSlBoundary().end_s()) < 20.0) {
247 add_stop_obstacle_cost = true;
248 }
249 }
250 if (add_stop_obstacle_cost) {
251 static constexpr double kReferenceLineStaticObsCost = 1e3;
252 reference_line_info->AddCost(kReferenceLineStaticObsCost);
253 }
254 }
255 }
256
257 if (FLAGS_enable_trajectory_check) {
259 const std::string msg = "Current planning trajectory is not valid.";
260 AERROR << msg;
261 return ret.SetStageStatus(StageStatusType::ERROR, msg);
262 }
263 }
264
265 reference_line_info->SetTrajectory(trajectory);
266 reference_line_info->SetDrivable(true);
267 ret.SetStageStatus(StageStatusType::RUNNING);
268 return ret;
269}
static double NowInSeconds()
gets the current time in second.
Definition clock.cc:56
static Result ValidTrajectory(const DiscretizedTrajectory &trajectory)
common::SLPoint GetStopSL(const ObjectStop &stop_decision, const ReferenceLine &reference_line) const
void RecordObstacleDebugInfo(ReferenceLineInfo *reference_line_info)
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
std::vector< std::shared_ptr< Task > > task_list_
Definition stage.h:87
#define ADEBUG
Definition log.h:41
#define AINFO
Definition log.h:42

◆ Process()

StageResult apollo::planning::LaneFollowParkStage::Process ( const common::TrajectoryPoint &  planning_init_point,
Frame *  frame 
)
overridevirtual

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::Stage.

在文件 lane_follow_park_stage.cc 第 95 行定义.

95 {
96 if (frame->reference_line_info().empty()) {
97 return StageResult(StageStatusType::FINISHED);
98 }
99
100 bool has_drivable_reference_line = false;
101
102 ADEBUG << "Number of reference lines:\t" << frame->mutable_reference_line_info()->size();
103
104 unsigned int count = 0;
105 StageResult result;
106 int need_escape = 0;
107 for (auto& reference_line_info : *frame->mutable_reference_line_info()) {
108 // TODO(SHU): need refactor
109 if (count++ == frame->mutable_reference_line_info()->size()) {
110 break;
111 }
112 ADEBUG << "No: [" << count << "] Reference Line.";
113 ADEBUG << "IsChangeLanePath: " << reference_line_info.IsChangeLanePath();
114
115 if (has_drivable_reference_line) {
116 reference_line_info.SetDrivable(false);
117 break;
118 }
119
120 result = PlanOnReferenceLine(planning_start_point, frame, &reference_line_info);
121
122 bool escape = LaneEscapeUtil::IsNeedEscape(
123 reference_line_info,
124 scenario_config_.min_distance_block_obs_to_junction(),
125 scenario_config_.enable_junction_borrow(),
126 scenario_config_.passby_min_gap(),
127 scenario_config_.passby_kappa_ratio(),
128 scenario_config_.queue_check_count(),
129 scenario_config_.stable_block_count());
130 need_escape = (escape && need_escape != -1) ? 1 : -1;
131 AINFO << "need escape: " << need_escape;
132
133 if (!result.HasError()) {
134 if (!reference_line_info.IsChangeLanePath()) {
135 ADEBUG << "reference line is NOT lane change ref.";
136 has_drivable_reference_line = true;
137 continue;
138 }
139 if (reference_line_info.Cost() < kStraightForwardLineCost) {
140 // If the path and speed optimization succeed on target lane while
141 // under smart lane-change or IsClearToChangeLane under older version
142 has_drivable_reference_line = true;
143 reference_line_info.SetDrivable(true);
144 } else {
145 reference_line_info.SetDrivable(false);
146 ADEBUG << "\tlane change failed";
147 }
148 } else {
149 reference_line_info.SetDrivable(false);
150 }
151 }
152 AINFO << "need escape: " << need_escape;
153 if (need_escape == 1) {
154 ParkDataCenter::Instance()->set_need_escape(true);
155 next_stage_.clear();
156 return StageResult(StageStatusType::FINISHED);
157 }
158
159 return has_drivable_reference_line ? result.SetStageStatus(StageStatusType::RUNNING)
160 : result.SetStageStatus(StageStatusType::ERROR);
161}
static bool IsNeedEscape(ReferenceLineInfo &reference_line_info, double min_distance_block_obs_to_junction, bool enable_junction_borrow, double passby_min_gap, double passby_kappa_ratio, int queue_check_count, int stable_block_count)
StageResult PlanOnReferenceLine(const common::TrajectoryPoint &planning_start_point, Frame *frame, ReferenceLineInfo *reference_line_info)
std::string next_stage_
Definition stage.h:89

◆ RecordObstacleDebugInfo()

void apollo::planning::LaneFollowParkStage::RecordObstacleDebugInfo ( ReferenceLineInfo *  reference_line_info)

在文件 lane_follow_park_stage.cc 第 69 行定义.

69 {
70 if (!FLAGS_enable_record_debug) {
71 ADEBUG << "Skip record debug info";
72 return;
73 }
74 auto ptr_debug = reference_line_info->mutable_debug();
75
76 const auto path_decision = reference_line_info->path_decision();
77 for (const auto obstacle : path_decision->obstacles().Items()) {
78 auto obstacle_debug = ptr_debug->mutable_planning_data()->add_obstacle();
79 obstacle_debug->set_id(obstacle->Id());
80 obstacle_debug->mutable_sl_boundary()->CopyFrom(obstacle->PerceptionSLBoundary());
81 const auto& decider_tags = obstacle->decider_tags();
82 const auto& decisions = obstacle->decisions();
83 if (decider_tags.size() != decisions.size()) {
84 AERROR << "decider_tags size: " << decider_tags.size()
85 << " different from decisions size:" << decisions.size();
86 }
87 for (size_t i = 0; i < decider_tags.size(); ++i) {
88 auto decision_tag = obstacle_debug->add_decision_tag();
89 decision_tag->set_decider_tag(decider_tags[i]);
90 decision_tag->mutable_decision()->CopyFrom(decisions[i]);
91 }
92 }
93}

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