Apollo 10.0
自动驾驶开放平台
apollo::planning::FemPosDeviationOsqpInterface类 参考

#include <fem_pos_deviation_osqp_interface.h>

apollo::planning::FemPosDeviationOsqpInterface 的协作图:

Public 成员函数

 FemPosDeviationOsqpInterface ()=default
 
virtual ~FemPosDeviationOsqpInterface ()=default
 
void set_ref_points (const std::vector< std::pair< double, double > > &ref_points)
 
void set_bounds_around_refs (const std::vector< double > &bounds_around_refs)
 
void set_weight_fem_pos_deviation (const double weight_fem_pos_deviation)
 
void set_weight_path_length (const double weight_path_length)
 
void set_weight_ref_deviation (const double weight_ref_deviation)
 
void set_max_iter (const int max_iter)
 
void set_time_limit (const double time_limit)
 
void set_verbose (const bool verbose)
 
void set_scaled_termination (const bool scaled_termination)
 
void set_warm_start (const bool warm_start)
 
bool Solve ()
 
const std::vector< double > & opt_x () const
 
const std::vector< double > & opt_y () const
 

详细描述

在文件 fem_pos_deviation_osqp_interface.h31 行定义.

构造及析构函数说明

◆ FemPosDeviationOsqpInterface()

apollo::planning::FemPosDeviationOsqpInterface::FemPosDeviationOsqpInterface ( )
default

◆ ~FemPosDeviationOsqpInterface()

virtual apollo::planning::FemPosDeviationOsqpInterface::~FemPosDeviationOsqpInterface ( )
virtualdefault

成员函数说明

◆ opt_x()

const std::vector< double > & apollo::planning::FemPosDeviationOsqpInterface::opt_x ( ) const
inline

在文件 fem_pos_deviation_osqp_interface.h72 行定义.

72{ return x_; }

◆ opt_y()

const std::vector< double > & apollo::planning::FemPosDeviationOsqpInterface::opt_y ( ) const
inline

在文件 fem_pos_deviation_osqp_interface.h74 行定义.

74{ return y_; }

◆ set_bounds_around_refs()

void apollo::planning::FemPosDeviationOsqpInterface::set_bounds_around_refs ( const std::vector< double > &  bounds_around_refs)
inline

在文件 fem_pos_deviation_osqp_interface.h42 行定义.

42 {
43 bounds_around_refs_ = bounds_around_refs;
44 }

◆ set_max_iter()

void apollo::planning::FemPosDeviationOsqpInterface::set_max_iter ( const int  max_iter)
inline

在文件 fem_pos_deviation_osqp_interface.h58 行定义.

58{ max_iter_ = max_iter; }

◆ set_ref_points()

void apollo::planning::FemPosDeviationOsqpInterface::set_ref_points ( const std::vector< std::pair< double, double > > &  ref_points)
inline

在文件 fem_pos_deviation_osqp_interface.h37 行定义.

38 {
39 ref_points_ = ref_points;
40 }

◆ set_scaled_termination()

void apollo::planning::FemPosDeviationOsqpInterface::set_scaled_termination ( const bool  scaled_termination)
inline

在文件 fem_pos_deviation_osqp_interface.h64 行定义.

64 {
65 scaled_termination_ = scaled_termination;
66 }

◆ set_time_limit()

void apollo::planning::FemPosDeviationOsqpInterface::set_time_limit ( const double  time_limit)
inline

在文件 fem_pos_deviation_osqp_interface.h60 行定义.

60{ time_limit_ = time_limit; }

◆ set_verbose()

void apollo::planning::FemPosDeviationOsqpInterface::set_verbose ( const bool  verbose)
inline

在文件 fem_pos_deviation_osqp_interface.h62 行定义.

62{ verbose_ = verbose; }

◆ set_warm_start()

void apollo::planning::FemPosDeviationOsqpInterface::set_warm_start ( const bool  warm_start)
inline

在文件 fem_pos_deviation_osqp_interface.h68 行定义.

68{ warm_start_ = warm_start; }

◆ set_weight_fem_pos_deviation()

void apollo::planning::FemPosDeviationOsqpInterface::set_weight_fem_pos_deviation ( const double  weight_fem_pos_deviation)
inline

在文件 fem_pos_deviation_osqp_interface.h46 行定义.

46 {
47 weight_fem_pos_deviation_ = weight_fem_pos_deviation;
48 }

◆ set_weight_path_length()

void apollo::planning::FemPosDeviationOsqpInterface::set_weight_path_length ( const double  weight_path_length)
inline

在文件 fem_pos_deviation_osqp_interface.h50 行定义.

50 {
51 weight_path_length_ = weight_path_length;
52 }

◆ set_weight_ref_deviation()

void apollo::planning::FemPosDeviationOsqpInterface::set_weight_ref_deviation ( const double  weight_ref_deviation)
inline

在文件 fem_pos_deviation_osqp_interface.h54 行定义.

54 {
55 weight_ref_deviation_ = weight_ref_deviation;
56 }

◆ Solve()

bool apollo::planning::FemPosDeviationOsqpInterface::Solve ( )

在文件 fem_pos_deviation_osqp_interface.cc30 行定义.

30 {
31 // Sanity Check
32 if (ref_points_.empty()) {
33 AERROR << "reference points empty, solver early terminates";
34 return false;
35 }
36
37 if (ref_points_.size() != bounds_around_refs_.size()) {
38 AERROR << "ref_points and bounds size not equal, solver early terminates";
39 return false;
40 }
41
42 if (ref_points_.size() < 3) {
43 AERROR << "ref_points size smaller than 3, solver early terminates";
44 return false;
45 }
46
47 if (ref_points_.size() > std::numeric_limits<int>::max()) {
48 AERROR << "ref_points size too large, solver early terminates";
49 return false;
50 }
51
52 // Calculate optimization states definitions
53 num_of_points_ = static_cast<int>(ref_points_.size());
54 num_of_variables_ = num_of_points_ * 2;
55 num_of_constraints_ = num_of_variables_;
56
57 // Calculate kernel
58 std::vector<c_float> P_data;
59 std::vector<c_int> P_indices;
60 std::vector<c_int> P_indptr;
61 CalculateKernel(&P_data, &P_indices, &P_indptr);
62
63 // Calculate affine constraints
64 std::vector<c_float> A_data;
65 std::vector<c_int> A_indices;
66 std::vector<c_int> A_indptr;
67 std::vector<c_float> lower_bounds;
68 std::vector<c_float> upper_bounds;
69 CalculateAffineConstraint(&A_data, &A_indices, &A_indptr, &lower_bounds,
70 &upper_bounds);
71
72 // Calculate offset
73 std::vector<c_float> q;
74 CalculateOffset(&q);
75
76 // Set primal warm start
77 std::vector<c_float> primal_warm_start;
78 SetPrimalWarmStart(&primal_warm_start);
79
80 OSQPData* data = reinterpret_cast<OSQPData*>(c_malloc(sizeof(OSQPData)));
81 OSQPSettings* settings =
82 reinterpret_cast<OSQPSettings*>(c_malloc(sizeof(OSQPSettings)));
83
84 // Define Solver settings
85 osqp_set_default_settings(settings);
86 settings->max_iter = max_iter_;
87 settings->time_limit = time_limit_;
88 settings->verbose = verbose_;
89 settings->scaled_termination = scaled_termination_;
90 settings->warm_start = warm_start_;
91
92 OSQPWorkspace* work = nullptr;
93
94 bool res = OptimizeWithOsqp(num_of_variables_, lower_bounds.size(), &P_data,
95 &P_indices, &P_indptr, &A_data, &A_indices,
96 &A_indptr, &lower_bounds, &upper_bounds, &q,
97 &primal_warm_start, data, &work, settings);
98 if (res == false || work == nullptr || work->solution == nullptr) {
99 AERROR << "Failed to find solution.";
100 // Cleanup
101 osqp_cleanup(work);
102 c_free(data->A);
103 c_free(data->P);
104 c_free(data);
105 c_free(settings);
106
107 return false;
108 }
109
110 // Extract primal results
111 x_.resize(num_of_points_);
112 y_.resize(num_of_points_);
113 for (int i = 0; i < num_of_points_; ++i) {
114 int index = i * 2;
115 x_.at(i) = work->solution->x[index];
116 y_.at(i) = work->solution->x[index + 1];
117 }
118
119 // Cleanup
120 osqp_cleanup(work);
121 c_free(data->A);
122 c_free(data->P);
123 c_free(data);
124 c_free(settings);
125
126 return true;
127}
#define AERROR
Definition log.h:44

该类的文档由以下文件生成: