48 {
49 Clear();
50 const double kEpsilon = 1e-6;
51 if (!Sampling()) {
52 AERROR <<
"Fail to sample reference line smoother points!";
53 return false;
54 }
55
56 spline_solver_->Reset(t_knots_,
config_.qp_spline().spline_order());
57
58 if (!AddConstraint()) {
59 AERROR <<
"Add constraint for spline smoother failed";
60 return false;
61 }
62
63 if (!AddKernel()) {
64 AERROR <<
"Add kernel for spline smoother failed.";
65 return false;
66 }
67
68 if (!Solve()) {
69 AERROR <<
"Solve spline smoother problem failed";
70 }
71
72
73 const double start_t = t_knots_.front();
74 const double end_t = t_knots_.back();
75
76 const double resolution =
78 double t = start_t;
79 std::vector<ReferencePoint> ref_points;
80 const auto& spline = spline_solver_->spline();
82 ++i, t += resolution) {
83 const double heading =
84 std::atan2(spline.DerivativeY(t), spline.DerivativeX(t));
86 spline.DerivativeX(t), spline.SecondDerivativeX(t),
87 spline.DerivativeY(t), spline.SecondDerivativeY(t));
89 spline.DerivativeX(t), spline.SecondDerivativeX(t),
90 spline.ThirdDerivativeX(t), spline.DerivativeY(t),
91 spline.SecondDerivativeY(t), spline.ThirdDerivativeY(t));
92
93 std::pair<double, double> xy = spline(t);
94 xy.first += ref_x_;
95 xy.second += ref_y_;
96 common::SLPoint ref_sl_point;
97 if (!raw_reference_line.XYToSL({xy.first, xy.second}, &ref_sl_point)) {
98 return false;
99 }
100 if (ref_sl_point.s() < -kEpsilon ||
101 ref_sl_point.s() > raw_reference_line.Length()) {
102 continue;
103 }
104 ref_sl_point.set_s(std::max(ref_sl_point.s(), 0.0));
105 ReferencePoint rlp = raw_reference_line.GetReferencePoint(ref_sl_point.s());
106 auto new_lane_waypoints = rlp.lane_waypoints();
107 for (auto& lane_waypoint : new_lane_waypoints) {
108 lane_waypoint.l = ref_sl_point.l();
109 }
110 ref_points.emplace_back(ReferencePoint(
111 hdmap::MapPathPoint(common::math::Vec2d(xy.first, xy.second), heading,
112 new_lane_waypoints),
113 kappa, dkappa));
114 }
115
117 if (ref_points.size() < 2) {
118 AERROR <<
"Fail to generate smoothed reference line.";
119 return false;
120 }
121 *smoothed_reference_line = ReferenceLine(ref_points);
122 return true;
123}
static double ComputeCurvatureDerivative(const double dx, const double d2x, const double d3x, const double dy, const double d2y, const double d3y)
Compute the curvature change rate w.r.t.
static double ComputeCurvature(const double dx, const double d2x, const double dy, const double d2y)
Compute the curvature (kappa) given curve X = (x(t), y(t)) which t is an arbitrary parameter.
ReferenceLineSmootherConfig config_
static void RemoveDuplicates(std::vector< ReferencePoint > *points)
optional uint32 num_of_total_points