39 const std::string& config_dir,
40 const std::string& name,
41 const std::shared_ptr<DependencyInjector>& injector) {
46 return Task::LoadConfig<SquarePathConfig>(&config_);
50 std::vector<PathBoundary> candidate_path_boundaries;
51 std::vector<PathData> candidate_path_data;
57 AINFO << std::fixed <<
"Plan at the starting point: x = " << planning_start_point.
path_point().
x()
58 <<
", y = " << planning_start_point.
path_point().
y()
60 if (!DecidePathBounds(&candidate_path_boundaries)) {
61 AERROR <<
"Decide path bound failed";
64 if (!OptimizePath(candidate_path_boundaries, &candidate_path_data)) {
65 AERROR <<
"Optmize path failed";
68 if (!AssessPath(&candidate_path_data, reference_line_info)) {
69 AERROR <<
"Path assessment failed";
75bool SquarePath::DecidePathBounds(std::vector<PathBoundary>* boundary) {
76 boundary->emplace_back();
77 auto& path_bound = boundary->back();
78 std::string blocking_obstacle_id =
"";
79 std::string lane_type =
"";
80 double path_narrowest_width = 0;
82 const std::string msg =
"Failed to initialize path boundaries.";
86 path_bound.set_label(absl::StrCat(
"regular/",
"square"));
91 std::vector<SLPolygon> obs_sl_polygons;
98 &blocking_obstacle_id,
99 &path_narrowest_width)) {
100 const std::string msg
101 =
"Failed to decide fine tune the boundaries after "
102 "taking into consideration all static obstacles.";
108 while (!blocking_obstacle_id.empty() && path_bound.size() < temp_path_bound.size()
109 && counter < FLAGS_num_extra_tail_bound_point) {
110 path_bound.push_back(temp_path_bound[path_bound.size()]);
115 AINFO <<
"init l out of range" <<
init_sl_state_.second[0] << path_bound[0].l_lower.l <<
","
116 << path_bound[0].l_upper.l;
120 path_bound.set_blocking_obstacle_id(blocking_obstacle_id);
125bool SquarePath::OptimizePath(
126 const std::vector<PathBoundary>& path_boundaries,
127 std::vector<PathData>* candidate_path_data) {
130 std::array<double, 3> end_state = {0.0, 0.0, 0.0};
131 for (
const auto& path_boundary : path_boundaries) {
132 size_t path_boundary_size = path_boundary.boundary().size();
133 if (path_boundary_size <= 1U) {
134 AERROR <<
"Get invalid path boundary with size: " << path_boundary_size;
137 std::vector<double> opt_l, opt_dl, opt_ddl;
138 std::vector<std::pair<double, double>> ddl_bounds;
140 PrintCurves print_debug;
141 for (
size_t i = 0; i < path_boundary_size; ++i) {
142 double s =
static_cast<double>(i) * path_boundary.delta_s() + path_boundary.start_s();
143 double kappa = reference_line.GetNearestReferencePoint(s).kappa();
144 print_debug.AddPoint(
"ref_kappa", s, kappa);
146 print_debug.PrintToLog();
148 std::vector<double> ref_l(path_boundary_size, 0);
149 std::vector<double> weight_ref_l(path_boundary_size, 0);
151 path_boundary, config.path_reference_l_weight(), &ref_l, &weight_ref_l);
166 opt_l, opt_dl, opt_ddl, path_boundary.delta_s(), path_boundary.start_s());
168 path_data.SetReferenceLine(&reference_line);
169 path_data.SetFrenetPath(std::move(frenet_frame_path));
170 if (FLAGS_use_front_axe_center_in_path_planning) {
171 auto discretized_path
173 path_data.SetDiscretizedPath(discretized_path);
175 path_data.set_path_label(path_boundary.label());
176 path_data.set_blocking_obstacle_id(path_boundary.blocking_obstacle_id());
177 candidate_path_data->push_back(std::move(path_data));
180 if (candidate_path_data->empty()) {
186bool SquarePath::AssessPath(std::vector<PathData>* candidate_path_data, ReferenceLineInfo* reference_line_info) {
187 PathData& curr_path_data = candidate_path_data->back();
190 AINFO <<
"Lane follow path is invalid";
195 AINFO <<
"max_kappa:" << max_kappa;
197 for (
const auto& path_point : curr_path_data.discretized_path()) {
198 AINFO << path_point.x() <<
"," << path_point.y() <<
"," << path_point.theta() <<
"," << path_point.kappa()
199 <<
"," << path_point.dkappa();
200 if (std::fabs(path_point.kappa()) > max_kappa) {
201 AINFO <<
"Path kappa is too large" << path_point.kappa();
208 reference_line_info->MutableCandidatePathData()->push_back(curr_path_data);
209 if (reference_line_info->mutable_path_data()->Empty()) {
210 (*reference_line_info->mutable_path_data()) = std::move(curr_path_data);
215bool SquarePath::GetBoundaryFromSquare(
216 const ReferenceLineInfo& reference_line_info,
217 PathBoundary*
const path_boundary,
218 const SLState& init_sl_state) {
219 hdmap::PathOverlap junction_overlap;
220 if (reference_line_info.GetJunction(init_sl_state.first[0], &junction_overlap) == 0) {
224 const auto& junction = hdmap->GetJunctionById(
hdmap::MakeMapId(junction_overlap.object_id));
225 const auto& junction_polygon = junction->polygon();
226 const auto& reference_line = reference_line_info.reference_line();
227 SLBoundary sl_boundary;
228 reference_line.GetSLBoundary(junction_polygon, &sl_boundary);
229 SLPolygon sl_polygon(sl_boundary, junction_overlap.object_id);
231 for (
size_t i = 0; i < path_boundary->size(); i++) {
232 auto& point = path_boundary->at(i);
233 if (point.s < sl_polygon.MinS() || point.s > sl_polygon.MaxS()) {
236 double l_min = sl_polygon.GetRightBoundaryByS(point.s);
237 double l_max = sl_polygon.GetLeftBoundaryByS(point.s);
241 reference_line.GetRoadWidth(point.s, &road_left_width, &road_right_width);
245 l_min = std::max<double>(l_min, -road_right_width);
246 l_max = std::min<double>(l_max, road_left_width);
247 if (point.l_lower.l > l_min) {
248 point.l_lower.l = l_min;
251 if (point.l_upper.l < l_max) {
252 point.l_upper.l = l_max;
A general class to denote the return status of an API call.
static Status OK()
generate a success status.
@Brief This is a helper class that can load vehicle configurations.
static const HDMap * BaseMapPtr()
Frame holds all data for one planning cycle.
const common::TrajectoryPoint & PlanningStartPoint() const
static bool IsValidRegularPath(const ReferenceLineInfo &reference_line_info, const PathData &path_data)
Check if the generated path is valid
static bool GetBoundaryFromSelfLane(const ReferenceLineInfo &reference_line_info, const SLState &init_sl_state, PathBoundary *const path_bound)
generate path bound by self lane and adc position
static bool GetBoundaryFromStaticObstacles(const ReferenceLineInfo &reference_line_info, std::vector< SLPolygon > *const sl_polygons, const SLState &init_sl_state, PathBoundary *const path_boundaries, std::string *const blocking_obstacle_id, double *const narrowest_width)
Refine the boundary based on static obstacles.
static void GetSLPolygons(const ReferenceLineInfo &reference_line_info, std::vector< SLPolygon > *polygons, const SLState &init_sl_state)
static bool InitPathBoundary(const ReferenceLineInfo &reference_line_info, PathBoundary *const path_bound, SLState init_sl_state)
Starting from ADC's current position, increment until the path length, and set lateral bounds to be i...
void RecordDebugInfo(const PathBound &path_boundaries, const std::string &debug_name, ReferenceLineInfo *const reference_line_info)
add path_boundary debug info for PnC monitor
void GetStartPointSLState()
calculate init sl state by planning start point, result will store in init_sl_state_
static std::vector< common::PathPoint > ConvertPathPointRefFromFrontAxeToRearAxe(const PathData &path_data)
static void CalculateAccBound(const PathBoundary &path_boundary, const ReferenceLine &reference_line, std::vector< std::pair< double, double > > *ddl_bounds)
calculate ddl bound by referenceline kappa and adc lat accleration
static FrenetFramePath ToPiecewiseJerkPath(const std::vector< double > &x, const std::vector< double > &dx, const std::vector< double > &ddx, const double delta_s, const double start_s)
Data format tramform from raw data to FrenetFramePath
static double EstimateJerkBoundary(const double vehicle_speed)
Calculation of jerk boundary based on vehicle kinematics model.
static bool OptimizePath(const SLState &init_state, const std::array< double, 3 > &end_state, std::vector< double > l_ref, std::vector< double > l_ref_weight, const PathBoundary &path_boundary, const std::vector< std::pair< double, double > > &ddl_bounds, double dddl_bound, const PiecewiseJerkPathConfig &config, std::vector< double > *x, std::vector< double > *dx, std::vector< double > *ddx)
Piecewise jerk path optimizer.
static void UpdatePathRefWithBound(const PathBoundary &path_boundary, double weight, std::vector< double > *ref_l, std::vector< double > *weight_ref_l)
If ref_l is below or above path boundary, will update its values and weights
ReferenceLineInfo holds all data for one reference line.
const ReferenceLine & reference_line() const
bool Init(const std::string &config_dir, const std::string &name, const std::shared_ptr< DependencyInjector > &injector) override
ReferenceLineInfo * reference_line_info_
virtual bool Init(const std::string &config_dir, const std::string &name, const std::shared_ptr< DependencyInjector > &injector)
Planning module main class.
apollo::hdmap::Id MakeMapId(const std::string &id)
create a Map ID given a string.
std::pair< std::array< double, 3 >, std::array< double, 3 > > SLState
std::vector< PathBoundPoint > PathBound
optional PathPoint path_point
optional double max_steer_angle
optional double steer_ratio
optional double wheel_base
optional double max_lateral_distance
optional bool enable_road_boundary_constraint
optional PiecewiseJerkPathConfig path_optimizer_config