Piecewise jerk path optimizer.
102 {
103
104 const auto& lat_boundaries = path_boundary.boundary();
105 const size_t kNumKnots = lat_boundaries.size();
106 AINFO <<
"kNumKnots: " << kNumKnots;
107
108 double delta_s = path_boundary.delta_s();
109 PiecewiseJerkPathProblem piecewise_jerk_problem(kNumKnots, delta_s,
110 init_state.second);
111
112 const auto& adc_vertex_constraints = path_boundary.adc_vertex_bound();
113 const auto& extra_bound = path_boundary.extra_path_bound();
114
115 std::vector<double> towing_l_ref;
116 for (auto& path_boundary_pt : path_boundary) {
117 towing_l_ref.emplace_back(path_boundary_pt.towing_l);
118 }
119 PrintCurves print_curve;
120 for (size_t i = 0; i < adc_vertex_constraints.size(); i++) {
121 print_curve.AddPoint(path_boundary.label() + "_vertex_l_lower",
122 adc_vertex_constraints[i].rear_axle_s,
123 adc_vertex_constraints[i].lower_bound);
124 print_curve.AddPoint(path_boundary.label() + "_vertex_l_upper",
125 adc_vertex_constraints[i].rear_axle_s,
126 adc_vertex_constraints[i].upper_bound);
127 }
128 for (size_t i = 0; i < extra_bound.size(); i++) {
129 print_curve.AddPoint(path_boundary.label() + "_conner_l_lower",
130 extra_bound[i].rear_axle_s,
131 extra_bound[i].lower_bound);
132 print_curve.AddPoint(path_boundary.label() + "_conner_l_upper",
133 extra_bound[i].rear_axle_s,
134 extra_bound[i].upper_bound);
135 }
136
137
138
139 for (size_t i = 0; i < kNumKnots; i++) {
140 double s = i * path_boundary.delta_s() + path_boundary.start_s();
141 print_curve.AddPoint(path_boundary.label() + "_ref_l", s, l_ref[i]);
142 print_curve.AddPoint(path_boundary.label() + "_towing_ref_l", s,
143 towing_l_ref[i]);
144 print_curve.AddPoint(path_boundary.label() + "_ref_l_weight", s,
145 l_ref_weight[i]);
146 print_curve.AddPoint(path_boundary.label() + "_l_lower", s,
147 lat_boundaries[i].first);
148 print_curve.AddPoint(path_boundary.label() + "_l_upper", s,
149 lat_boundaries[i].second);
150 print_curve.AddPoint(path_boundary.label() + "_ddl_lower", s,
151 ddl_bounds[i].first);
152 print_curve.AddPoint(path_boundary.label() + "_ddl_upper", s,
153 ddl_bounds[i].second);
154 }
155 print_curve.AddPoint(path_boundary.label() + "_opt_l",
156 path_boundary.start_s(), init_state.second[0]);
157 print_curve.AddPoint(path_boundary.label() + "_opt_dl",
158 path_boundary.start_s(), init_state.second[1]);
159 print_curve.AddPoint(path_boundary.label() + "_opt_ddl",
160 path_boundary.start_s(), init_state.second[2]);
161
162 std::array<double, 3U> end_state_weight = {config.weight_end_state_l(),
163 config.weight_end_state_dl(),
164 config.weight_end_state_ddl()};
165 piecewise_jerk_problem.set_end_state_ref(end_state_weight, end_state);
166 piecewise_jerk_problem.set_x_ref(std::move(l_ref_weight), l_ref);
167 piecewise_jerk_problem.set_towing_x_ref(config.l_weight(), towing_l_ref);
168
169
170 piecewise_jerk_problem.set_weight_x(config.l_weight());
171 piecewise_jerk_problem.set_weight_dx(config.dl_weight());
172 piecewise_jerk_problem.set_weight_ddx(config.ddl_weight());
173 piecewise_jerk_problem.set_weight_dddx(config.dddl_weight());
174
175 piecewise_jerk_problem.set_scale_factor({1.0, 10.0, 100.0});
176 piecewise_jerk_problem.set_extra_constraints(extra_bound);
177 piecewise_jerk_problem.set_vertex_constraints(adc_vertex_constraints);
178 auto start_time = std::chrono::system_clock::now();
179
180 piecewise_jerk_problem.set_x_bounds(lat_boundaries);
181 piecewise_jerk_problem.set_dx_bounds(
182 -config.lateral_derivative_bound_default(),
183 config.lateral_derivative_bound_default());
184 piecewise_jerk_problem.set_ddx_bounds(ddl_bounds);
185
186 piecewise_jerk_problem.set_dddx_bound(dddl_bound);
187
188 bool success = piecewise_jerk_problem.Optimize(config.max_iteration());
189
190 auto end_time = std::chrono::system_clock::now();
191 std::chrono::duration<double>
diff = end_time - start_time;
192 ADEBUG <<
"Path Optimizer used time: " <<
diff.count() * 1000 <<
" ms.";
193
194 if (!success) {
195 AERROR << path_boundary.label() <<
"piecewise jerk path optimizer failed";
196 AINFO <<
"init s(" << init_state.first[0] <<
"," << init_state.first[1]
197 << "," << init_state.first[2] << ") l (" << init_state.second[0]
198 << "," << init_state.second[1] << "," << init_state.second[2];
199 AINFO <<
"dx bound" << config.lateral_derivative_bound_default();
200 AINFO <<
"jerk bound" << dddl_bound;
201 print_curve.PrintToLog();
202 return false;
203 }
204
205 *x = piecewise_jerk_problem.opt_x();
206 *dx = piecewise_jerk_problem.opt_dx();
207 *ddx = piecewise_jerk_problem.opt_ddx();
208 PrintBox print_box("opt_l_box");
209 for (size_t i = 0; i < kNumKnots; i++) {
210 double s = i * path_boundary.delta_s() + path_boundary.start_s();
211 print_curve.AddPoint(path_boundary.label() + "_opt_l", s, (*x)[i]);
212 print_curve.AddPoint(path_boundary.label() + "_opt_dl", s, (*dx)[i]);
213 print_curve.AddPoint(path_boundary.label() + "_opt_ddl", s, (*ddx)[i]);
214 print_box.AddAdcBox(s, (*x)[i], std::atan((*dx)[i]), true);
215 }
216 print_curve.PrintToLog();
217
218 return true;
219}
float diff(Image< float > *I, int x1, int y1, int x2, int y2)
Dissimilarity measure between pixels