Apollo  6.0
Open source self driving car software
fem_pos_deviation_osqp_interface.h
Go to the documentation of this file.
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"
27 
28 namespace apollo {
29 namespace planning {
30 
32  public:
33  FemPosDeviationOsqpInterface() = default;
34 
35  virtual ~FemPosDeviationOsqpInterface() = default;
36 
38  const std::vector<std::pair<double, double>>& ref_points) {
39  ref_points_ = ref_points;
40  }
41 
42  void set_bounds_around_refs(const std::vector<double>& bounds_around_refs) {
43  bounds_around_refs_ = bounds_around_refs;
44  }
45 
46  void set_weight_fem_pos_deviation(const double weight_fem_pos_deviation) {
47  weight_fem_pos_deviation_ = weight_fem_pos_deviation;
48  }
49 
50  void set_weight_path_length(const double weight_path_length) {
51  weight_path_length_ = weight_path_length;
52  }
53 
54  void set_weight_ref_deviation(const double weight_ref_deviation) {
55  weight_ref_deviation_ = weight_ref_deviation;
56  }
57 
58  void set_max_iter(const int max_iter) { max_iter_ = max_iter; }
59 
60  void set_time_limit(const double time_limit) { time_limit_ = time_limit; }
61 
62  void set_verbose(const bool verbose) { verbose_ = verbose; }
63 
64  void set_scaled_termination(const bool scaled_termination) {
65  scaled_termination_ = scaled_termination;
66  }
67 
68  void set_warm_start(const bool warm_start) { warm_start_ = warm_start; }
69 
70  bool Solve();
71 
72  const std::vector<double>& opt_x() const { return x_; }
73 
74  const std::vector<double>& opt_y() const { return y_; }
75 
76  private:
77  void CalculateKernel(std::vector<c_float>* P_data,
78  std::vector<c_int>* P_indices,
79  std::vector<c_int>* P_indptr);
80 
81  void CalculateOffset(std::vector<c_float>* q);
82 
83  void CalculateAffineConstraint(std::vector<c_float>* A_data,
84  std::vector<c_int>* A_indices,
85  std::vector<c_int>* A_indptr,
86  std::vector<c_float>* lower_bounds,
87  std::vector<c_float>* upper_bounds);
88 
89  void SetPrimalWarmStart(std::vector<c_float>* primal_warm_start);
90 
91  bool OptimizeWithOsqp(
92  const size_t kernel_dim, const size_t num_affine_constraint,
93  std::vector<c_float>* P_data, std::vector<c_int>* P_indices,
94  std::vector<c_int>* P_indptr, std::vector<c_float>* A_data,
95  std::vector<c_int>* A_indices, std::vector<c_int>* A_indptr,
96  std::vector<c_float>* lower_bounds, std::vector<c_float>* upper_bounds,
97  std::vector<c_float>* q, std::vector<c_float>* primal_warm_start,
98  OSQPData* data, OSQPWorkspace** work, OSQPSettings* settings);
99 
100  private:
101  // Reference points and deviation bounds
102  std::vector<std::pair<double, double>> ref_points_;
103  std::vector<double> bounds_around_refs_;
104 
105  // Weights in optimization cost function
106  double weight_fem_pos_deviation_ = 1.0e5;
107  double weight_path_length_ = 1.0;
108  double weight_ref_deviation_ = 1.0;
109 
110  // Settings of osqp
111  int max_iter_ = 4000;
112  double time_limit_ = 0.0;
113  bool verbose_ = false;
114  bool scaled_termination_ = true;
115  bool warm_start_ = true;
116 
117  // Optimization problem definitions
118  int num_of_points_ = 0;
119  int num_of_variables_ = 0;
120  int num_of_constraints_ = 0;
121 
122  // Optimized_result
123  std::vector<double> x_;
124  std::vector<double> y_;
125 };
126 } // namespace planning
127 } // namespace apollo
void set_bounds_around_refs(const std::vector< double > &bounds_around_refs)
Definition: fem_pos_deviation_osqp_interface.h:42
void set_ref_points(const std::vector< std::pair< double, double >> &ref_points)
Definition: fem_pos_deviation_osqp_interface.h:37
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
void set_weight_ref_deviation(const double weight_ref_deviation)
Definition: fem_pos_deviation_osqp_interface.h:54
void set_weight_path_length(const double weight_path_length)
Definition: fem_pos_deviation_osqp_interface.h:50
Planning module main class. It processes GPS and IMU as input, to generate planning info...
const std::vector< double > & opt_y() const
Definition: fem_pos_deviation_osqp_interface.h:74
void set_verbose(const bool verbose)
Definition: fem_pos_deviation_osqp_interface.h:62
void set_max_iter(const int max_iter)
Definition: fem_pos_deviation_osqp_interface.h:58
Definition: fem_pos_deviation_osqp_interface.h:31
void set_scaled_termination(const bool scaled_termination)
Definition: fem_pos_deviation_osqp_interface.h:64
const std::vector< double > & opt_x() const
Definition: fem_pos_deviation_osqp_interface.h:72
void set_weight_fem_pos_deviation(const double weight_fem_pos_deviation)
Definition: fem_pos_deviation_osqp_interface.h:46
void set_warm_start(const bool warm_start)
Definition: fem_pos_deviation_osqp_interface.h:68
void set_time_limit(const double time_limit)
Definition: fem_pos_deviation_osqp_interface.h:60