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