45 injector_ = std::make_shared<DependencyInjector>();
47 if (FLAGS_use_navigation_mode) {
48 planning_base_ = std::make_unique<NaviPlanning>(injector_);
50 planning_base_ = std::make_unique<OnLanePlanning>(injector_);
54 <<
"failed to load planning config file "
57 if (FLAGS_planning_offline_learning ||
59 if (!message_process_.
Init(config_, injector_)) {
60 AERROR <<
"failed to init MessageProcess";
65 planning_base_->Init(config_);
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);
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);
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);
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);
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);
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);
128 FLAGS_planning_command_status);
133 const std::shared_ptr<prediction::PredictionObstacles>&
134 prediction_obstacles,
135 const std::shared_ptr<canbus::Chassis>& chassis,
136 const std::shared_ptr<localization::LocalizationEstimate>&
137 localization_estimate) {
138 ACHECK(prediction_obstacles !=
nullptr);
148 std::lock_guard<std::mutex> lock(mutex_);
151 planning_command_.
header())) {
153 std::make_shared<PlanningCommand>(planning_command_);
157 std::lock_guard<std::mutex> lock(mutex_);
159 std::make_shared<TrafficLightDetection>(traffic_light_);
160 local_view_.
relative_map = std::make_shared<MapMsg>(relative_map_);
163 std::lock_guard<std::mutex> lock(mutex_);
170 planning_command_.Clear();
172 local_view_.
pad_msg = std::make_shared<PadMessage>(pad_msg_);
176 std::lock_guard<std::mutex> lock(mutex_);
177 local_view_.
stories = std::make_shared<Stories>(stories_);
180 std::lock_guard<std::mutex> lock(mutex_);
184 control_interactive_msg_.
header())) {
186 std::make_shared<ControlInteractiveMsg>(control_interactive_msg_);
191 AINFO <<
"Input check failed";
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);
219 AERROR <<
"fail to generate learning data frame";
226 planning_base_->RunOnce(local_view_, &adc_trajectory_pb);
228 common::util::FillHeader(
node_->Name(), &adc_trajectory_pb);
230 SetLocation(&adc_trajectory_pb);
233 for (
auto& p : *adc_trajectory_pb.mutable_trajectory_point()) {
234 p.set_relative_time(p.relative_time() + dt);
236 planning_writer_->Write(adc_trajectory_pb);
241 common::util::FillHeader(
node_->Name(), &command_status);
252 }
else if (planning_base_->IsPlanningFinished(current_trajectory_type)) {
253 AINFO <<
"Set the external_command: FINISHED";
256 AINFO <<
"Set the external_command: RUNNING";
259 command_status_writer_->Write(command_status);
262 auto* history = injector_->history();
263 history->Add(adc_trajectory_pb);
268void PlanningComponent::CheckRerouting() {
269 auto* rerouting = injector_->planning_context()
270 ->mutable_planning_status()
271 ->mutable_rerouting();
272 if (!rerouting->need_rerouting()) {
275 common::util::FillHeader(
node_->Name(),
276 rerouting->mutable_lane_follow_command());
277 auto lane_follow_command_ptr =
278 std::make_shared<apollo::external_command::LaneFollowCommand>(
279 rerouting->lane_follow_command());
280 rerouting_client_->SendRequest(lane_follow_command_ptr);
281 rerouting->set_need_rerouting(
false);
284bool PlanningComponent::CheckInput() {
285 ADCTrajectory trajectory_pb;
287 SetLocation(&trajectory_pb);
288 auto* not_ready = trajectory_pb.mutable_decision()
289 ->mutable_main_decision()
290 ->mutable_not_ready();
293 not_ready->set_reason(
"localization not ready");
294 }
else if (local_view_.
chassis ==
nullptr) {
295 not_ready->set_reason(
"chassis not ready");
297 not_ready->set_reason(
"map not ready");
302 if (FLAGS_use_navigation_mode) {
304 not_ready->set_reason(
"relative map not ready");
309 not_ready->set_reason(
"planning_command not ready");
313 if (not_ready->has_reason()) {
314 AINFO << not_ready->reason() <<
"; skip the planning cycle.";
315 common::util::FillHeader(
node_->Name(), &trajectory_pb);
316 planning_writer_->Write(trajectory_pb);
322void PlanningComponent::SetLocation(ADCTrajectory*
const ptr_trajectory_pb) {
323 auto p = ptr_trajectory_pb->mutable_location_pose();
324 p->mutable_vehice_location()->set_x(
326 p->mutable_vehice_location()->set_y(
328 const Vec2d& adc_position = {
331 Vec2d left_point, right_point;
332 if (planning_base_->GenerateWidthOfLane(adc_position, left_point,
334 p->mutable_left_lane_boundary_point()->set_x(left_point.x());
335 p->mutable_left_lane_boundary_point()->set_y(left_point.y());
336 p->mutable_right_lane_boundary_point()->set_x(right_point.x());
337 p->mutable_right_lane_boundary_point()->set_y(right_point.y());
Implements a class of 2-dimensional vectors.
bool GetProtoConfig(T *config) const
const std::string & ConfigFilePath() const
std::shared_ptr< Node > node_
static const HDMap * BaseMapPtr()
bool Init(const PlanningConfig &planning_config)
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 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 module main class.
Some string util functions.
bool IsProtoEqual(const ProtoA &a, const ProtoB &b)
optional ErrorCode error_code
optional apollo::common::Header header
optional TrajectoryType trajectory_type
optional apollo::common::Header header
std::shared_ptr< PadMessage > pad_msg
std::shared_ptr< localization::LocalizationEstimate > localization_estimate
std::shared_ptr< PlanningCommand > planning_command
std::shared_ptr< relative_map::MapMsg > relative_map
std::shared_ptr< control::ControlInteractiveMsg > control_interactive_msg
std::shared_ptr< prediction::PredictionObstacles > prediction_obstacles
std::shared_ptr< storytelling::Stories > stories
std::shared_ptr< canbus::Chassis > chassis
std::shared_ptr< perception::TrafficLightDetection > traffic_light
optional apollo::common::Header header
optional DrivingAction action
optional apollo::common::Header header
optional PlanningLearningMode learning_mode
optional TopicConfig topic_config
optional string story_telling_topic
optional string planning_command_topic
optional string planning_learning_data_topic
optional string relative_map_topic
optional string control_interative_topic
optional string planning_trajectory_topic
optional string traffic_light_detection_topic
optional string routing_request_topic
optional string planning_pad_topic