63 {
64 if (xWS.cols() < 2) {
65 AERROR <<
"reference points size smaller than two, smoother early "
66 "returned";
67 return false;
68 }
69 const auto start_timestamp = std::chrono::system_clock::now();
70
71
72 gear_ = CheckGear(xWS);
73
74
75 std::vector<std::vector<LineSegment2d>> obstacles_linesegments_vec;
76 for (const auto& obstacle_vertices : obstacles_vertices_vec) {
77 size_t vertices_num = obstacle_vertices.size();
78 std::vector<LineSegment2d> obstacle_linesegments;
79 for (size_t i = 0; i + 1 < vertices_num; ++i) {
80 LineSegment2d line_segment =
81 LineSegment2d(obstacle_vertices[i], obstacle_vertices[i + 1]);
82 obstacle_linesegments.emplace_back(line_segment);
83 }
84 obstacles_linesegments_vec.emplace_back(obstacle_linesegments);
85 }
86 obstacles_linesegments_vec_ = std::move(obstacles_linesegments_vec);
87
88
89 DiscretizedPath warm_start_path;
90 size_t xWS_size = xWS.cols();
91 double accumulated_s = 0.0;
92 Vec2d last_path_point(xWS(0, 0), xWS(1, 0));
93 for (size_t i = 0; i < xWS_size; ++i) {
94 Vec2d cur_path_point(xWS(0, i), xWS(1, i));
95 accumulated_s += cur_path_point.DistanceTo(last_path_point);
96 PathPoint path_point;
97 path_point.set_x(xWS(0, i));
98 path_point.set_y(xWS(1, i));
99 path_point.set_theta(xWS(2, i));
100 path_point.set_s(accumulated_s);
101 warm_start_path.push_back(std::move(path_point));
102 last_path_point = cur_path_point;
103 }
104
105 const double interpolated_delta_s =
108 std::vector<std::pair<double, double>> interpolated_warm_start_point2ds;
109 double path_length = warm_start_path.Length();
110 double delta_s = path_length / std::ceil(path_length / interpolated_delta_s);
111 path_length += delta_s * 1.0e-6;
112 for (double s = 0; s < path_length; s += delta_s) {
113 const auto point2d = warm_start_path.Evaluate(s);
114 interpolated_warm_start_point2ds.emplace_back(point2d.x(), point2d.y());
115 }
116
117 const size_t interpolated_size = interpolated_warm_start_point2ds.size();
118 if (interpolated_size < 4) {
119 AERROR <<
"interpolated_warm_start_path smaller than 4, can't enforce "
120 "heading continuity";
121 return false;
122 } else if (interpolated_size < 6) {
123 ADEBUG <<
"interpolated_warm_start_path smaller than 4, can't enforce "
124 "initial zero kappa";
125 enforce_initial_kappa_ = false;
126 } else {
127 enforce_initial_kappa_ = true;
128 }
129
130
131 AdjustStartEndHeading(xWS, &interpolated_warm_start_point2ds);
132
133
134 DiscretizedPath interpolated_warm_start_path;
135 if (!SetPathProfile(interpolated_warm_start_point2ds,
136 &interpolated_warm_start_path)) {
137 AERROR <<
"Set path profile fails";
138 return false;
139 }
140
141
142 std::vector<double> bounds;
143 if (!GenerateInitialBounds(interpolated_warm_start_path, &bounds)) {
144 AERROR <<
"Generate initial bounds failed, path point to close to obstacle";
145 return false;
146 }
147
148
149
150 input_colliding_point_index_.clear();
151 if (!CheckCollisionAvoidance(interpolated_warm_start_path,
152 &input_colliding_point_index_)) {
153 AERROR <<
"Interpolated input path points colliding with obstacle";
154
155
156
157
158 }
159
160 const auto path_smooth_start_timestamp = std::chrono::system_clock::now();
161
162
163 DiscretizedPath smoothed_path_points;
164 if (!SmoothPath(interpolated_warm_start_path, bounds,
165 &smoothed_path_points)) {
166 return false;
167 }
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190 const auto path_smooth_end_timestamp = std::chrono::system_clock::now();
191 std::chrono::duration<double> path_smooth_diff =
192 path_smooth_end_timestamp - path_smooth_start_timestamp;
193 ADEBUG <<
"iterative anchoring path smoother time: "
194 << path_smooth_diff.count() * 1000.0 << " ms.";
195
196 const auto speed_smooth_start_timestamp = std::chrono::system_clock::now();
197
198
199 SpeedData smoothed_speeds;
200 if (!SmoothSpeed(init_a, init_v, smoothed_path_points.Length(),
201 &smoothed_speeds)) {
202 return false;
203 }
204
205
206
207
208
209
210
211
212 const auto speed_smooth_end_timestamp = std::chrono::system_clock::now();
213 std::chrono::duration<double> speed_smooth_diff =
214 speed_smooth_end_timestamp - speed_smooth_start_timestamp;
215 ADEBUG <<
"iterative anchoring speed smoother time: "
216 << speed_smooth_diff.count() * 1000.0 << " ms.";
217
218
219 if (!CombinePathAndSpeed(smoothed_path_points, smoothed_speeds,
220 discretized_trajectory)) {
221 return false;
222 }
223
224 AdjustPathAndSpeedByGear(discretized_trajectory);
225
226 const auto end_timestamp = std::chrono::system_clock::now();
227 std::chrono::duration<double> diff = end_timestamp - start_timestamp;
228 ADEBUG <<
"iterative anchoring smoother total time: " << diff.count() * 1000.0
229 << " ms.";
230
231 ADEBUG <<
"discretized_trajectory size " << discretized_trajectory->size();
232 return true;
233}
optional double interpolated_delta_s
optional IterativeAnchoringConfig iterative_anchoring_smoother_config