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

#include <planning_component.h>

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

Public 成员函数

 PlanningComponent ()=default
 
 ~PlanningComponent ()=default
 
bool Init () override
 
bool Proc (const std::shared_ptr< prediction::PredictionObstacles > &prediction_obstacles, const std::shared_ptr< canbus::Chassis > &chassis, const std::shared_ptr< localization::LocalizationEstimate > &localization_estimate) override
 
- Public 成员函数 继承自 apollo::cyber::Component< prediction::PredictionObstacles, canbus::Chassis, localization::LocalizationEstimate >
 Component ()
 
 ~Component () override
 
bool Initialize (const ComponentConfig &config) override
 init the component by protobuf object.
 
bool Process (const std::shared_ptr< prediction::PredictionObstacles > &msg0, const std::shared_ptr< canbus::Chassis > &msg1, const std::shared_ptr< localization::LocalizationEstimate > &msg2, const std::shared_ptr< NullType > &msg3)
 
- Public 成员函数 继承自 apollo::cyber::ComponentBase
virtual ~ComponentBase ()
 
virtual bool Initialize (const TimerComponentConfig &config)
 
virtual void Shutdown ()
 
template<typename T >
bool GetProtoConfig (T *config) const
 

额外继承的成员函数

- Public 类型 继承自 apollo::cyber::ComponentBase
template<typename M >
using Reader = cyber::Reader< M >
 
- Protected 成员函数 继承自 apollo::cyber::ComponentBase
virtual void Clear ()
 
const std::string & ConfigFilePath () const
 
void LoadConfigFiles (const ComponentConfig &config)
 
void LoadConfigFiles (const TimerComponentConfig &config)
 
- Protected 属性 继承自 apollo::cyber::ComponentBase
std::atomic< bool > is_shutdown_ = {false}
 
std::shared_ptr< Node > node_ = nullptr
 
std::string config_file_path_ = ""
 
std::vector< std::shared_ptr< ReaderBase > > readers_
 

详细描述

在文件 planning_component.h 第 45 行定义.

构造及析构函数说明

◆ PlanningComponent()

apollo::planning::PlanningComponent::PlanningComponent ( )
default

◆ ~PlanningComponent()

apollo::planning::PlanningComponent::~PlanningComponent ( )
default

成员函数说明

◆ Init()

bool apollo::planning::PlanningComponent::Init ( )
overridevirtual

实现了 apollo::cyber::ComponentBase.

在文件 planning_component.cc 第 44 行定义.

44 {
45 injector_ = std::make_shared<DependencyInjector>();
46
47 if (FLAGS_use_navigation_mode) {
48 planning_base_ = std::make_unique<NaviPlanning>(injector_);
49 } else {
50 planning_base_ = std::make_unique<OnLanePlanning>(injector_);
51 }
52
54 << "failed to load planning config file "
56
57 if (FLAGS_planning_offline_learning ||
59 if (!message_process_.Init(config_, injector_)) {
60 AERROR << "failed to init MessageProcess";
61 return false;
62 }
63 }
64
65 planning_base_->Init(config_);
66
67 planning_command_reader_ = node_->CreateReader<PlanningCommand>(
69 [this](const std::shared_ptr<PlanningCommand>& planning_command) {
70 AINFO << "Received planning data: run planning callback."
71 << planning_command->header().DebugString();
72 std::lock_guard<std::mutex> lock(mutex_);
73 planning_command_.CopyFrom(*planning_command);
74 });
75
76 traffic_light_reader_ = node_->CreateReader<TrafficLightDetection>(
78 [this](const std::shared_ptr<TrafficLightDetection>& traffic_light) {
79 ADEBUG << "Received traffic light data: run traffic light callback.";
80 std::lock_guard<std::mutex> lock(mutex_);
81 traffic_light_.CopyFrom(*traffic_light);
82 });
83
84 pad_msg_reader_ = node_->CreateReader<PadMessage>(
86 [this](const std::shared_ptr<PadMessage>& pad_msg) {
87 ADEBUG << "Received pad data: run pad callback.";
88 std::lock_guard<std::mutex> lock(mutex_);
89 pad_msg_.CopyFrom(*pad_msg);
90 });
91
92 story_telling_reader_ = node_->CreateReader<Stories>(
94 [this](const std::shared_ptr<Stories>& stories) {
95 ADEBUG << "Received story_telling data: run story_telling callback.";
96 std::lock_guard<std::mutex> lock(mutex_);
97 stories_.CopyFrom(*stories);
98 });
99
100 control_interactive_reader_ = node_->CreateReader<ControlInteractiveMsg>(
102 [this](const std::shared_ptr<ControlInteractiveMsg>&
103 control_interactive_msg) {
104 ADEBUG << "Received story_telling data: run story_telling callback.";
105 std::lock_guard<std::mutex> lock(mutex_);
106 control_interactive_msg_.CopyFrom(*control_interactive_msg);
107 });
108
109 if (FLAGS_use_navigation_mode) {
110 relative_map_reader_ = node_->CreateReader<MapMsg>(
112 [this](const std::shared_ptr<MapMsg>& map_message) {
113 ADEBUG << "Received relative map data: run relative map callback.";
114 std::lock_guard<std::mutex> lock(mutex_);
115 relative_map_.CopyFrom(*map_message);
116 });
117 }
118 planning_writer_ = node_->CreateWriter<ADCTrajectory>(
120
121 rerouting_client_ =
123 external_command::CommandStatus>(
125 planning_learning_data_writer_ = node_->CreateWriter<PlanningLearningData>(
127 command_status_writer_ = node_->CreateWriter<external_command::CommandStatus>(
128 FLAGS_planning_command_status);
129 return true;
130}
bool GetProtoConfig(T *config) const
const std::string & ConfigFilePath() const
std::shared_ptr< Node > node_
bool Init(const PlanningConfig &planning_config)
#define ACHECK(cond)
Definition log.h:80
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
optional PlanningLearningMode learning_mode
optional string traffic_light_detection_topic

◆ Proc()

bool apollo::planning::PlanningComponent::Proc ( const std::shared_ptr< prediction::PredictionObstacles > &  prediction_obstacles,
const std::shared_ptr< canbus::Chassis > &  chassis,
const std::shared_ptr< localization::LocalizationEstimate > &  localization_estimate 
)
override

在文件 planning_component.cc 第 132 行定义.

137 {
138 ACHECK(prediction_obstacles != nullptr);
139
140 // check and process possible rerouting request
141 CheckRerouting();
142
143 // process fused input data
144 local_view_.prediction_obstacles = prediction_obstacles;
145 local_view_.chassis = chassis;
146 local_view_.localization_estimate = localization_estimate;
147 {
148 std::lock_guard<std::mutex> lock(mutex_);
149 if (!local_view_.planning_command ||
150 !common::util::IsProtoEqual(local_view_.planning_command->header(),
151 planning_command_.header())) {
152 local_view_.planning_command =
153 std::make_shared<PlanningCommand>(planning_command_);
154 }
155 }
156 {
157 std::lock_guard<std::mutex> lock(mutex_);
158 local_view_.traffic_light =
159 std::make_shared<TrafficLightDetection>(traffic_light_);
160 local_view_.relative_map = std::make_shared<MapMsg>(relative_map_);
161 }
162 {
163 std::lock_guard<std::mutex> lock(mutex_);
164 if (!local_view_.pad_msg ||
165 !common::util::IsProtoEqual(local_view_.pad_msg->header(),
166 pad_msg_.header())) {
167 // Check if "CLEAR_PLANNING" PadMessage is received and process.
168 if (pad_msg_.action() == PadMessage::CLEAR_PLANNING) {
169 local_view_.planning_command = nullptr;
170 planning_command_.Clear();
171 }
172 local_view_.pad_msg = std::make_shared<PadMessage>(pad_msg_);
173 }
174 }
175 {
176 std::lock_guard<std::mutex> lock(mutex_);
177 local_view_.stories = std::make_shared<Stories>(stories_);
178 }
179 {
180 std::lock_guard<std::mutex> lock(mutex_);
181 if (!local_view_.control_interactive_msg ||
183 local_view_.control_interactive_msg->header(),
184 control_interactive_msg_.header())) {
185 local_view_.control_interactive_msg =
186 std::make_shared<ControlInteractiveMsg>(control_interactive_msg_);
187 }
188 }
189
190 if (!CheckInput()) {
191 AINFO << "Input check failed";
192 return false;
193 }
194
196 // data process for online training
197 message_process_.OnChassis(*local_view_.chassis);
198 message_process_.OnPrediction(*local_view_.prediction_obstacles);
199 if (local_view_.planning_command->has_lane_follow_command()) {
200 message_process_.OnRoutingResponse(
201 local_view_.planning_command->lane_follow_command());
202 }
203 message_process_.OnStoryTelling(*local_view_.stories);
204 message_process_.OnTrafficLightDetection(*local_view_.traffic_light);
205 message_process_.OnLocalization(*local_view_.localization_estimate);
206 }
207
208 // publish learning data frame for RL test
209 if (config_.learning_mode() == PlanningConfig::RL_TEST) {
210 PlanningLearningData planning_learning_data;
211 LearningDataFrame* learning_data_frame =
212 injector_->learning_based_data()->GetLatestLearningDataFrame();
213 if (learning_data_frame) {
214 planning_learning_data.mutable_learning_data_frame()->CopyFrom(
215 *learning_data_frame);
216 common::util::FillHeader(node_->Name(), &planning_learning_data);
217 planning_learning_data_writer_->Write(planning_learning_data);
218 } else {
219 AERROR << "fail to generate learning data frame";
220 return false;
221 }
222 return true;
223 }
224
225 ADCTrajectory adc_trajectory_pb;
226 planning_base_->RunOnce(local_view_, &adc_trajectory_pb);
227 auto start_time = adc_trajectory_pb.header().timestamp_sec();
228 common::util::FillHeader(node_->Name(), &adc_trajectory_pb);
229
230 SetLocation(&adc_trajectory_pb);
231 // modify trajectory relative time due to the timestamp change in header
232 const double dt = start_time - adc_trajectory_pb.header().timestamp_sec();
233 for (auto& p : *adc_trajectory_pb.mutable_trajectory_point()) {
234 p.set_relative_time(p.relative_time() + dt);
235 }
236 planning_writer_->Write(adc_trajectory_pb);
237
238 // Send command execution feedback.
239 // Error occured while executing the command.
240 external_command::CommandStatus command_status;
241 common::util::FillHeader(node_->Name(), &command_status);
242 if (nullptr != local_view_.planning_command) {
243 command_status.set_command_id(local_view_.planning_command->command_id());
244 }
245
246 ADCTrajectory::TrajectoryType current_trajectory_type =
247 adc_trajectory_pb.trajectory_type();
248 if (adc_trajectory_pb.header().status().error_code() !=
250 command_status.set_status(external_command::CommandStatusType::ERROR);
251 command_status.set_message(adc_trajectory_pb.header().status().msg());
252 } else if (planning_base_->IsPlanningFinished(current_trajectory_type)) {
253 AINFO << "Set the external_command: FINISHED";
254 command_status.set_status(external_command::CommandStatusType::FINISHED);
255 } else {
256 AINFO << "Set the external_command: RUNNING";
257 command_status.set_status(external_command::CommandStatusType::RUNNING);
258 }
259 command_status_writer_->Write(command_status);
260
261 // record in history
262 auto* history = injector_->history();
263 history->Add(adc_trajectory_pb);
264
265 return true;
266}
void OnPrediction(const apollo::prediction::PredictionObstacles &prediction_obstacles)
void OnStoryTelling(const apollo::storytelling::Stories &stories)
void OnRoutingResponse(const apollo::routing::RoutingResponse &routing_response)
void OnLocalization(const apollo::localization::LocalizationEstimate &le)
void OnTrafficLightDetection(const apollo::perception::TrafficLightDetection &traffic_light_detection)
void OnChassis(const apollo::canbus::Chassis &chassis)
bool IsProtoEqual(const ProtoA &a, const ProtoB &b)
Definition util.h:47
std::shared_ptr< PadMessage > pad_msg
Definition local_view.h:46
std::shared_ptr< localization::LocalizationEstimate > localization_estimate
Definition local_view.h:43
std::shared_ptr< PlanningCommand > planning_command
Definition local_view.h:48
std::shared_ptr< relative_map::MapMsg > relative_map
Definition local_view.h:45
std::shared_ptr< control::ControlInteractiveMsg > control_interactive_msg
Definition local_view.h:50
std::shared_ptr< prediction::PredictionObstacles > prediction_obstacles
Definition local_view.h:41
std::shared_ptr< storytelling::Stories > stories
Definition local_view.h:47
std::shared_ptr< canbus::Chassis > chassis
Definition local_view.h:42
std::shared_ptr< perception::TrafficLightDetection > traffic_light
Definition local_view.h:44
optional apollo::common::Header header
Definition pad_msg.proto:8
optional DrivingAction action
Definition pad_msg.proto:26
optional apollo::common::Header header

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