Apollo  6.0
Open source self driving car software
dual_variable_warm_start_slack_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 
17 /*
18  * @file
19  */
20 
21 #pragma once
22 
23 #include <limits>
24 #include <vector>
25 
26 #include "Eigen/Dense"
27 #include "modules/common/configs/proto/vehicle_config.pb.h"
29 #include "modules/planning/proto/planner_open_space_config.pb.h"
30 #include "osqp/osqp.h"
31 
32 namespace apollo {
33 namespace planning {
34 
36  public:
38  size_t horizon, double ts, const Eigen::MatrixXd& ego,
39  const Eigen::MatrixXi& obstacles_edges_num, const size_t obstacles_num,
40  const Eigen::MatrixXd& obstacles_A, const Eigen::MatrixXd& obstacles_b,
41  const Eigen::MatrixXd& xWS,
42  const PlannerOpenSpaceConfig& planner_open_space_config);
43 
44  virtual ~DualVariableWarmStartSlackOSQPInterface() = default;
45 
46  void get_optimization_results(Eigen::MatrixXd* l_warm_up,
47  Eigen::MatrixXd* n_warm_up,
48  Eigen::MatrixXd* s_warm_up) const;
49 
50  bool optimize();
51 
52  void assembleP(std::vector<c_float>* P_data, std::vector<c_int>* P_indices,
53  std::vector<c_int>* P_indptr);
54 
55  void assembleConstraint(std::vector<c_float>* A_data,
56  std::vector<c_int>* A_indices,
57  std::vector<c_int>* A_indptr);
58 
59  void assembleA(const int r, const int c, const std::vector<c_float>& P_data,
60  const std::vector<c_int>& P_indices,
61  const std::vector<c_int>& P_indptr);
62 
63  void checkSolution(const Eigen::MatrixXd& l_warm_up,
64  const Eigen::MatrixXd& n_warm_up);
65 
66  void printMatrix(const int r, const int c, const std::vector<c_float>& P_data,
67  const std::vector<c_int>& P_indices,
68  const std::vector<c_int>& P_indptr);
69 
70  private:
71  OSQPConfig osqp_config_;
72 
73  int num_of_variables_;
74  int num_of_constraints_;
75  int horizon_;
76  double ts_;
77  Eigen::MatrixXd ego_;
78  int lambda_horizon_ = 0;
79  int miu_horizon_ = 0;
80  int slack_horizon_ = 0;
81  double beta_ = 0.0;
82 
83  Eigen::MatrixXd l_warm_up_;
84  Eigen::MatrixXd n_warm_up_;
85  Eigen::MatrixXd slacks_;
86  double wheelbase_;
87 
88  double w_ev_;
89  double l_ev_;
90  std::vector<double> g_;
91  double offset_;
92  Eigen::MatrixXi obstacles_edges_num_;
93  int obstacles_num_;
94  int obstacles_edges_sum_;
95 
96  double min_safety_distance_;
97 
98  // lagrangian l start index
99  int l_start_index_ = 0;
100 
101  // lagrangian n start index
102  int n_start_index_ = 0;
103 
104  // slack s start index
105  int s_start_index_ = 0;
106 
107  // obstacles_A
108  Eigen::MatrixXd obstacles_A_;
109 
110  // obstacles_b
111  Eigen::MatrixXd obstacles_b_;
112 
113  // states of warm up stage
114  Eigen::MatrixXd xWS_;
115 
116  // constraint A matrix in eigen format
117  Eigen::MatrixXf constraint_A_;
118 
119  bool check_mode_;
120 };
121 
122 } // namespace planning
123 } // namespace apollo
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Planning module main class. It processes GPS and IMU as input, to generate planning info...
DualVariableWarmStartSlackOSQPInterface(size_t horizon, double ts, const Eigen::MatrixXd &ego, const Eigen::MatrixXi &obstacles_edges_num, const size_t obstacles_num, const Eigen::MatrixXd &obstacles_A, const Eigen::MatrixXd &obstacles_b, const Eigen::MatrixXd &xWS, const PlannerOpenSpaceConfig &planner_open_space_config)
void assembleConstraint(std::vector< c_float > *A_data, std::vector< c_int > *A_indices, std::vector< c_int > *A_indptr)
void printMatrix(const int r, const int c, const std::vector< c_float > &P_data, const std::vector< c_int > &P_indices, const std::vector< c_int > &P_indptr)
void assembleP(std::vector< c_float > *P_data, std::vector< c_int > *P_indices, std::vector< c_int > *P_indptr)
void assembleA(const int r, const int c, const std::vector< c_float > &P_data, const std::vector< c_int > &P_indices, const std::vector< c_int > &P_indptr)
void get_optimization_results(Eigen::MatrixXd *l_warm_up, Eigen::MatrixXd *n_warm_up, Eigen::MatrixXd *s_warm_up) const
Definition: dual_variable_warm_start_slack_osqp_interface.h:35
void checkSolution(const Eigen::MatrixXd &l_warm_up, const Eigen::MatrixXd &n_warm_up)