Apollo 11.0
自动驾驶开放平台
fem_pos_deviation_sqp_osqp_interface.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2019 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
21#pragma once
22
23#include <utility>
24#include <vector>
25
26#include "osqp/osqp.h"
29
30namespace apollo {
31namespace planning {
32
34 public:
36
38
40 const std::vector<std::pair<double, double>>& ref_points) {
41 ref_points_ = ref_points;
42 }
43
44 void set_bounds_around_refs(const std::vector<double>& bounds_around_refs) {
45 bounds_around_refs_ = bounds_around_refs;
46 }
47
48 void set_weight_fem_pos_deviation(const double weight_fem_pos_deviation) {
49 weight_fem_pos_deviation_ = weight_fem_pos_deviation;
50 }
51
52 void set_weight_path_length(const double weight_path_length) {
53 weight_path_length_ = weight_path_length;
54 }
55
56 void set_weight_ref_deviation(const double weight_ref_deviation) {
57 weight_ref_deviation_ = weight_ref_deviation;
58 }
59
61 const double weight_curvature_constraint_slack_var) {
62 weight_curvature_constraint_slack_var_ =
63 weight_curvature_constraint_slack_var;
64 }
65
66 void set_curvature_constraint(const double curvature_constraint) {
67 curvature_constraint_ = curvature_constraint;
68 }
69
70 void set_max_iter(const int max_iter) { max_iter_ = max_iter; }
71
72 void set_time_limit(const double time_limit) { time_limit_ = time_limit; }
73
74 void set_verbose(const bool verbose) { verbose_ = verbose; }
75
76 void set_scaled_termination(const bool scaled_termination) {
77 scaled_termination_ = scaled_termination;
78 }
79
80 void set_warm_start(const bool warm_start) { warm_start_ = warm_start; }
81
82 void set_sqp_pen_max_iter(const int sqp_pen_max_iter) {
83 sqp_pen_max_iter_ = sqp_pen_max_iter;
84 }
85
86 void set_sqp_ftol(const double sqp_ftol) { sqp_ftol_ = sqp_ftol; }
87
88 void set_sqp_sub_max_iter(const int sqp_sub_max_iter) {
89 sqp_sub_max_iter_ = sqp_sub_max_iter;
90 }
91
92 void set_sqp_ctol(const double sqp_ctol) { sqp_ctol_ = sqp_ctol; }
93
94 bool Solve();
95
96 const std::vector<std::pair<double, double>>& opt_xy() const {
97 return opt_xy_;
98 }
99
100 private:
101 void CalculateKernel(std::vector<c_float>* P_data,
102 std::vector<c_int>* P_indices,
103 std::vector<c_int>* P_indptr);
104
105 void CalculateOffset(std::vector<c_float>* q);
106
107 std::vector<double> CalculateLinearizedFemPosParams(
108 const std::vector<std::pair<double, double>>& points, const size_t index);
109
110 void CalculateAffineConstraint(
111 const std::vector<std::pair<double, double>>& points,
112 std::vector<c_float>* A_data, std::vector<c_int>* A_indices,
113 std::vector<c_int>* A_indptr, std::vector<c_float>* lower_bounds,
114 std::vector<c_float>* upper_bounds);
115
116 void SetPrimalWarmStart(const std::vector<std::pair<double, double>>& points,
117 std::vector<c_float>* primal_warm_start);
118
119 bool OptimizeWithOsqp(const std::vector<c_float>& primal_warm_start,
120 OSQPWorkspace** work);
121
122 double CalculateConstraintViolation(
123 const std::vector<std::pair<double, double>>& points);
124
125 private:
126 // Init states and constraints
127 std::vector<std::pair<double, double>> ref_points_;
128 std::vector<double> bounds_around_refs_;
129 double curvature_constraint_ = 0.2;
130
131 // Weights in optimization cost function
132 double weight_fem_pos_deviation_ = 1.0e5;
133 double weight_path_length_ = 1.0;
134 double weight_ref_deviation_ = 1.0;
135 double weight_curvature_constraint_slack_var_ = 1.0e5;
136
137 // Settings of osqp
138 int max_iter_ = 4000;
139 double time_limit_ = 0.0;
140 bool verbose_ = false;
141 bool scaled_termination_ = true;
142 bool warm_start_ = true;
143
144 // Settings of sqp
145 int sqp_pen_max_iter_ = 100;
146 double sqp_ftol_ = 1e-2;
147 int sqp_sub_max_iter_ = 100;
148 double sqp_ctol_ = 1e-2;
149
150 // Optimization problem definitions
151 int num_of_points_ = 0;
152 int num_of_pos_variables_ = 0;
153 int num_of_slack_variables_ = 0;
154 int num_of_variables_ = 0;
155 int num_of_variable_constraints_ = 0;
156 int num_of_curvature_constraints_ = 0;
157 int num_of_constraints_ = 0;
158
159 // Optimized_result
160 std::vector<std::pair<double, double>> opt_xy_;
161 std::vector<double> slack_;
162 double average_interval_length_ = 0.0;
163
164 // park generic
165 public:
166 void set_point_box(std::vector<std::vector<common::math::Vec2d>> point_box) {
167 point_box_ = point_box;
168 }
169
170 private:
171 void CalculateOffset(std::vector<std::pair<double, double>> points,
172 std::vector<c_float>* q);
173
174 std::vector<std::vector<common::math::Vec2d>> point_box_;
175};
176} // namespace planning
177} // namespace apollo
void set_weight_curvature_constraint_slack_var(const double weight_curvature_constraint_slack_var)
void set_weight_fem_pos_deviation(const double weight_fem_pos_deviation)
const std::vector< std::pair< double, double > > & opt_xy() const
void set_ref_points(const std::vector< std::pair< double, double > > &ref_points)
void set_point_box(std::vector< std::vector< common::math::Vec2d > > point_box)
void set_bounds_around_refs(const std::vector< double > &bounds_around_refs)
Planning module main class.
class register implement
Definition arena_queue.h:37
Defines the Vec2d class.