55 {
56
57
58 const std::vector<std::vector<Vec2d>>& obstacles_vertices_vec =
59 open_space_info.obstacles_vertices_vec();
60 const std::vector<double>& XYbounds = open_space_info.ROI_xy_boundary();
61 const Eigen::MatrixXi& obstacles_edges_num =
62 open_space_info.obstacles_edges_num();
63 const Eigen::MatrixXd& obstacles_A = open_space_info.obstacles_A();
64 const Eigen::MatrixXd& obstacles_b = open_space_info.obstacles_b();
65
66 DiscretizedTrajectory warm_start_trajectory =
67 open_space_info.path_planning_trajectory_result();
68 const double origin_angle = open_space_info.origin_heading();
69 const Vec2d origin_point = open_space_info.origin_point();
70 for (size_t i = 0; i < warm_start_trajectory.size(); i++) {
71 double x = warm_start_trajectory[i].path_point().x();
72 double y = warm_start_trajectory[i].path_point().y();
73 double theta = warm_start_trajectory[i].path_point().theta();
75 origin_point,
76 &x,
77 &y,
78 &theta);
79 warm_start_trajectory[i].mutable_path_point()->set_x(x);
80 warm_start_trajectory[i].mutable_path_point()->set_y(y);
81 warm_start_trajectory[i].mutable_path_point()->set_theta(theta);
82 }
83
84
85 Eigen::MatrixXd xWS;
86 Eigen::MatrixXd uWS;
87 Eigen::MatrixXd state_result_ds;
88 Eigen::MatrixXd control_result_ds;
89 Eigen::MatrixXd time_result_ds;
90 Eigen::MatrixXd l_warm_up;
91 Eigen::MatrixXd n_warm_up;
92 Eigen::MatrixXd dual_l_result_ds;
93 Eigen::MatrixXd dual_n_result_ds;
94
95 if (FLAGS_enable_parallel_trajectory_smoothing) {
96 std::vector<DiscretizedTrajectory> partition_trajectories;
97
98 PartitionTrajectory(warm_start_trajectory, &partition_trajectories);
99
100 size_t size = partition_trajectories.size();
101 std::vector<Eigen::MatrixXd> xWS_vec;
102 std::vector<Eigen::MatrixXd> uWS_vec;
103 std::vector<Eigen::MatrixXd> state_result_ds_vec;
104 std::vector<Eigen::MatrixXd> control_result_ds_vec;
105 std::vector<Eigen::MatrixXd> time_result_ds_vec;
106 std::vector<Eigen::MatrixXd> l_warm_up_vec;
107 std::vector<Eigen::MatrixXd> n_warm_up_vec;
108 std::vector<Eigen::MatrixXd> dual_l_result_ds_vec;
109 std::vector<Eigen::MatrixXd> dual_n_result_ds_vec;
110 xWS_vec.resize(size);
111 uWS_vec.resize(size);
112 state_result_ds_vec.resize(size);
113 control_result_ds_vec.resize(size);
114 time_result_ds_vec.resize(size);
115 l_warm_up_vec.resize(size);
116 n_warm_up_vec.resize(size);
117 dual_l_result_ds_vec.resize(size);
118 dual_n_result_ds_vec.resize(size);
119
120
121 ADEBUG <<
"Trajectories size in smoother is " << size;
122 for (size_t i = 0; i < size; ++i) {
123 LoadTrajectoryInEigen(partition_trajectories[i], xWS_vec[i],
124 uWS_vec[i]);
125 Eigen::MatrixXd last_time_u(2, 1);
126 last_time_u << 0.0, 0.0;
127 double init_v = 0.0;
128
129
130 const auto smoother_start_timestamp = std::chrono::system_clock::now();
131 if (FLAGS_use_iterative_anchoring_smoother) {
132 AINFO <<
"use iterative anchoring smoother";
133 if (!GenerateDecoupledTraj(
134 xWS_vec[i], last_time_u(1, 0), init_v, obstacles_vertices_vec,
135 &state_result_ds_vec[i], &control_result_ds_vec[i],
136 &time_result_ds_vec[i])) {
137 AERROR <<
"Smoother fail at " << i <<
"th trajectory";
138 AERROR << i <<
"th trajectory size is " << xWS_vec[i].cols();
140 ErrorCode::PLANNING_ERROR,
141 "iterative anchoring smoothing problem failed to solve");
142 }
143 } else {
144 const double start_system_timestamp =
145 std::chrono::duration<double>(
146 std::chrono::system_clock::now().time_since_epoch())
147 .count();
148 AINFO <<
"use distance approach parallel smoother";
149 if (!GenerateDistanceApproachTraj(
150 xWS_vec[i], uWS_vec[i], XYbounds, obstacles_edges_num,
151 obstacles_A, obstacles_b, obstacles_vertices_vec, last_time_u,
152 init_v, &state_result_ds_vec[i], &control_result_ds_vec[i],
153 &time_result_ds_vec[i], &l_warm_up_vec[i], &n_warm_up_vec[i],
154 &dual_l_result_ds_vec[i], &dual_n_result_ds_vec[i])) {
155 AERROR <<
"Smoother fail at " << i
156 << "th trajectory with index starts from 0";
157 AERROR << i <<
"th trajectory size is " << xWS_vec[i].cols();
158 AERROR <<
"State matrix: " << xWS_vec[i];
159 AERROR <<
"Control matrix: " << uWS_vec[i];
160 return Status(ErrorCode::PLANNING_ERROR,
161 "distance approach smoothing problem failed to solve");
162 }
163 const auto end_system_timestamp =
164 std::chrono::duration<double>(
165 std::chrono::system_clock::now().time_since_epoch())
166 .count();
167 const auto time_diff_ms =
168 (end_system_timestamp - start_system_timestamp) * 1000;
169 ADEBUG <<
"total planning time spend: " << time_diff_ms <<
" ms.";
170 ADEBUG << i <<
"th trajectory size is " << xWS_vec[i].cols();
171 ADEBUG <<
"average time spend: " << time_diff_ms / xWS_vec[i].cols()
172 << " ms per point.";
173 ADEBUG <<
"average time spend after smooth: "
174 << time_diff_ms / state_result_ds_vec[i].cols()
175 << " ms per point.";
176 ADEBUG << i <<
"th smoothed trajectory size is "
177 << state_result_ds_vec[i].cols();
178 }
179 const auto smoother_end_timestamp = std::chrono::system_clock::now();
180 std::chrono::duration<double> smoother_diff =
181 smoother_end_timestamp - smoother_start_timestamp;
182 AINFO <<
"Open space trajectory smoothing total time: "
183 << smoother_diff.count() * 1000.0 << " ms at the " << i
184 << "th trajectory.";
185 AINFO <<
"The " << i <<
"th trajectory pre-smoothing size is "
186 << xWS_vec[i].cols() << "; post-smoothing size is "
187 << state_result_ds_vec[i].cols();
188 }
189
190
191 CombineTrajectories(xWS_vec, uWS_vec, state_result_ds_vec,
192 control_result_ds_vec, time_result_ds_vec,
193 l_warm_up_vec, n_warm_up_vec, dual_l_result_ds_vec,
194 dual_n_result_ds_vec, &xWS, &uWS, &state_result_ds,
195 &control_result_ds, &time_result_ds, &l_warm_up,
196 &n_warm_up, &dual_l_result_ds, &dual_n_result_ds);
197
198 } else {
199 AINFO <<
"use distance approach smoother";
200 LoadTrajectoryInEigen(warm_start_trajectory, xWS, uWS);
201
202 Eigen::MatrixXd last_time_u(2, 1);
203 last_time_u << 0, 0;
204
205 const double init_v = 0;
206 FLAGS_use_iterative_anchoring_smoother = false;
207 if (!GenerateDistanceApproachTraj(
208 xWS, uWS, XYbounds, obstacles_edges_num, obstacles_A, obstacles_b,
209 obstacles_vertices_vec, last_time_u, init_v, &state_result_ds,
210 &control_result_ds, &time_result_ds, &l_warm_up, &n_warm_up,
211 &dual_l_result_ds, &dual_n_result_ds)) {
212 return Status(ErrorCode::PLANNING_ERROR,
213 "distance approach smoothing problem failed to solve");
214 }
215 }
216
217
218 if (FLAGS_enable_record_debug) {
219 open_space_debug_.Clear();
220 RecordDebugInfo(origin_point, origin_angle,
221 open_space_info.open_space_end_pose(),
222 xWS, uWS, l_warm_up, n_warm_up, dual_l_result_ds,
223 dual_n_result_ds, state_result_ds, control_result_ds,
224 time_result_ds, XYbounds, obstacles_vertices_vec);
225 }
226
227
228 size_t state_size = state_result_ds.cols();
229 for (size_t i = 0; i < state_size; ++i) {
231 origin_angle, origin_point,
232 &(state_result_ds(0, i)), &(state_result_ds(1, i)),
233 &(state_result_ds(2, i)));
234 }
235
236 LoadTrajectory(state_result_ds, control_result_ds, time_result_ds);
237
238
239
240
241
242
243
245}
static Status OK()
generate a success status.
static void PathPointNormalizing(double rotate_angle, const common::math::Vec2d &translate_origin, double *x, double *y, double *phi)
static void PathPointDeNormalizing(double rotate_angle, const common::math::Vec2d &translate_origin, double *x, double *y, double *phi)