Apollo 10.0
自动驾驶开放平台
planning_base.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
18
19#include "modules/common_msgs/planning_msgs/planning_internal.pb.h"
20
22#include "cyber/time/clock.h"
33
34namespace apollo {
35namespace planning {
36
38
39PlanningBase::PlanningBase(const std::shared_ptr<DependencyInjector>& injector)
40 : injector_(injector) {}
41
43
45 injector_->planning_context()->Init();
46 config_ = config;
47 return Status::OK();
48}
49
51 const ADCTrajectory::TrajectoryType& current_trajectory_type) const {
52 const auto frame = injector_->frame_history()->Latest();
53 if (current_trajectory_type == apollo::planning::ADCTrajectory::OPEN_SPACE) {
54 AINFO << "Current trajectory type is: OPEN SPACE";
55 if (frame->open_space_info().openspace_planning_finish()) {
56 AINFO << "OPEN SPACE: planning finished";
57 return true;
58 } else {
59 AINFO << "OPEN SPACE: planning not finished";
60 return false;
61 }
62 } else {
63 // const auto frame = injector_->frame_history()->Latest();
64 if (nullptr == frame || frame->reference_line_info().empty() ||
65 nullptr == local_view_.planning_command) {
66 AINFO << "Current reference point is empty;";
67 return true;
68 }
69 const auto& reference_line_info = frame->reference_line_info().front();
70 // Check if the ReferenceLineInfo is the last passage.
71 const auto& reference_points =
72 reference_line_info.reference_line().reference_points();
73 if (reference_points.empty()) {
74 AINFO << "Current reference points is empty;";
75 return true;
76 }
77 const auto& last_reference_point = reference_points.back();
78 const std::vector<hdmap::LaneWaypoint>& lane_way_points =
79 last_reference_point.lane_waypoints();
80 if (lane_way_points.empty()) {
81 AINFO << "Last reference point is empty;";
82 return true;
83 }
84 // Get the end lane way point.
85 if (nullptr == frame->local_view().end_lane_way_point) {
86 AINFO << "Current end lane way is empty;";
87 return true;
88 }
89 bool is_has_passed_destination = injector_->planning_context()
90 ->planning_status()
91 .destination()
92 .has_passed_destination();
93 AINFO << "Current passed destination:" << is_has_passed_destination;
94 return is_has_passed_destination;
95 }
96}
97
98void PlanningBase::FillPlanningPb(const double timestamp,
99 ADCTrajectory* const trajectory_pb) {
100 trajectory_pb->mutable_header()->set_timestamp_sec(timestamp);
101 if (local_view_.prediction_obstacles->has_header()) {
102 trajectory_pb->mutable_header()->set_lidar_timestamp(
103 local_view_.prediction_obstacles->header().lidar_timestamp());
104 trajectory_pb->mutable_header()->set_camera_timestamp(
105 local_view_.prediction_obstacles->header().camera_timestamp());
106 trajectory_pb->mutable_header()->set_radar_timestamp(
107 local_view_.prediction_obstacles->header().radar_timestamp());
108 }
109 trajectory_pb->mutable_routing_header()->CopyFrom(
110 local_view_.planning_command->header());
111}
112
114 // Use PublicRoadPlanner as default Planner
115 std::string planner_name = "apollo::planning::PublicRoadPlanner";
116 if ("" != config_.planner()) {
117 planner_name = config_.planner();
118 planner_name = ConfigUtil::GetFullPlanningClassName(planner_name);
119 }
120 planner_ =
122 planner_name);
123}
124
125bool PlanningBase::GenerateWidthOfLane(const Vec2d& current_location,
126 Vec2d& left_point, Vec2d& right_point) {
127 double left_width = 0, right_width = 0;
128 const auto frame = injector_->frame_history()->Latest();
129 if (nullptr == frame || frame->reference_line_info().empty()) {
130 AINFO << "Reference lane is empty!";
131 return false;
132 }
133 const auto& reference_line_info = frame->reference_line_info().front();
134 // get current SL
135 common::SLPoint current_sl;
136 reference_line_info.reference_line().XYToSL(current_location, &current_sl);
137 // Get the lane width of vehicle location
138 bool get_width_of_lane = reference_line_info.reference_line().GetLaneWidth(
139 current_sl.s(), &left_width, &right_width);
140 AINFO << "get_width_of_lane: " << get_width_of_lane
141 << ", left_width: " << left_width << ", right_width: " << right_width;
142 if (get_width_of_lane && left_width != 0 && right_width != 0) {
143 AINFO << "Get the width of lane successfully!";
144 SLPoint sl_left_point, sl_right_point;
145 sl_left_point.set_s(current_sl.s());
146 sl_left_point.set_l(left_width);
147 sl_right_point.set_s(current_sl.s());
148 sl_right_point.set_l(-right_width);
149 reference_line_info.reference_line().SLToXY(sl_left_point, &left_point);
150 reference_line_info.reference_line().SLToXY(sl_right_point, &right_point);
151 return true;
152 } else {
153 AINFO << "Failed to get the width of lane!";
154 return false;
155 }
156}
157
158} // namespace planning
159} // namespace apollo
A general class to denote the return status of an API call.
Definition status.h:43
static Status OK()
generate a success status.
Definition status.h:60
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
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 GetFullPlanningClassName(const std::string &class_name)
Given the class name of planning module, combine the namespace "apollo::planning::" with it to create...
Planner is a base class for specific planners.
Definition planner.h:45
virtual apollo::common::Status Init(const PlanningConfig &config)
virtual void FillPlanningPb(const double timestamp, ADCTrajectory *const trajectory_pb)
bool GenerateWidthOfLane(const Vec2d &current_location, Vec2d &left_point, Vec2d &right_point)
bool IsPlanningFinished(const ADCTrajectory::TrajectoryType &current_trajectory_type) const
Check if vehicle reaches the end point of the RoutingRequest.
std::shared_ptr< Planner > planner_
std::shared_ptr< DependencyInjector > injector_
Planning module main class.
#define AINFO
Definition log.h:42
class register implement
Definition arena_queue.h:37
std::shared_ptr< PlanningCommand > planning_command
Definition local_view.h:48
std::shared_ptr< prediction::PredictionObstacles > prediction_obstacles
Definition local_view.h:41