27 const Eigen::MatrixXd& ego,
28 const Eigen::MatrixXd& xWS,
29 const Eigen::MatrixXd& uWS,
30 const Eigen::MatrixXd& l_warm_up,
31 const Eigen::MatrixXd& n_warm_up,
32 const Eigen::MatrixXd& x0,
33 const Eigen::MatrixXd& xf,
34 const Eigen::MatrixXd& last_time_u,
35 const std::vector<double>& XYbounds,
36 const Eigen::MatrixXi& obstacles_edges_num,
37 const size_t obstacles_num,
38 const Eigen::MatrixXd& obstacles_A,
39 const Eigen::MatrixXd& obstacles_b,
45 l_warm_up_(l_warm_up),
46 n_warm_up_(n_warm_up),
49 last_time_u_(last_time_u),
51 obstacles_edges_num_(obstacles_edges_num),
52 obstacles_A_(obstacles_A),
53 obstacles_b_(obstacles_b) {
54 ACHECK(horizon < std::numeric_limits<int>::max()) <<
"Invalid cast on horizon in open space planner";
55 horizon_ =
static_cast<int>(horizon);
56 ACHECK(obstacles_num < std::numeric_limits<int>::max()) <<
"Invalid cast on obstacles_num in open space planner";
58 obstacles_num_ =
static_cast<int>(obstacles_num);
59 w_ev_ = ego_(1, 0) + ego_(3, 0);
60 l_ev_ = ego_(0, 0) + ego_(2, 0);
61 g_ = {l_ev_ / 2, w_ev_ / 2, l_ev_ / 2, w_ev_ / 2};
62 offset_ = (ego_(0, 0) + ego_(2, 0)) / 2 - ego_(2, 0);
63 obstacles_edges_sum_ = obstacles_edges_num_.sum();
64 state_result_ = Eigen::MatrixXd::Zero(4, horizon_ + 1);
65 dual_l_result_ = Eigen::MatrixXd::Zero(obstacles_edges_sum_, horizon_ + 1);
66 dual_n_result_ = Eigen::MatrixXd::Zero(4 * obstacles_num_, horizon_ + 1);
67 control_result_ = Eigen::MatrixXd::Zero(2, horizon_ + 1);
68 time_result_ = Eigen::MatrixXd::Zero(1, horizon_ + 1);
69 state_start_index_ = 0;
70 control_start_index_ = 4 * (horizon_ + 1);
71 time_start_index_ = control_start_index_ + 2 * horizon_;
72 l_start_index_ = time_start_index_;
73 n_start_index_ = l_start_index_ + obstacles_edges_sum_ * (horizon_ + 1);
75 planner_open_space_config_ = planner_open_space_config;
76 distance_approach_config_ = planner_open_space_config_.distance_approach_config();
77 weight_state_x_ = distance_approach_config_.
weight_x();
78 weight_state_y_ = distance_approach_config_.
weight_y();
79 weight_state_phi_ = distance_approach_config_.
weight_phi();
80 weight_state_v_ = distance_approach_config_.
weight_v();
81 weight_input_steer_ = distance_approach_config_.
weight_steer();
82 weight_input_a_ = distance_approach_config_.
weight_a();
98 use_fix_time_ = distance_approach_config_.
use_fix_time();
104 const size_t horizon,
106 const Eigen::MatrixXd& ego,
107 const Eigen::MatrixXd& xWS,
108 const Eigen::MatrixXd& uWS,
109 const Eigen::MatrixXd& l_warm_up,
110 const Eigen::MatrixXd& n_warm_up,
111 const Eigen::MatrixXd& x0,
112 const Eigen::MatrixXd& xf,
113 const Eigen::MatrixXd& last_time_u,
114 const std::vector<double>& XYbounds,
115 const Eigen::MatrixXi& obstacles_edges_num,
116 const size_t obstacles_num,
117 const Eigen::MatrixXd& obstacles_A,
118 const Eigen::MatrixXd& obstacles_b,
124 l_warm_up_(l_warm_up),
125 n_warm_up_(n_warm_up),
128 last_time_u_(last_time_u),
130 obstacles_edges_num_(obstacles_edges_num),
131 obstacles_A_(obstacles_A),
132 obstacles_b_(obstacles_b),
133 distance_approach_config_(distance_approach_config) {
134 ACHECK(horizon < std::numeric_limits<int>::max()) <<
"Invalid cast on horizon in open space planner";
135 horizon_ =
static_cast<int>(horizon);
136 ACHECK(obstacles_num < std::numeric_limits<int>::max()) <<
"Invalid cast on obstacles_num in open space planner";
138 obstacles_num_ =
static_cast<int>(obstacles_num);
139 w_ev_ = ego_(1, 0) + ego_(3, 0);
140 l_ev_ = ego_(0, 0) + ego_(2, 0);
141 g_ = {l_ev_ / 2, w_ev_ / 2, l_ev_ / 2, w_ev_ / 2};
142 offset_ = (ego_(0, 0) + ego_(2, 0)) / 2 - ego_(2, 0);
143 obstacles_edges_sum_ = obstacles_edges_num_.sum();
144 state_result_ = Eigen::MatrixXd::Zero(4, horizon_ + 1);
145 dual_l_result_ = Eigen::MatrixXd::Zero(obstacles_edges_sum_, horizon_ + 1);
146 dual_n_result_ = Eigen::MatrixXd::Zero(4 * obstacles_num_, horizon_ + 1);
147 control_result_ = Eigen::MatrixXd::Zero(2, horizon_ + 1);
148 time_result_ = Eigen::MatrixXd::Zero(1, horizon_ + 1);
149 state_start_index_ = 0;
150 control_start_index_ = 4 * (horizon_ + 1);
151 time_start_index_ = control_start_index_ + 2 * horizon_;
152 l_start_index_ = time_start_index_;
153 n_start_index_ = l_start_index_ + obstacles_edges_sum_ * (horizon_ + 1);
155 weight_state_x_ = distance_approach_config_.
weight_x();
156 weight_state_y_ = distance_approach_config_.
weight_y();
157 weight_state_phi_ = distance_approach_config_.
weight_phi();
158 weight_state_v_ = distance_approach_config_.
weight_v();
159 weight_input_steer_ = distance_approach_config_.
weight_steer();
160 weight_input_a_ = distance_approach_config_.
weight_a();
176 use_fix_time_ = distance_approach_config_.
use_fix_time();
186 IndexStyleEnum& index_style) {
189 int n1 = 4 * (horizon_ + 1);
192 int n2 = 2 * horizon_;
195 lambda_horizon_ = obstacles_edges_num_.sum() * (horizon_ + 1);
196 ADEBUG <<
"lambda_horizon_: " << lambda_horizon_;
198 miu_horizon_ = obstacles_num_ * 4 * (horizon_ + 1);
199 ADEBUG <<
"miu_horizon_: " << miu_horizon_;
202 int m1 = 4 * horizon_;
208 int m4 = 4 * obstacles_num_ * (horizon_ + 1);
211 num_of_variables_ = n1 + n2 + lambda_horizon_ + miu_horizon_;
212 num_of_constraints_ = m1 + m2 + m4 + (num_of_variables_ - (horizon_ + 1) + 2);
215 n = num_of_variables_;
216 ADEBUG <<
"num_of_variables_ " << num_of_variables_;
218 m = num_of_constraints_;
219 ADEBUG <<
"num_of_constraints_ " << num_of_constraints_;
223 index_style = IndexStyleEnum::C_STYLE;
234 ADEBUG <<
"get_bounds_info";
235 ACHECK(XYbounds_.size() == 4) <<
"XYbounds_ size is not 4, but" << XYbounds_.size();
240 int variable_index = 0;
241 for (
int i = 0; i < 4; ++i) {
248 for (
int i = 1; i < horizon_; ++i) {
250 x_l[variable_index] = -2e19;
251 x_u[variable_index] = 2e19;
254 x_l[variable_index + 1] = -2e19;
255 x_u[variable_index + 1] = 2e19;
258 x_l[variable_index + 2] = -2e19;
259 x_u[variable_index + 2] = 2e19;
262 x_l[variable_index + 3] = -2e19;
263 x_u[variable_index + 3] = 2e19;
269 for (
int i = 0; i < 4; ++i) {
270 x_l[variable_index + i] = -2e19;
271 x_u[variable_index + i] = 2e19;
274 ADEBUG <<
"variable_index after adding state variables : " << variable_index;
277 for (
int i = 0; i < horizon_; ++i) {
279 x_l[variable_index] = -2e19;
280 x_u[variable_index] = 2e19;
283 x_l[variable_index + 1] = -2e19;
284 x_u[variable_index + 1] = 2e19;
288 ADEBUG <<
"variable_index after adding control variables : " << variable_index;
292 for (
int i = 0; i < horizon_ + 1; ++i) {
293 for (
int j = 0; j < obstacles_edges_sum_; ++j) {
294 x_l[variable_index] = 0.0;
295 x_u[variable_index] = 2e19;
299 ADEBUG <<
"variable_index after adding lagrange l : " << variable_index;
302 for (
int i = 0; i < horizon_ + 1; ++i) {
303 for (
int j = 0; j < 4 * obstacles_num_; ++j) {
304 x_l[variable_index] = 0.0;
305 x_u[variable_index] = 2e19;
310 ADEBUG <<
"variable_index after adding lagrange n : " << variable_index;
316 int constraint_index = 0;
317 for (
int i = 0; i < 4 * horizon_; ++i) {
321 constraint_index += 4 * horizon_;
323 ADEBUG <<
"constraint_index after adding Euler forward dynamics constraints: " << constraint_index;
327 for (
int i = 0; i < horizon_; ++i) {
328 g_l[constraint_index] = -max_steer_rate_;
329 g_u[constraint_index] = max_steer_rate_;
333 ADEBUG <<
"constraint_index after adding steering rate constraints: " << constraint_index;
337 for (
int i = 0; i < horizon_ + 1; ++i) {
338 for (
int j = 0; j < obstacles_num_; ++j) {
340 g_l[constraint_index] = -2e19;
341 g_u[constraint_index] = 1.0;
344 g_l[constraint_index + 1] = 0.0;
345 g_u[constraint_index + 1] = 0.0;
346 g_l[constraint_index + 2] = 0.0;
347 g_u[constraint_index + 2] = 0.0;
350 g_l[constraint_index + 3] = min_safety_distance_;
351 g_u[constraint_index + 3] = 2e19;
352 constraint_index += 4;
355 ADEBUG <<
"constraints_index after adding obstacles related constraints: " << constraint_index;
359 g_l[constraint_index] = x0_(0, 0);
360 g_u[constraint_index] = x0_(0, 0);
361 g_l[constraint_index + 1] = x0_(1, 0);
362 g_u[constraint_index + 1] = x0_(1, 0);
363 g_l[constraint_index + 2] = x0_(2, 0);
364 g_u[constraint_index + 2] = x0_(2, 0);
365 g_l[constraint_index + 3] = x0_(3, 0);
366 g_u[constraint_index + 3] = x0_(3, 0);
367 constraint_index += 4;
369 for (
int i = 1; i < horizon_; ++i) {
370 g_l[constraint_index] = XYbounds_[0];
371 g_u[constraint_index] = XYbounds_[1];
372 g_l[constraint_index + 1] = XYbounds_[2];
373 g_u[constraint_index + 1] = XYbounds_[3];
374 g_l[constraint_index + 2] = -max_speed_reverse_;
375 g_u[constraint_index + 2] = max_speed_forward_;
376 constraint_index += 3;
380 g_l[constraint_index] = xf_(0, 0);
381 g_u[constraint_index] = xf_(0, 0);
382 g_l[constraint_index + 1] = xf_(1, 0);
383 g_u[constraint_index + 1] = xf_(1, 0);
384 g_l[constraint_index + 2] = xf_(2, 0);
385 g_u[constraint_index + 2] = xf_(2, 0);
386 g_l[constraint_index + 3] = xf_(3, 0);
387 g_u[constraint_index + 3] = xf_(3, 0);
388 constraint_index += 4;
390 for (
int i = 0; i < horizon_; ++i) {
391 g_l[constraint_index] = -max_steer_angle_;
392 g_u[constraint_index] = max_steer_angle_;
393 g_l[constraint_index + 1] = -max_acceleration_reverse_;
394 g_u[constraint_index + 1] = max_acceleration_forward_;
395 constraint_index += 2;
398 for (
int i = 0; i < lambda_horizon_; ++i) {
399 g_l[constraint_index] = 0.0;
400 g_u[constraint_index] = 2e19;
404 for (
int i = 0; i < miu_horizon_; ++i) {
405 g_l[constraint_index] = 0.0;
406 g_u[constraint_index] = 2e19;
410 ADEBUG <<
"constraint_index after adding obstacles constraints: " << constraint_index;
411 ADEBUG <<
"get_bounds_info_ out";
425 ADEBUG <<
"get_starting_point";
426 ACHECK(init_x) <<
"Warm start init_x setting failed";
428 CHECK_EQ(horizon_, uWS_.cols());
429 CHECK_EQ(horizon_ + 1, xWS_.cols());
432 for (
int i = 0; i < horizon_ + 1; ++i) {
434 for (
int j = 0; j < 4; ++j) {
435 x[index + j] = xWS_(j, i);
440 for (
int i = 0; i < horizon_; ++i) {
442 x[control_start_index_ + index] = uWS_(0, i);
443 x[control_start_index_ + index + 1] = uWS_(1, i);
447 for (
int i = 0; i < horizon_ + 1; ++i) {
448 int index = i * obstacles_edges_sum_;
449 for (
int j = 0; j < obstacles_edges_sum_; ++j) {
450 x[l_start_index_ + index + j] = l_warm_up_(j, i);
455 for (
int i = 0; i < horizon_ + 1; ++i) {
456 int index = i * 4 * obstacles_num_;
457 for (
int j = 0; j < 4 * obstacles_num_; ++j) {
458 x[n_start_index_ + index + j] = n_warm_up_(j, i);
462 if (enable_constraint_check_) {
465 ADEBUG <<
"initial points constraint checking";
470 ADEBUG <<
"get_starting_point out";
480 gradient(
tag_f, n, x, grad_f);
486 if (enable_constraint_check_) {
501 if (values ==
nullptr) {
503 for (
int idx = 0; idx < nnz_jac; idx++) {
504 iRow[idx] = rind_g[idx];
505 jCol[idx] = cind_g[idx];
509 sparse_jac(
tag_g, m, n, 1, x, &nnz_jac, &rind_g, &cind_g, &jacval, options_g);
510 for (
int idx = 0; idx < nnz_jac; idx++) {
511 values[idx] = jacval[idx];
527 AERROR <<
"NOT VALID NOW";
537 const double* lambda,
543 if (values ==
nullptr) {
547 for (
int idx = 0; idx < nnz_L; idx++) {
548 iRow[idx] = rind_L[idx];
549 jCol[idx] = cind_L[idx];
555 obj_lam[0] = obj_factor;
557 for (
int idx = 0; idx < m; idx++) {
558 obj_lam[1 + idx] = lambda[idx];
561 set_param_vec(
tag_L, m + 1, obj_lam);
562 sparse_hess(
tag_L, n, 1,
const_cast<double*
>(x), &nnz_L, &rind_L, &cind_L, &hessval, options_L);
564 for (
int idx = 0; idx < nnz_L; idx++) {
565 values[idx] = hessval[idx];
573 Ipopt::SolverReturn status,
580 const double* lambda,
582 const Ipopt::IpoptData* ip_data,
583 Ipopt::IpoptCalculatedQuantities* ip_cq) {
584 int state_index = state_start_index_;
585 int control_index = control_start_index_;
587 int dual_l_index = l_start_index_;
588 int dual_n_index = n_start_index_;
591 if (enable_constraint_check_) {
592 ADEBUG <<
"final resolution constraint checking";
600 for (
int i = 0; i < horizon_; ++i) {
601 state_result_(0, i) = x[state_index];
602 state_result_(1, i) = x[state_index + 1];
603 state_result_(2, i) = x[state_index + 2];
604 state_result_(3, i) = x[state_index + 3];
605 control_result_(0, i) = x[control_index];
606 control_result_(1, i) = x[control_index + 1];
607 time_result_(0, i) = ts_;
608 for (
int j = 0; j < obstacles_edges_sum_; ++j) {
609 dual_l_result_(j, i) = x[dual_l_index + j];
611 for (
int k = 0; k < 4 * obstacles_num_; k++) {
612 dual_n_result_(k, i) = x[dual_n_index + k];
617 dual_l_index += obstacles_edges_sum_;
618 dual_n_index += 4 * obstacles_num_;
620 state_result_(0, 0) = x0_(0, 0);
621 state_result_(1, 0) = x0_(1, 0);
622 state_result_(2, 0) = x0_(2, 0);
623 state_result_(3, 0) = x0_(3, 0);
625 state_result_(0, horizon_) = xf_(0, 0);
626 state_result_(1, horizon_) = xf_(1, 0);
627 state_result_(2, horizon_) = xf_(2, 0);
628 state_result_(3, horizon_) = xf_(3, 0);
629 time_result_(0, horizon_) = ts_;
631 for (
int j = 0; j < obstacles_edges_sum_; ++j) {
632 dual_l_result_(j, horizon_) = x[dual_l_index + j];
634 for (
int k = 0; k < 4 * obstacles_num_; k++) {
635 dual_n_result_(k, horizon_) = x[dual_n_index + k];
648 Eigen::MatrixXd* state_result,
649 Eigen::MatrixXd* control_result,
650 Eigen::MatrixXd* time_result,
651 Eigen::MatrixXd* dual_l_result,
652 Eigen::MatrixXd* dual_n_result)
const {
653 ADEBUG <<
"get_optimization_results";
654 *state_result = state_result_;
655 *control_result = control_result_;
656 *time_result = time_result_;
657 *dual_l_result = dual_l_result_;
658 *dual_n_result = dual_n_result_;
663 CHECK_EQ(state_result_.cols(), xWS_.cols());
664 CHECK_EQ(state_result_.rows(), xWS_.rows());
665 double state_diff_max = 0.0;
666 for (
int i = 0; i < horizon_ + 1; ++i) {
667 for (
int j = 0; j < 4; ++j) {
668 state_diff_max = std::max(std::abs(xWS_(j, i) - state_result_(j, i)), state_diff_max);
673 CHECK_EQ(control_result_.rows(), uWS_.rows());
674 double control_diff_max = 0.0;
675 for (
int i = 0; i < horizon_; ++i) {
676 control_diff_max = std::max(std::abs(uWS_(0, i) - control_result_(0, i)), control_diff_max);
677 control_diff_max = std::max(std::abs(uWS_(1, i) - control_result_(1, i)), control_diff_max);
681 CHECK_EQ(dual_l_result_.cols(), l_warm_up_.cols());
682 CHECK_EQ(dual_l_result_.rows(), l_warm_up_.rows());
683 double l_diff_max = 0.0;
684 for (
int i = 0; i < horizon_ + 1; ++i) {
685 for (
int j = 0; j < obstacles_edges_sum_; ++j) {
686 l_diff_max = std::max(std::abs(l_warm_up_(j, i) - dual_l_result_(j, i)), l_diff_max);
691 CHECK_EQ(n_warm_up_.cols(), dual_n_result_.cols());
692 CHECK_EQ(n_warm_up_.rows(), dual_n_result_.rows());
693 double n_diff_max = 0.0;
694 for (
int i = 0; i < horizon_ + 1; ++i) {
695 for (
int j = 0; j < 4 * obstacles_num_; ++j) {
696 n_diff_max = std::max(std::abs(n_warm_up_(j, i) - dual_n_result_(j, i)), n_diff_max);
700 ADEBUG <<
"state_diff_max: " << state_diff_max;
701 ADEBUG <<
"control_diff_max: " << control_diff_max;
702 ADEBUG <<
"dual_l_diff_max: " << l_diff_max;
703 ADEBUG <<
"dual_n_diff_max: " << n_diff_max;
714 DCHECK(ts_ != 0) <<
"ts in distance_approach_ is 0";
715 int control_index = control_start_index_;
717 int state_index = state_start_index_;
724 for (
int i = 0; i < horizon_ + 1; ++i) {
725 T x1_diff = x[state_index] - xWS_(0, i);
726 T x2_diff = x[state_index + 1] - xWS_(1, i);
727 T x3_diff = x[state_index + 2] - xWS_(2, i);
728 T x4_abs = x[state_index + 3];
729 *obj_value += weight_state_x_ * x1_diff * x1_diff + weight_state_y_ * x2_diff * x2_diff
730 + weight_state_phi_ * x3_diff * x3_diff + weight_state_v_ * x4_abs * x4_abs;
735 for (
int i = 0; i < horizon_; ++i) {
736 *obj_value += weight_input_steer_ * x[control_index] * x[control_index]
737 + weight_input_a_ * x[control_index + 1] * x[control_index + 1];
742 control_index = control_start_index_;
743 T last_time_steer_rate = (x[control_index] - last_time_u_(0, 0)) / ts_;
744 T last_time_a_rate = (x[control_index + 1] - last_time_u_(1, 0)) / ts_;
746 *obj_value += weight_stitching_steer_ * last_time_steer_rate * last_time_steer_rate
747 + weight_stitching_a_ * last_time_a_rate * last_time_a_rate;
750 for (
int i = 0; i < horizon_ - 1; ++i) {
751 T steering_rate = (x[control_index + 2] - x[control_index]) / ts_;
752 T a_rate = (x[control_index + 3] - x[control_index + 1]) / ts_;
753 *obj_value += weight_rate_steer_ * steering_rate * steering_rate + weight_rate_a_ * a_rate * a_rate;
761 int state_index = state_start_index_;
764 int control_index = control_start_index_;
769 int constraint_index = 0;
773 for (
int i = 0; i < horizon_; ++i) {
786 = x[state_index + 4] - (x[state_index] + ts_ * x[state_index + 3] * cos(x[state_index + 2]));
799 g[constraint_index + 1]
800 = x[state_index + 5] - (x[state_index + 1] + ts_ * x[state_index + 3] * sin(x[state_index + 2]));
815 g[constraint_index + 2] = x[state_index + 6]
816 - (x[state_index + 2] + ts_ * x[state_index + 3] * tan(x[control_index]) / wheelbase_);
824 g[constraint_index + 3] = x[state_index + 7] - (x[state_index + 3] + ts_ * x[control_index + 1]);
827 constraint_index += 4;
831 ADEBUG <<
"constraint_index after adding Euler forward dynamics constraints "
837 control_index = control_start_index_;
840 g[constraint_index] = (x[control_index] - last_time_u_(0, 0)) / ts_;
844 for (
int i = 1; i < horizon_; ++i) {
845 g[constraint_index] = (x[control_index] - x[control_index - 2]) / ts_;
852 state_index = state_start_index_;
853 int l_index = l_start_index_;
854 int n_index = n_start_index_;
856 for (
int i = 0; i < horizon_ + 1; ++i) {
857 int edges_counter = 0;
858 for (
int j = 0; j < obstacles_num_; ++j) {
859 int current_edges_num = obstacles_edges_num_(j, 0);
860 Eigen::MatrixXd Aj = obstacles_A_.block(edges_counter, 0, current_edges_num, 2);
861 Eigen::MatrixXd bj = obstacles_b_.block(edges_counter, 0, current_edges_num, 1);
866 for (
int k = 0; k < current_edges_num; ++k) {
868 tmp1 += Aj(k, 0) * x[l_index + k];
869 tmp2 += Aj(k, 1) * x[l_index + k];
871 g[constraint_index] = tmp1 * tmp1 + tmp2 * tmp2;
874 g[constraint_index + 1]
875 = x[n_index] - x[n_index + 2] + cos(x[state_index + 2]) * tmp1 + sin(x[state_index + 2]) * tmp2;
877 g[constraint_index + 2]
878 = x[n_index + 1] - x[n_index + 3] - sin(x[state_index + 2]) * tmp1 + cos(x[state_index + 2]) * tmp2;
882 for (
int k = 0; k < 4; ++k) {
883 tmp3 += -g_[k] * x[n_index + k];
887 for (
int k = 0; k < current_edges_num; ++k) {
888 tmp4 += bj(k, 0) * x[l_index + k];
891 g[constraint_index + 3] = tmp3 + (x[state_index] + cos(x[state_index + 2]) * offset_) * tmp1
892 + (x[state_index + 1] + sin(x[state_index + 2]) * offset_) * tmp2 - tmp4;
895 edges_counter += current_edges_num;
896 l_index += current_edges_num;
898 constraint_index += 4;
902 ADEBUG <<
"constraint_index after obstacles avoidance constraints "
907 state_index = state_start_index_;
908 control_index = control_start_index_;
910 l_index = l_start_index_;
911 n_index = n_start_index_;
914 g[constraint_index] = x[state_index];
915 g[constraint_index + 1] = x[state_index + 1];
916 g[constraint_index + 2] = x[state_index + 2];
917 g[constraint_index + 3] = x[state_index + 3];
918 constraint_index += 4;
922 for (
int i = 1; i < horizon_; ++i) {
923 g[constraint_index] = x[state_index];
924 g[constraint_index + 1] = x[state_index + 1];
925 g[constraint_index + 2] = x[state_index + 3];
926 constraint_index += 3;
931 g[constraint_index] = x[state_index];
932 g[constraint_index + 1] = x[state_index + 1];
933 g[constraint_index + 2] = x[state_index + 2];
934 g[constraint_index + 3] = x[state_index + 3];
935 constraint_index += 4;
938 for (
int i = 0; i < horizon_; ++i) {
939 g[constraint_index] = x[control_index];
940 g[constraint_index + 1] = x[control_index + 1];
941 constraint_index += 2;
945 for (
int i = 0; i < lambda_horizon_; ++i) {
946 g[constraint_index] = x[l_index];
951 for (
int i = 0; i < miu_horizon_; ++i) {
952 g[constraint_index] = x[n_index];
968 const double delta_v = 1e-4;
969 for (
int idx = 0; idx < n; ++idx) {
970 x_u_tmp[idx] = x_u_tmp[idx] + delta_v;
971 x_l_tmp[idx] = x_l_tmp[idx] - delta_v;
972 if (x[idx] > x_u_tmp[idx] || x[idx] < x_l_tmp[idx]) {
973 AINFO <<
"x idx unfeasible: " << idx <<
", x: " << x[idx] <<
", lower: " << x_l_tmp[idx]
974 <<
", upper: " << x_u_tmp[idx];
979 int m1 = 4 * horizon_;
982 int m2 = m1 + horizon_;
988 int m4 = m3 + 4 * obstacles_num_ * (horizon_ + 1);
995 int m6 = m5 + 3 * (horizon_ - 1);
1001 int m8 = m7 + 2 * horizon_;
1007 int m10 = m9 + lambda_horizon_;
1010 int m11 = m10 + miu_horizon_;
1012 CHECK_EQ(m11, num_of_constraints_);
1014 AINFO <<
"dynamics constatins to: " << m1;
1015 AINFO <<
"control rate constraints (only steering) to: " << m2;
1016 AINFO <<
"sampling time equality constraints to: " << m3;
1017 AINFO <<
"obstacle constraints to: " << m4;
1018 AINFO <<
"start conf constraints to: " << m5;
1019 AINFO <<
"constraints on x,y,v to: " << m6;
1020 AINFO <<
"end constraints to: " << m7;
1021 AINFO <<
"control bnd to: " << m8;
1022 AINFO <<
"time interval constraints to: " << m9;
1023 AINFO <<
"lambda constraints to: " << m10;
1024 AINFO <<
"miu constraints to: " << m11;
1025 AINFO <<
"total constraints: " << num_of_constraints_;
1027 for (
int idx = 0; idx < m; ++idx) {
1028 if (g[idx] > g_u_tmp[idx] + delta_v || g[idx] < g_l_tmp[idx] - delta_v) {
1029 AINFO <<
"constratins idx unfeasible: " << idx <<
", g: " << g[idx] <<
", lower: " << g_l_tmp[idx]
1030 <<
", upper: " << g_u_tmp[idx];
1037 std::vector<double> xp(n);
1038 std::vector<double> lamp(m);
1039 std::vector<double> zl(m);
1040 std::vector<double> zu(m);
1041 std::vector<adouble> xa(n);
1042 std::vector<adouble> g(m);
1043 std::vector<double> lam(m);
1048 obj_lam =
new double[m + 1];
1052 for (
int idx = 0; idx < n; idx++) {
1053 xa[idx] <<= xp[idx];
1056 obj_value >>= dummy;
1060 for (
int idx = 0; idx < n; idx++) {
1061 xa[idx] <<= xp[idx];
1064 for (
int idx = 0; idx < m; idx++) {
1070 for (
int idx = 0; idx < n; idx++) {
1071 xa[idx] <<= xp[idx];
1073 for (
int idx = 0; idx < m; idx++) {
1078 obj_value *= mkparam(sig);
1080 for (
int idx = 0; idx < m; idx++) {
1081 obj_value += g[idx] * mkparam(lam[idx]);
1083 obj_value >>= dummy;
1098 sparse_jac(
tag_g, m, n, 0, &xp[0], &nnz_jac, &rind_g, &cind_g, &jacval, options_g);
1099 *nnz_jac_g = nnz_jac;
1103 sparse_hess(
tag_L, n, 0, &xp[0], &nnz_L, &rind_L, &cind_L, &hessval, options_L);
bool eval_jac_g_ser(int n, const double *x, bool new_x, int m, int nele_jac, int *iRow, int *jCol, double *values) override
DistanceApproachIPOPTFixedTsInterface(const size_t horizon, const double ts, const Eigen::MatrixXd &ego, const Eigen::MatrixXd &xWS, const Eigen::MatrixXd &uWS, const Eigen::MatrixXd &l_warm_up, const Eigen::MatrixXd &n_warm_up, const Eigen::MatrixXd &x0, const Eigen::MatrixXd &xf, const Eigen::MatrixXd &last_time_u, const std::vector< double > &XYbounds, const Eigen::MatrixXi &obstacles_edges_num, const size_t obstacles_num, const Eigen::MatrixXd &obstacles_A, const Eigen::MatrixXd &obstacles_b, const PlannerOpenSpaceConfig &planner_open_space_config)
void eval_obj(int n, const T *x, T *obj_value)
Template to return the objective value
bool get_bounds_info(int n, double *x_l, double *x_u, int m, double *g_l, double *g_u) override
Method to return the bounds for my problem
bool eval_f(int n, const double *x, bool new_x, double &obj_value) override
Method to return the objective value
bool check_g(int n, const double *x, int m, const double *g)
Check unfeasible constraints for further study
bool get_starting_point(int n, bool init_x, double *x, bool init_z, double *z_L, double *z_U, int m, bool init_lambda, double *lambda) override
Method to return the starting point for the algorithm
void eval_constraints(int n, const T *x, int m, T *g)
Template to compute constraints
void generate_tapes(int n, int m, int *nnz_jac_g, int *nnz_h_lag)
Method to generate the required tapes by ADOL-C
void get_optimization_results(Eigen::MatrixXd *state_result, Eigen::MatrixXd *control_result, Eigen::MatrixXd *time_result, Eigen::MatrixXd *dual_l_result, Eigen::MatrixXd *dual_n_result) const override
bool get_nlp_info(int &n, int &m, int &nnz_jac_g, int &nnz_h_lag, IndexStyleEnum &index_style) override
Method to return some info about the nlp
bool eval_g(int n, const double *x, bool new_x, int m, double *g) override
Method to return the constraint residuals
bool eval_h(int n, const double *x, bool new_x, double obj_factor, int m, const double *lambda, bool new_lambda, int nele_hess, int *iRow, int *jCol, double *values) override
Method to return: 1) The structure of the hessian of the lagrangian (if "values" is nullptr) 2) The v...
bool eval_grad_f(int n, const double *x, bool new_x, double *grad_f) override
Method to return the gradient of the objective
bool eval_jac_g(int n, const double *x, bool new_x, int m, int nele_jac, int *iRow, int *jCol, double *values) override
Method to return: 1) The structure of the jacobian (if "values" is nullptr) 2) The values of the jaco...
void finalize_solution(Ipopt::SolverReturn status, int n, const double *x, const double *z_L, const double *z_U, int m, const double *g, const double *lambda, double obj_value, const Ipopt::IpoptData *ip_data, Ipopt::IpoptCalculatedQuantities *ip_cq) override
This method is called when the algorithm is complete so the TNLP can store/write the solution
Planning module main class.
optional double max_steer_angle
optional double steer_ratio
optional double max_steer_angle_rate
optional double wheel_base
optional double weight_second_order_time
optional bool use_fix_time
optional double max_speed_forward
optional double weight_first_order_time
optional double min_safety_distance
optional double max_acceleration_forward
optional double max_acceleration_reverse
optional double weight_steer
optional double weight_phi
optional double max_time_sample_scaling
optional bool enable_initial_final_check
optional double min_time_sample_scaling
optional double weight_a_rate
optional bool enable_constraint_check
optional double weight_a_stitching
optional double weight_steer_stitching
optional double weight_steer_rate
optional double max_speed_reverse