26 const size_t horizon,
const double ts,
const Eigen::MatrixXd& ego,
27 const Eigen::MatrixXd& xWS,
const Eigen::MatrixXd& uWS,
28 const Eigen::MatrixXd& l_warm_up,
const Eigen::MatrixXd& n_warm_up,
29 const Eigen::MatrixXd& x0,
const Eigen::MatrixXd& xf,
30 const Eigen::MatrixXd& last_time_u,
const std::vector<double>& XYbounds,
31 const Eigen::MatrixXi& obstacles_edges_num,
const size_t obstacles_num,
32 const Eigen::MatrixXd& obstacles_A,
const Eigen::MatrixXd& obstacles_b,
38 l_warm_up_(l_warm_up),
39 n_warm_up_(n_warm_up),
42 last_time_u_(last_time_u),
44 obstacles_edges_num_(obstacles_edges_num),
45 obstacles_A_(obstacles_A),
46 obstacles_b_(obstacles_b) {
47 ACHECK(horizon < std::numeric_limits<int>::max())
48 <<
"Invalid cast on horizon in open space planner";
49 horizon_ =
static_cast<int>(horizon);
50 ACHECK(obstacles_num < std::numeric_limits<int>::max())
51 <<
"Invalid cast on obstacles_num in open space planner";
53 obstacles_num_ =
static_cast<int>(obstacles_num);
54 w_ev_ = ego_(1, 0) + ego_(3, 0);
55 l_ev_ = ego_(0, 0) + ego_(2, 0);
56 g_ = {l_ev_ / 2, w_ev_ / 2, l_ev_ / 2, w_ev_ / 2};
57 offset_ = (ego_(0, 0) + ego_(2, 0)) / 2 - ego_(2, 0);
58 obstacles_edges_sum_ = obstacles_edges_num_.sum();
59 state_result_ = Eigen::MatrixXd::Zero(4, horizon_ + 1);
60 dual_l_result_ = Eigen::MatrixXd::Zero(obstacles_edges_sum_, horizon_ + 1);
61 dual_n_result_ = Eigen::MatrixXd::Zero(4 * obstacles_num_, horizon_ + 1);
62 control_result_ = Eigen::MatrixXd::Zero(2, horizon_);
63 time_result_ = Eigen::MatrixXd::Zero(1, horizon_);
64 state_start_index_ = 0;
65 control_start_index_ = 4 * (horizon_ + 1);
66 time_start_index_ = control_start_index_ + 2 * horizon_;
67 l_start_index_ = time_start_index_ + (horizon_ + 1);
68 n_start_index_ = l_start_index_ + obstacles_edges_sum_ * (horizon_ + 1);
70 distance_approach_config_ =
72 weight_state_x_ = distance_approach_config_.weight_x();
73 weight_state_y_ = distance_approach_config_.weight_y();
74 weight_state_phi_ = distance_approach_config_.weight_phi();
75 weight_state_v_ = distance_approach_config_.weight_v();
76 weight_input_steer_ = distance_approach_config_.weight_steer();
77 weight_input_a_ = distance_approach_config_.weight_a();
78 weight_rate_steer_ = distance_approach_config_.weight_steer_rate();
79 weight_rate_a_ = distance_approach_config_.weight_a_rate();
80 weight_stitching_steer_ = distance_approach_config_.weight_steer_stitching();
81 weight_stitching_a_ = distance_approach_config_.weight_a_stitching();
82 weight_first_order_time_ =
83 distance_approach_config_.weight_first_order_time();
84 weight_second_order_time_ =
85 distance_approach_config_.weight_second_order_time();
86 min_safety_distance_ = distance_approach_config_.min_safety_distance();
89 max_speed_forward_ = distance_approach_config_.max_speed_forward();
90 max_speed_reverse_ = distance_approach_config_.max_speed_reverse();
91 max_acceleration_forward_ =
92 distance_approach_config_.max_acceleration_forward();
93 max_acceleration_reverse_ =
94 distance_approach_config_.max_acceleration_reverse();
95 min_time_sample_scaling_ =
96 distance_approach_config_.min_time_sample_scaling();
97 max_time_sample_scaling_ =
98 distance_approach_config_.max_time_sample_scaling();
101 use_fix_time_ = distance_approach_config_.use_fix_time();
103 enable_constraint_check_ =
104 distance_approach_config_.enable_constraint_check();
105 enable_jacobian_ad_ = distance_approach_config_.enable_jacobian_ad();
169 double* g_l,
double* g_u) {
170 ADEBUG <<
"get_bounds_info";
171 ACHECK(XYbounds_.size() == 4)
172 <<
"XYbounds_ size is not 4, but" << XYbounds_.size();
177 int variable_index = 0;
178 for (
int i = 0; i < 4; ++i) {
185 for (
int i = 1; i < horizon_; ++i) {
187 x_l[variable_index] = -2e19;
188 x_u[variable_index] = 2e19;
191 x_l[variable_index + 1] = -2e19;
192 x_u[variable_index + 1] = 2e19;
195 x_l[variable_index + 2] = -2e19;
196 x_u[variable_index + 2] = 2e19;
199 x_l[variable_index + 3] = -2e19;
200 x_u[variable_index + 3] = 2e19;
206 for (
int i = 0; i < 4; ++i) {
207 x_l[variable_index + i] = -2e19;
208 x_u[variable_index + i] = 2e19;
211 ADEBUG <<
"variable_index after adding state variables : " << variable_index;
214 for (
int i = 0; i < horizon_; ++i) {
216 x_l[variable_index] = -2e19;
217 x_u[variable_index] = 2e19;
220 x_l[variable_index + 1] = -2e19;
221 x_u[variable_index + 1] = 2e19;
225 ADEBUG <<
"variable_index after adding control variables : "
229 for (
int i = 0; i < horizon_ + 1; ++i) {
230 x_l[variable_index] = -2e19;
231 x_u[variable_index] = 2e19;
234 ADEBUG <<
"variable_index after adding sample time : " << variable_index;
235 ADEBUG <<
"sample time fix time status is : " << use_fix_time_;
239 for (
int i = 0; i < horizon_ + 1; ++i) {
240 for (
int j = 0; j < obstacles_edges_sum_; ++j) {
241 x_l[variable_index] = 0.0;
242 x_u[variable_index] = 2e19;
246 ADEBUG <<
"variable_index after adding lagrange l : " << variable_index;
249 for (
int i = 0; i < horizon_ + 1; ++i) {
250 for (
int j = 0; j < 4 * obstacles_num_; ++j) {
251 x_l[variable_index] = 0.0;
252 x_u[variable_index] = 2e19;
257 ADEBUG <<
"variable_index after adding lagrange n : " << variable_index;
263 int constraint_index = 0;
264 for (
int i = 0; i < 4 * horizon_; ++i) {
268 constraint_index += 4 * horizon_;
270 ADEBUG <<
"constraint_index after adding Euler forward dynamics constraints: "
275 for (
int i = 0; i < horizon_; ++i) {
276 g_l[constraint_index] = -max_steer_rate_;
277 g_u[constraint_index] = max_steer_rate_;
281 ADEBUG <<
"constraint_index after adding steering rate constraints: "
285 for (
int i = 0; i < horizon_; ++i) {
286 g_l[constraint_index] = 0.0;
287 g_u[constraint_index] = 0.0;
291 ADEBUG <<
"constraint_index after adding time constraints: "
296 for (
int i = 0; i < horizon_ + 1; ++i) {
297 for (
int j = 0; j < obstacles_num_; ++j) {
299 g_l[constraint_index] = -2e19;
300 g_u[constraint_index] = 1.0;
303 g_l[constraint_index + 1] = 0.0;
304 g_u[constraint_index + 1] = 0.0;
305 g_l[constraint_index + 2] = 0.0;
306 g_u[constraint_index + 2] = 0.0;
309 g_l[constraint_index + 3] = min_safety_distance_;
310 g_u[constraint_index + 3] = 2e19;
311 constraint_index += 4;
317 g_l[constraint_index] = x0_(0, 0);
318 g_u[constraint_index] = x0_(0, 0);
319 g_l[constraint_index + 1] = x0_(1, 0);
320 g_u[constraint_index + 1] = x0_(1, 0);
321 g_l[constraint_index + 2] = x0_(2, 0);
322 g_u[constraint_index + 2] = x0_(2, 0);
323 g_l[constraint_index + 3] = x0_(3, 0);
324 g_u[constraint_index + 3] = x0_(3, 0);
325 constraint_index += 4;
327 for (
int i = 1; i < horizon_; ++i) {
328 g_l[constraint_index] = XYbounds_[0];
329 g_u[constraint_index] = XYbounds_[1];
330 g_l[constraint_index + 1] = XYbounds_[2];
331 g_u[constraint_index + 1] = XYbounds_[3];
332 g_l[constraint_index + 2] = -max_speed_reverse_;
333 g_u[constraint_index + 2] = max_speed_forward_;
334 constraint_index += 3;
338 g_l[constraint_index] = xf_(0, 0);
339 g_u[constraint_index] = xf_(0, 0);
340 g_l[constraint_index + 1] = xf_(1, 0);
341 g_u[constraint_index + 1] = xf_(1, 0);
342 g_l[constraint_index + 2] = xf_(2, 0);
343 g_u[constraint_index + 2] = xf_(2, 0);
344 g_l[constraint_index + 3] = xf_(3, 0);
345 g_u[constraint_index + 3] = xf_(3, 0);
346 constraint_index += 4;
348 for (
int i = 0; i < horizon_; ++i) {
349 g_l[constraint_index] = -max_steer_angle_;
350 g_u[constraint_index] = max_steer_angle_;
351 g_l[constraint_index + 1] = -max_acceleration_reverse_;
352 g_u[constraint_index + 1] = max_acceleration_forward_;
353 constraint_index += 2;
356 for (
int i = 0; i < horizon_ + 1; ++i) {
357 if (!use_fix_time_) {
358 g_l[constraint_index] = min_time_sample_scaling_;
359 g_u[constraint_index] = max_time_sample_scaling_;
361 g_l[constraint_index] = 1.0;
362 g_u[constraint_index] = 1.0;
367 for (
int i = 0; i < lambda_horizon_; ++i) {
368 g_l[constraint_index] = 0.0;
369 g_u[constraint_index] = 2e19;
373 for (
int i = 0; i < miu_horizon_; ++i) {
374 g_l[constraint_index] = 0.0;
375 g_u[constraint_index] = 2e19;
379 ADEBUG <<
"constraint_index after adding obstacles constraints: "
381 ADEBUG <<
"get_bounds_info_ out";
480 int nele_jac,
int* iRow,
481 int* jCol,
double* values) {
483 CHECK_EQ(n, num_of_variables_)
484 <<
"No. of variables wrong in eval_jac_g. n : " << n;
485 CHECK_EQ(m, num_of_constraints_)
486 <<
"No. of constraints wrong in eval_jac_g. n : " << m;
488 if (values ==
nullptr) {
490 int constraint_index = 0;
491 int state_index = state_start_index_;
492 int control_index = control_start_index_;
493 int time_index = time_start_index_;
496 for (
int i = 0; i < horizon_; ++i) {
498 iRow[nz_index] = state_index;
499 jCol[nz_index] = state_index;
502 iRow[nz_index] = state_index;
503 jCol[nz_index] = state_index + 2;
506 iRow[nz_index] = state_index;
507 jCol[nz_index] = state_index + 3;
510 iRow[nz_index] = state_index;
511 jCol[nz_index] = state_index + 4;
515 iRow[nz_index] = state_index;
516 jCol[nz_index] = control_index;
519 iRow[nz_index] = state_index;
520 jCol[nz_index] = control_index + 1;
524 iRow[nz_index] = state_index;
525 jCol[nz_index] = time_index;
529 iRow[nz_index] = state_index + 1;
530 jCol[nz_index] = state_index + 1;
533 iRow[nz_index] = state_index + 1;
534 jCol[nz_index] = state_index + 2;
537 iRow[nz_index] = state_index + 1;
538 jCol[nz_index] = state_index + 3;
541 iRow[nz_index] = state_index + 1;
542 jCol[nz_index] = state_index + 5;
546 iRow[nz_index] = state_index + 1;
547 jCol[nz_index] = control_index;
550 iRow[nz_index] = state_index + 1;
551 jCol[nz_index] = control_index + 1;
555 iRow[nz_index] = state_index + 1;
556 jCol[nz_index] = time_index;
560 iRow[nz_index] = state_index + 2;
561 jCol[nz_index] = state_index + 2;
564 iRow[nz_index] = state_index + 2;
565 jCol[nz_index] = state_index + 3;
568 iRow[nz_index] = state_index + 2;
569 jCol[nz_index] = state_index + 6;
573 iRow[nz_index] = state_index + 2;
574 jCol[nz_index] = control_index;
577 iRow[nz_index] = state_index + 2;
578 jCol[nz_index] = control_index + 1;
582 iRow[nz_index] = state_index + 2;
583 jCol[nz_index] = time_index;
587 iRow[nz_index] = state_index + 3;
588 jCol[nz_index] = state_index + 3;
591 iRow[nz_index] = state_index + 3;
592 jCol[nz_index] = state_index + 7;
596 iRow[nz_index] = state_index + 3;
597 jCol[nz_index] = control_index + 1;
601 iRow[nz_index] = state_index + 3;
602 jCol[nz_index] = time_index;
608 constraint_index += 4;
612 control_index = control_start_index_;
613 state_index = state_start_index_;
614 time_index = time_start_index_;
617 iRow[nz_index] = constraint_index;
618 jCol[nz_index] = control_index;
622 iRow[nz_index] = constraint_index;
623 jCol[nz_index] = time_index;
630 for (
int i = 1; i < horizon_; ++i) {
632 iRow[nz_index] = constraint_index;
633 jCol[nz_index] = control_index - 2;
637 iRow[nz_index] = constraint_index;
638 jCol[nz_index] = control_index;
642 iRow[nz_index] = constraint_index;
643 jCol[nz_index] = time_index;
653 time_index = time_start_index_;
655 for (
int i = 0; i < horizon_; ++i) {
657 iRow[nz_index] = constraint_index;
658 jCol[nz_index] = time_index;
662 iRow[nz_index] = constraint_index;
663 jCol[nz_index] = time_index + 1;
672 state_index = state_start_index_;
673 int l_index = l_start_index_;
674 int n_index = n_start_index_;
675 for (
int i = 0; i < horizon_ + 1; ++i) {
676 for (
int j = 0; j < obstacles_num_; ++j) {
677 int current_edges_num = obstacles_edges_num_(j, 0);
680 for (
int k = 0; k < current_edges_num; ++k) {
682 iRow[nz_index] = constraint_index;
683 jCol[nz_index] = l_index + k;
689 iRow[nz_index] = constraint_index + 1;
690 jCol[nz_index] = state_index + 2;
694 for (
int k = 0; k < current_edges_num; ++k) {
695 iRow[nz_index] = constraint_index + 1;
696 jCol[nz_index] = l_index + k;
701 iRow[nz_index] = constraint_index + 1;
702 jCol[nz_index] = n_index;
705 iRow[nz_index] = constraint_index + 1;
706 jCol[nz_index] = n_index + 2;
711 iRow[nz_index] = constraint_index + 2;
712 jCol[nz_index] = state_index + 2;
716 for (
int k = 0; k < current_edges_num; ++k) {
717 iRow[nz_index] = constraint_index + 2;
718 jCol[nz_index] = l_index + k;
723 iRow[nz_index] = constraint_index + 2;
724 jCol[nz_index] = n_index + 1;
727 iRow[nz_index] = constraint_index + 2;
728 jCol[nz_index] = n_index + 3;
733 iRow[nz_index] = constraint_index + 3;
734 jCol[nz_index] = state_index;
737 iRow[nz_index] = constraint_index + 3;
738 jCol[nz_index] = state_index + 1;
741 iRow[nz_index] = constraint_index + 3;
742 jCol[nz_index] = state_index + 2;
746 for (
int k = 0; k < current_edges_num; ++k) {
747 iRow[nz_index] = constraint_index + 3;
748 jCol[nz_index] = l_index + k;
753 for (
int k = 0; k < 4; ++k) {
754 iRow[nz_index] = constraint_index + 3;
755 jCol[nz_index] = n_index + k;
760 l_index += current_edges_num;
762 constraint_index += 4;
768 state_index = state_start_index_;
769 control_index = control_start_index_;
770 time_index = time_start_index_;
771 l_index = l_start_index_;
772 n_index = n_start_index_;
775 iRow[nz_index] = constraint_index;
776 jCol[nz_index] = state_index;
778 iRow[nz_index] = constraint_index + 1;
779 jCol[nz_index] = state_index + 1;
781 iRow[nz_index] = constraint_index + 2;
782 jCol[nz_index] = state_index + 2;
784 iRow[nz_index] = constraint_index + 3;
785 jCol[nz_index] = state_index + 3;
787 constraint_index += 4;
790 for (
int i = 1; i < horizon_; ++i) {
791 iRow[nz_index] = constraint_index;
792 jCol[nz_index] = state_index;
794 iRow[nz_index] = constraint_index + 1;
795 jCol[nz_index] = state_index + 1;
797 iRow[nz_index] = constraint_index + 2;
798 jCol[nz_index] = state_index + 3;
800 constraint_index += 3;
805 iRow[nz_index] = constraint_index;
806 jCol[nz_index] = state_index;
808 iRow[nz_index] = constraint_index + 1;
809 jCol[nz_index] = state_index + 1;
811 iRow[nz_index] = constraint_index + 2;
812 jCol[nz_index] = state_index + 2;
814 iRow[nz_index] = constraint_index + 3;
815 jCol[nz_index] = state_index + 3;
817 constraint_index += 4;
820 for (
int i = 0; i < horizon_; ++i) {
821 iRow[nz_index] = constraint_index;
822 jCol[nz_index] = control_index;
824 iRow[nz_index] = constraint_index + 1;
825 jCol[nz_index] = control_index + 1;
827 constraint_index += 2;
831 for (
int i = 0; i < horizon_ + 1; ++i) {
832 iRow[nz_index] = constraint_index;
833 jCol[nz_index] = time_index;
839 for (
int i = 0; i < lambda_horizon_; ++i) {
840 iRow[nz_index] = constraint_index;
841 jCol[nz_index] = l_index;
847 for (
int i = 0; i < miu_horizon_; ++i) {
848 iRow[nz_index] = constraint_index;
849 jCol[nz_index] = n_index;
855 CHECK_EQ(nz_index,
static_cast<int>(nele_jac));
856 CHECK_EQ(constraint_index,
static_cast<int>(m));
858 std::fill(values, values + nele_jac, 0.0);
861 int time_index = time_start_index_;
862 int state_index = state_start_index_;
863 int control_index = control_start_index_;
868 for (
int i = 0; i < horizon_; ++i) {
869 values[nz_index] = -1.0;
873 x[time_index] * ts_ *
874 (x[state_index + 3] +
875 x[time_index] * ts_ * 0.5 * x[control_index + 1]) *
876 std::sin(x[state_index + 2] +
877 x[time_index] * ts_ * 0.5 * x[state_index + 3] *
878 std::tan(x[control_index]) / wheelbase_);
883 (x[time_index] * ts_ *
884 std::cos(x[state_index + 2] +
885 x[time_index] * ts_ * 0.5 * x[state_index + 3] *
886 std::tan(x[control_index]) / wheelbase_) +
887 x[time_index] * ts_ *
888 (x[state_index + 3] +
889 x[time_index] * ts_ * 0.5 * x[control_index + 1]) *
890 (-1) * x[time_index] * ts_ * 0.5 * std::tan(x[control_index]) /
892 std::sin(x[state_index + 2] +
893 x[time_index] * ts_ * 0.5 * x[state_index + 3] *
894 std::tan(x[control_index]) / wheelbase_));
897 values[nz_index] = 1.0;
901 x[time_index] * ts_ *
902 (x[state_index + 3] +
903 x[time_index] * ts_ * 0.5 * x[control_index + 1]) *
904 std::sin(x[state_index + 2] +
905 x[time_index] * ts_ * 0.5 * x[state_index + 3] *
906 std::tan(x[control_index]) / wheelbase_) *
907 x[time_index] * ts_ * 0.5 * x[state_index + 3] /
908 (std::cos(x[control_index]) * std::cos(x[control_index])) /
913 -1.0 * (x[time_index] * ts_ * x[time_index] * ts_ * 0.5 *
914 std::cos(x[state_index + 2] +
915 x[time_index] * ts_ * 0.5 * x[state_index + 3] *
916 std::tan(x[control_index]) / wheelbase_));
922 (x[state_index + 3] +
923 x[time_index] * ts_ * 0.5 * x[control_index + 1]) *
924 std::cos(x[state_index + 2] +
925 x[time_index] * ts_ * 0.5 * x[state_index + 3] *
926 std::tan(x[control_index]) / wheelbase_) +
927 x[time_index] * ts_ * ts_ * 0.5 * x[control_index + 1] *
928 std::cos(x[state_index + 2] +
929 x[time_index] * ts_ * 0.5 * x[state_index + 3] *
930 std::tan(x[control_index]) / wheelbase_) -
931 x[time_index] * ts_ *
932 (x[state_index + 3] +
933 x[time_index] * ts_ * 0.5 * x[control_index + 1]) *
934 x[state_index + 3] * ts_ * 0.5 * std::tan(x[control_index]) /
936 std::sin(x[state_index + 2] +
937 x[time_index] * ts_ * 0.5 * x[state_index + 3] *
938 std::tan(x[control_index]) / wheelbase_));
941 values[nz_index] = -1.0;
945 -1.0 * (x[time_index] * ts_ *
946 (x[state_index + 3] +
947 x[time_index] * ts_ * 0.5 * x[control_index + 1]) *
948 std::cos(x[state_index + 2] +
949 x[time_index] * ts_ * 0.5 * x[state_index + 3] *
950 std::tan(x[control_index]) / wheelbase_));
955 (x[time_index] * ts_ *
956 std::sin(x[state_index + 2] +
957 x[time_index] * ts_ * 0.5 * x[state_index + 3] *
958 std::tan(x[control_index]) / wheelbase_) +
959 x[time_index] * ts_ *
960 (x[state_index + 3] +
961 x[time_index] * ts_ * 0.5 * x[control_index + 1]) *
962 x[time_index] * ts_ * 0.5 * std::tan(x[control_index]) /
964 std::cos(x[state_index + 2] +
965 x[time_index] * ts_ * 0.5 * x[state_index + 3] *
966 std::tan(x[control_index]) / wheelbase_));
969 values[nz_index] = 1.0;
973 -1.0 * (x[time_index] * ts_ *
974 (x[state_index + 3] +
975 x[time_index] * ts_ * 0.5 * x[control_index + 1]) *
976 std::cos(x[state_index + 2] +
977 x[time_index] * ts_ * 0.5 * x[state_index + 3] *
978 std::tan(x[control_index]) / wheelbase_) *
979 x[time_index] * ts_ * 0.5 * x[state_index + 3] /
980 (std::cos(x[control_index]) * std::cos(x[control_index])) /
985 -1.0 * (x[time_index] * ts_ * x[time_index] * ts_ * 0.5 *
986 std::sin(x[state_index + 2] +
987 x[time_index] * ts_ * 0.5 * x[state_index + 3] *
988 std::tan(x[control_index]) / wheelbase_));
994 (x[state_index + 3] +
995 x[time_index] * ts_ * 0.5 * x[control_index + 1]) *
996 std::sin(x[state_index + 2] +
997 x[time_index] * ts_ * 0.5 * x[state_index + 3] *
998 std::tan(x[control_index]) / wheelbase_) +
999 x[time_index] * ts_ * ts_ * 0.5 * x[control_index + 1] *
1000 std::sin(x[state_index + 2] +
1001 x[time_index] * ts_ * 0.5 * x[state_index + 3] *
1002 std::tan(x[control_index]) / wheelbase_) +
1003 x[time_index] * ts_ *
1004 (x[state_index + 3] +
1005 x[time_index] * ts_ * 0.5 * x[control_index + 1]) *
1006 x[state_index + 3] * ts_ * 0.5 * std::tan(x[control_index]) /
1008 std::cos(x[state_index + 2] +
1009 x[time_index] * ts_ * 0.5 * x[state_index + 3] *
1010 std::tan(x[control_index]) / wheelbase_));
1013 values[nz_index] = -1.0;
1016 values[nz_index] = -1.0 * x[time_index] * ts_ *
1017 std::tan(x[control_index]) / wheelbase_;
1020 values[nz_index] = 1.0;
1024 -1.0 * (x[time_index] * ts_ *
1025 (x[state_index + 3] +
1026 x[time_index] * ts_ * 0.5 * x[control_index + 1]) /
1027 (std::cos(x[control_index]) * std::cos(x[control_index])) /
1032 -1.0 * (x[time_index] * ts_ * x[time_index] * ts_ * 0.5 *
1033 std::tan(x[control_index]) / wheelbase_);
1038 (x[state_index + 3] +
1039 x[time_index] * ts_ * 0.5 * x[control_index + 1]) *
1040 std::tan(x[control_index]) / wheelbase_ +
1041 x[time_index] * ts_ * ts_ * 0.5 * x[control_index + 1] *
1042 std::tan(x[control_index]) / wheelbase_);
1045 values[nz_index] = -1.0;
1048 values[nz_index] = 1.0;
1051 values[nz_index] = -1.0 * ts_ * x[time_index];
1054 values[nz_index] = -1.0 * ts_ * x[control_index + 1];
1063 control_index = control_start_index_;
1064 state_index = state_start_index_;
1065 time_index = time_start_index_;
1070 values[nz_index] = 1.0 / x[time_index] / ts_;
1074 values[nz_index] = -1.0 * (x[control_index] - last_time_u_(0, 0)) /
1075 x[time_index] / x[time_index] / ts_;
1080 for (
int i = 1; i < horizon_; ++i) {
1083 values[nz_index] = -1.0 / x[time_index] / ts_;
1087 values[nz_index] = 1.0 / x[time_index] / ts_;
1091 values[nz_index] = -1.0 * (x[control_index] - x[control_index - 2]) /
1092 x[time_index] / x[time_index] / ts_;
1099 ADEBUG <<
"After fulfilled control rate constraints derivative, nz_index : "
1100 << nz_index <<
" nele_jac : " << nele_jac;
1103 time_index = time_start_index_;
1104 for (
int i = 0; i < horizon_; ++i) {
1106 values[nz_index] = -1.0;
1110 values[nz_index] = 1.0;
1116 ADEBUG <<
"After fulfilled time constraints derivative, nz_index : "
1117 << nz_index <<
" nele_jac : " << nele_jac;
1122 state_index = state_start_index_;
1123 int l_index = l_start_index_;
1124 int n_index = n_start_index_;
1126 for (
int i = 0; i < horizon_ + 1; ++i) {
1127 int edges_counter = 0;
1128 for (
int j = 0; j < obstacles_num_; ++j) {
1129 int current_edges_num = obstacles_edges_num_(j, 0);
1130 Eigen::MatrixXd Aj =
1131 obstacles_A_.block(edges_counter, 0, current_edges_num, 2);
1132 Eigen::MatrixXd bj =
1133 obstacles_b_.block(edges_counter, 0, current_edges_num, 1);
1138 for (
int k = 0; k < current_edges_num; ++k) {
1140 tmp1 += Aj(k, 0) * x[l_index + k];
1141 tmp2 += Aj(k, 1) * x[l_index + k];
1145 for (
int k = 0; k < current_edges_num; ++k) {
1148 2 * tmp1 * Aj(k, 0) + 2 * tmp2 * Aj(k, 1);
1154 values[nz_index] = -std::sin(x[state_index + 2]) * tmp1 +
1155 std::cos(x[state_index + 2]) * tmp2;
1159 for (
int k = 0; k < current_edges_num; ++k) {
1160 values[nz_index] = std::cos(x[state_index + 2]) * Aj(k, 0) +
1161 std::sin(x[state_index + 2]) * Aj(k, 1);
1166 values[nz_index] = 1.0;
1169 values[nz_index] = -1.0;
1174 values[nz_index] = -std::cos(x[state_index + 2]) * tmp1 -
1175 std::sin(x[state_index + 2]) * tmp2;
1179 for (
int k = 0; k < current_edges_num; ++k) {
1180 values[nz_index] = -std::sin(x[state_index + 2]) * Aj(k, 0) +
1181 std::cos(x[state_index + 2]) * Aj(k, 1);
1186 values[nz_index] = 1.0;
1189 values[nz_index] = -1.0;
1195 for (
int k = 0; k < 4; ++k) {
1196 tmp3 += -g_[k] * x[n_index + k];
1199 for (
int k = 0; k < current_edges_num; ++k) {
1200 tmp4 += bj(k, 0) * x[l_index + k];
1204 values[nz_index] = tmp1;
1207 values[nz_index] = tmp2;
1211 -std::sin(x[state_index + 2]) * offset_ * tmp1 +
1212 std::cos(x[state_index + 2]) * offset_ * tmp2;
1216 for (
int k = 0; k < current_edges_num; ++k) {
1218 (x[state_index] + std::cos(x[state_index + 2]) * offset_) *
1220 (x[state_index + 1] + std::sin(x[state_index + 2]) * offset_) *
1227 for (
int k = 0; k < 4; ++k) {
1228 values[nz_index] = -g_[k];
1233 edges_counter += current_edges_num;
1234 l_index += current_edges_num;
1241 state_index = state_start_index_;
1242 control_index = control_start_index_;
1243 time_index = time_start_index_;
1244 l_index = l_start_index_;
1245 n_index = n_start_index_;
1248 values[nz_index] = 1.0;
1250 values[nz_index] = 1.0;
1252 values[nz_index] = 1.0;
1254 values[nz_index] = 1.0;
1257 for (
int i = 1; i < horizon_; ++i) {
1258 values[nz_index] = 1.0;
1260 values[nz_index] = 1.0;
1262 values[nz_index] = 1.0;
1267 values[nz_index] = 1.0;
1269 values[nz_index] = 1.0;
1271 values[nz_index] = 1.0;
1273 values[nz_index] = 1.0;
1276 for (
int i = 0; i < horizon_; ++i) {
1277 values[nz_index] = 1.0;
1279 values[nz_index] = 1.0;
1283 for (
int i = 0; i < horizon_ + 1; ++i) {
1284 values[nz_index] = 1.0;
1288 for (
int i = 0; i < lambda_horizon_; ++i) {
1289 values[nz_index] = 1.0;
1293 for (
int i = 0; i < miu_horizon_; ++i) {
1294 values[nz_index] = 1.0;
1298 ADEBUG <<
"eval_jac_g, fulfilled obstacle constraint values";
1299 CHECK_EQ(nz_index,
static_cast<int>(nele_jac));
1302 ADEBUG <<
"eval_jac_g done";
1551 int state_index = state_start_index_;
1554 int control_index = control_start_index_;
1557 int time_index = time_start_index_;
1559 int constraint_index = 0;
1562 for (
int i = 0; i < horizon_; ++i) {
1564 g[constraint_index] =
1565 x[state_index + 4] -
1567 ts_ * x[time_index] *
1568 (x[state_index + 3] +
1569 ts_ * x[time_index] * 0.5 * x[control_index + 1]) *
1570 cos(x[state_index + 2] + ts_ * x[time_index] * 0.5 *
1571 x[state_index + 3] *
1572 tan(x[control_index]) / wheelbase_));
1588 g[constraint_index + 1] =
1589 x[state_index + 5] -
1590 (x[state_index + 1] +
1591 ts_ * x[time_index] *
1592 (x[state_index + 3] +
1593 ts_ * x[time_index] * 0.5 * x[control_index + 1]) *
1594 sin(x[state_index + 2] + ts_ * x[time_index] * 0.5 *
1595 x[state_index + 3] *
1596 tan(x[control_index]) / wheelbase_));
1611 g[constraint_index + 2] =
1612 x[state_index + 6] -
1613 (x[state_index + 2] +
1614 ts_ * x[time_index] *
1615 (x[state_index + 3] +
1616 ts_ * x[time_index] * 0.5 * x[control_index + 1]) *
1617 tan(x[control_index]) / wheelbase_);
1635 g[constraint_index + 3] =
1636 x[state_index + 7] -
1637 (x[state_index + 3] + ts_ * x[time_index] * x[control_index + 1]);
1646 constraint_index += 4;
1651 ADEBUG <<
"constraint_index after adding Euler forward dynamics constraints "
1653 << constraint_index;
1657 control_index = control_start_index_;
1658 time_index = time_start_index_;
1661 g[constraint_index] =
1662 (x[control_index] - last_time_u_(0, 0)) / x[time_index] / ts_;
1667 for (
int i = 1; i < horizon_; ++i) {
1668 g[constraint_index] =
1669 (x[control_index] - x[control_index - 2]) / x[time_index] / ts_;
1676 time_index = time_start_index_;
1677 for (
int i = 0; i < horizon_; ++i) {
1678 g[constraint_index] = x[time_index + 1] - x[time_index];
1683 ADEBUG <<
"constraint_index after adding time constraints "
1685 << constraint_index;
1689 state_index = state_start_index_;
1690 int l_index = l_start_index_;
1691 int n_index = n_start_index_;
1693 for (
int i = 0; i < horizon_ + 1; ++i) {
1694 int edges_counter = 0;
1695 for (
int j = 0; j < obstacles_num_; ++j) {
1696 int current_edges_num = obstacles_edges_num_(j, 0);
1697 Eigen::MatrixXd Aj =
1698 obstacles_A_.block(edges_counter, 0, current_edges_num, 2);
1699 Eigen::MatrixXd bj =
1700 obstacles_b_.block(edges_counter, 0, current_edges_num, 1);
1705 for (
int k = 0; k < current_edges_num; ++k) {
1707 tmp1 += Aj(k, 0) * x[l_index + k];
1708 tmp2 += Aj(k, 1) * x[l_index + k];
1710 g[constraint_index] = tmp1 * tmp1 + tmp2 * tmp2;
1713 g[constraint_index + 1] = x[n_index] - x[n_index + 2] +
1714 cos(x[state_index + 2]) * tmp1 +
1715 sin(x[state_index + 2]) * tmp2;
1717 g[constraint_index + 2] = x[n_index + 1] - x[n_index + 3] -
1718 sin(x[state_index + 2]) * tmp1 +
1719 cos(x[state_index + 2]) * tmp2;
1723 for (
int k = 0; k < 4; ++k) {
1724 tmp3 += -g_[k] * x[n_index + k];
1728 for (
int k = 0; k < current_edges_num; ++k) {
1729 tmp4 += bj(k, 0) * x[l_index + k];
1732 g[constraint_index + 3] =
1733 tmp3 + (x[state_index] + cos(x[state_index + 2]) * offset_) * tmp1 +
1734 (x[state_index + 1] + sin(x[state_index + 2]) * offset_) * tmp2 -
1738 edges_counter += current_edges_num;
1739 l_index += current_edges_num;
1741 constraint_index += 4;
1745 ADEBUG <<
"constraint_index after obstacles avoidance constraints "
1747 << constraint_index;
1750 state_index = state_start_index_;
1751 control_index = control_start_index_;
1752 time_index = time_start_index_;
1753 l_index = l_start_index_;
1754 n_index = n_start_index_;
1757 g[constraint_index] = x[state_index];
1758 g[constraint_index + 1] = x[state_index + 1];
1759 g[constraint_index + 2] = x[state_index + 2];
1760 g[constraint_index + 3] = x[state_index + 3];
1761 constraint_index += 4;
1765 for (
int i = 1; i < horizon_; ++i) {
1766 g[constraint_index] = x[state_index];
1767 g[constraint_index + 1] = x[state_index + 1];
1768 g[constraint_index + 2] = x[state_index + 3];
1769 constraint_index += 3;
1774 g[constraint_index] = x[state_index];
1775 g[constraint_index + 1] = x[state_index + 1];
1776 g[constraint_index + 2] = x[state_index + 2];
1777 g[constraint_index + 3] = x[state_index + 3];
1778 constraint_index += 4;
1781 for (
int i = 0; i < horizon_; ++i) {
1782 g[constraint_index] = x[control_index];
1783 g[constraint_index + 1] = x[control_index + 1];
1784 constraint_index += 2;
1788 for (
int i = 0; i < horizon_ + 1; ++i) {
1789 g[constraint_index] = x[time_index];
1794 for (
int i = 0; i < lambda_horizon_; ++i) {
1795 g[constraint_index] = x[l_index];
1800 for (
int i = 0; i < miu_horizon_; ++i) {
1801 g[constraint_index] = x[n_index];