23#include <unordered_map>
41 : next_stage_(
""), context_(nullptr), injector_(nullptr), name_(
"") {}
44 const std::shared_ptr<DependencyInjector>& injector,
45 const std::string& config_dir,
void* context) {
49 name_ = config.
name();
52 ->mutable_planning_status()
54 ->set_stage_type(name_);
56 std::string task_config_dir = config_dir +
"/" + path_name;
60 auto task_type = task.
type();
64 if (
nullptr == task_ptr) {
65 AERROR <<
"Create task " << task.name() <<
" of " << name_ <<
" failed!";
68 if (task_ptr->Init(task_config_dir, task.name(), injector)) {
71 AERROR << task.name() <<
" init failed!";
77 std::string fallback_task_type =
"FastStopTrajectoryFallback";
78 std::string fallback_task_name =
"FAST_STOP_TRAJECTORY_FALLBACK";
88 AERROR <<
"Create fallback task " << fallback_task_name <<
" of " << name_
92 if (!
fallback_task_->Init(task_config_dir, fallback_task_name, injector)) {
93 AERROR << fallback_task_name <<
" init failed!";
105 AERROR <<
"referenceline is empty in stage" << name_;
109 if (!reference_line_info.IsDrivable()) {
110 AERROR <<
"The generated path is not drivable skip";
111 reference_line_info.SetDrivable(
false);
115 if (reference_line_info.IsChangeLanePath()) {
116 AERROR <<
"The generated refline is change lane path, skip";
117 reference_line_info.SetDrivable(
false);
124 ret = task->Execute(frame, &reference_line_info);
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.";
137 AERROR <<
"Failed to run tasks[" << task->Name()
147 if (!reference_line_info.CombinePathAndSpeedProfile(
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);
155 reference_line_info.SetTrajectory(trajectory);
156 reference_line_info.SetDrivable(
true);
166 reference_line_info.SetDrivable(
false);
172 auto& picked_reference_line_info =
177 const auto ret = task->Execute(frame, &picked_reference_line_info);
180 const double time_diff_ms = (end_timestamp - start_timestamp) * 1000;
181 ADEBUG <<
"task[" << task->Name() <<
"] time spent: " << time_diff_ms
183 RecordDebugInfo(&picked_reference_line_info, task->Name(), time_diff_ms);
187 AERROR <<
"Failed to run tasks[" << task->Name()
188 <<
"], Error message: " << ret.error_message();
193 const std::vector<common::TrajectoryPoint>& adc_future_trajectory_points =
194 picked_reference_line_info.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);
212 ret = task->Execute(frame);
216 AERROR <<
"Failed to run tasks[" << task->Name()
217 <<
"], Error message: " << ret.error_message();
219 const double time_diff_ms = (end_timestamp - start_timestamp) * 1000;
220 AINFO <<
"Planning Perf: task name [" << task->Name() <<
"], "
221 << time_diff_ms <<
" ms.";
226 const double time_diff_ms = (end_timestamp - start_timestamp) * 1000;
227 AINFO <<
"Planning Perf: task name [" << task->Name() <<
"], "
228 << time_diff_ms <<
" ms.";
237 auto publishable_traj_and_gear =
238 std::make_pair(std::move(publishable_trajectory), gear);
241 std::move(publishable_traj_and_gear);
249 auto publishable_traj_and_gear =
250 std::make_pair(std::move(publishable_trajectory), gear);
253 std::move(publishable_traj_and_gear);
264 const std::string& name,
265 const double time_diff_ms) {
266 if (!FLAGS_enable_record_debug) {
267 ADEBUG <<
"Skip record debug info";
270 if (reference_line_info ==
nullptr) {
271 AERROR <<
"Reference line info is null.";
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);
A general class to denote the return status of an API call.
bool ok() const
check whether the return status is OK.
const std::string & error_message() const
returns the error message of the status, empty if the status is OK.
static Status OK()
generate a success status.
a singleton clock that can be used to get the current timestamp.
static double NowInSeconds()
gets the current time in second.
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...
Frame holds all data for one planning cycle.
const OpenSpaceInfo & open_space_info() const
OpenSpaceInfo * mutable_open_space_info()
const std::list< ReferenceLineInfo > & reference_line_info() const
std::list< ReferenceLineInfo > * mutable_reference_line_info()
bool fallback_flag() const
const TrajGearPair & fallback_trajectory() const
const TrajGearPair & chosen_partitioned_trajectory() const
std::pair< PublishableTrajectory, canbus::Chassis::GearPosition > * mutable_publishable_trajectory_data()
ReferenceLineInfo holds all data for one reference line.
LatencyStats * mutable_latency_stats()
const StageResult & SetStageStatus(const StageStatusType &stage_status)
Set the stage status.
const StageResult & SetTaskStatus(const common::Status &status)
Set the task execution result.
virtual StageResult FinishScenario()
StageResult ExecuteTaskOnOpenSpace(Frame *frame)
virtual bool Init(const StagePipeline &config, const std::shared_ptr< DependencyInjector > &injector, const std::string &config_dir, void *context)
std::shared_ptr< DependencyInjector > injector_
StagePipeline pipeline_config_
StageResult ExecuteTaskOnReferenceLineForOnlineLearning(const common::TrajectoryPoint &planning_start_point, Frame *frame)
void RecordDebugInfo(ReferenceLineInfo *reference_line_info, const std::string &name, const double time_diff_ms)
StageResult ExecuteTaskOnReferenceLine(const common::TrajectoryPoint &planning_start_point, Frame *frame)
std::shared_ptr< Task > fallback_task_
const std::string & Name() const
std::vector< std::shared_ptr< Task > > task_list_
Planning module main class.
optional double relative_time
optional PathPoint path_point
repeated PluginDeclareInfo task
optional PluginDeclareInfo fallback_task