Apollo 11.0
自动驾驶开放平台
apollo::planning::FemPosDeviationSmoother类 参考

#include <fem_pos_deviation_smoother.h>

apollo::planning::FemPosDeviationSmoother 的协作图:

Public 成员函数

 FemPosDeviationSmoother (const FemPosDeviationSmootherConfig &config)
 
bool QpWithOsqp (const std::vector< std::pair< double, double > > &raw_point2d, const std::vector< double > &bounds, std::vector< double > *opt_x, std::vector< double > *opt_y)
 
bool NlpWithIpopt (const std::vector< std::pair< double, double > > &raw_point2d, const std::vector< double > &bounds, std::vector< double > *opt_x, std::vector< double > *opt_y)
 
bool SqpWithOsqp (const std::vector< std::pair< double, double > > &raw_point2d, const std::vector< double > &bounds, std::vector< double > *opt_x, std::vector< double > *opt_y)
 
bool Solve (const std::vector< std::pair< double, double > > &raw_point2d, const std::vector< double > &bounds, std::vector< double > *opt_x, std::vector< double > *opt_y, std::vector< std::vector< common::math::Vec2d > > point_box={})
 
bool SqpWithOsqp (const std::vector< std::pair< double, double > > &raw_point2d, const std::vector< double > &bounds, std::vector< double > *opt_x, std::vector< double > *opt_y, std::vector< std::vector< common::math::Vec2d > > point_box)
 

详细描述

在文件 fem_pos_deviation_smoother.h 第 48 行定义.

构造及析构函数说明

◆ FemPosDeviationSmoother()

apollo::planning::FemPosDeviationSmoother::FemPosDeviationSmoother ( const FemPosDeviationSmootherConfig &  config)
explicit

在文件 fem_pos_deviation_smoother.cc 第 33 行定义.

35 : config_(config) {}

成员函数说明

◆ NlpWithIpopt()

bool apollo::planning::FemPosDeviationSmoother::NlpWithIpopt ( const std::vector< std::pair< double, double > > &  raw_point2d,
const std::vector< double > &  bounds,
std::vector< double > *  opt_x,
std::vector< double > *  opt_y 
)

在文件 fem_pos_deviation_smoother.cc 第 138 行定义.

141 {
142 if (opt_x == nullptr || opt_y == nullptr) {
143 AERROR << "opt_x or opt_y is nullptr";
144 return false;
145 }
146
147 FemPosDeviationIpoptInterface* smoother =
148 new FemPosDeviationIpoptInterface(raw_point2d, bounds);
149
150 smoother->set_weight_fem_pos_deviation(config_.weight_fem_pos_deviation());
151 smoother->set_weight_path_length(config_.weight_path_length());
152 smoother->set_weight_ref_deviation(config_.weight_ref_deviation());
153 smoother->set_weight_curvature_constraint_slack_var(
155 smoother->set_curvature_constraint(config_.curvature_constraint());
156
157 Ipopt::SmartPtr<Ipopt::TNLP> problem = smoother;
158
159 // Create an instance of the IpoptApplication
160 Ipopt::SmartPtr<Ipopt::IpoptApplication> app = IpoptApplicationFactory();
161
162 app->Options()->SetIntegerValue("print_level",
163 static_cast<int>(config_.print_level()));
164 app->Options()->SetIntegerValue(
165 "max_iter", static_cast<int>(config_.max_num_of_iterations()));
166 app->Options()->SetIntegerValue(
167 "acceptable_iter",
168 static_cast<int>(config_.acceptable_num_of_iterations()));
169 app->Options()->SetNumericValue("tol", config_.tol());
170 app->Options()->SetNumericValue("acceptable_tol", config_.acceptable_tol());
171
172 Ipopt::ApplicationReturnStatus status = app->Initialize();
173 if (status != Ipopt::Solve_Succeeded) {
174 AERROR << "*** Error during initialization!";
175 return false;
176 }
177
178 status = app->OptimizeTNLP(problem);
179
180 if (status == Ipopt::Solve_Succeeded ||
181 status == Ipopt::Solved_To_Acceptable_Level) {
182 // Retrieve some statistics about the solve
183 Ipopt::Index iter_count = app->Statistics()->IterationCount();
184 ADEBUG << "*** The problem solved in " << iter_count << " iterations!";
185 } else {
186 AERROR << "Solver fails with return code: " << static_cast<int>(status);
187 return false;
188 }
189 smoother->get_optimization_results(opt_x, opt_y);
190 return true;
191}
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44

◆ QpWithOsqp()

bool apollo::planning::FemPosDeviationSmoother::QpWithOsqp ( const std::vector< std::pair< double, double > > &  raw_point2d,
const std::vector< double > &  bounds,
std::vector< double > *  opt_x,
std::vector< double > *  opt_y 
)

在文件 fem_pos_deviation_smoother.cc 第 54 行定义.

57 {
58 if (opt_x == nullptr || opt_y == nullptr) {
59 AERROR << "opt_x or opt_y is nullptr";
60 return false;
61 }
62
63 FemPosDeviationOsqpInterface solver;
64
65 solver.set_weight_fem_pos_deviation(config_.weight_fem_pos_deviation());
66 solver.set_weight_path_length(config_.weight_path_length());
67 solver.set_weight_ref_deviation(config_.weight_ref_deviation());
68
69 solver.set_max_iter(config_.max_iter());
70 solver.set_time_limit(config_.time_limit());
71 solver.set_verbose(config_.verbose());
72 solver.set_scaled_termination(config_.scaled_termination());
73 solver.set_warm_start(config_.warm_start());
74
75 solver.set_ref_points(raw_point2d);
76 solver.set_bounds_around_refs(bounds);
77
78 if (!solver.Solve()) {
79 return false;
80 }
81
82 *opt_x = solver.opt_x();
83 *opt_y = solver.opt_y();
84 return true;
85}

◆ Solve()

bool apollo::planning::FemPosDeviationSmoother::Solve ( const std::vector< std::pair< double, double > > &  raw_point2d,
const std::vector< double > &  bounds,
std::vector< double > *  opt_x,
std::vector< double > *  opt_y,
std::vector< std::vector< common::math::Vec2d > >  point_box = {} 
)

在文件 fem_pos_deviation_smoother.cc 第 37 行定义.

41 {
42 if (config_.apply_curvature_constraint()) {
43 if (config_.use_sqp()) {
44 return SqpWithOsqp(raw_point2d, bounds, opt_x, opt_y, point_box);
45 } else {
46 return NlpWithIpopt(raw_point2d, bounds, opt_x, opt_y);
47 }
48 } else {
49 return QpWithOsqp(raw_point2d, bounds, opt_x, opt_y);
50 }
51 return true;
52}
bool QpWithOsqp(const std::vector< std::pair< double, double > > &raw_point2d, const std::vector< double > &bounds, std::vector< double > *opt_x, std::vector< double > *opt_y)
bool NlpWithIpopt(const std::vector< std::pair< double, double > > &raw_point2d, const std::vector< double > &bounds, std::vector< double > *opt_x, std::vector< double > *opt_y)
bool SqpWithOsqp(const std::vector< std::pair< double, double > > &raw_point2d, const std::vector< double > &bounds, std::vector< double > *opt_x, std::vector< double > *opt_y)

◆ SqpWithOsqp() [1/2]

bool apollo::planning::FemPosDeviationSmoother::SqpWithOsqp ( const std::vector< std::pair< double, double > > &  raw_point2d,
const std::vector< double > &  bounds,
std::vector< double > *  opt_x,
std::vector< double > *  opt_y 
)

◆ SqpWithOsqp() [2/2]

bool apollo::planning::FemPosDeviationSmoother::SqpWithOsqp ( const std::vector< std::pair< double, double > > &  raw_point2d,
const std::vector< double > &  bounds,
std::vector< double > *  opt_x,
std::vector< double > *  opt_y,
std::vector< std::vector< common::math::Vec2d > >  point_box 
)

在文件 fem_pos_deviation_smoother.cc 第 87 行定义.

91 {
92 if (opt_x == nullptr || opt_y == nullptr) {
93 AERROR << "opt_x or opt_y is nullptr";
94 return false;
95 }
96
97 FemPosDeviationSqpOsqpInterface solver;
98
99 solver.set_weight_fem_pos_deviation(config_.weight_fem_pos_deviation());
100 solver.set_weight_path_length(config_.weight_path_length());
101 solver.set_weight_ref_deviation(config_.weight_ref_deviation());
102 solver.set_weight_curvature_constraint_slack_var(
104 solver.set_point_box(point_box);
105
106 solver.set_curvature_constraint(config_.curvature_constraint());
107
108 solver.set_sqp_sub_max_iter(config_.sqp_sub_max_iter());
109 solver.set_sqp_ftol(config_.sqp_ftol());
110 solver.set_sqp_pen_max_iter(config_.sqp_pen_max_iter());
111 solver.set_sqp_ctol(config_.sqp_ctol());
112
113 solver.set_max_iter(config_.max_iter());
114 solver.set_time_limit(config_.time_limit());
115 solver.set_verbose(config_.verbose());
116 solver.set_scaled_termination(config_.scaled_termination());
117 solver.set_warm_start(config_.warm_start());
118
119 solver.set_ref_points(raw_point2d);
120 solver.set_bounds_around_refs(bounds);
121
122 if (!solver.Solve()) {
123 return false;
124 }
125
126 std::vector<std::pair<double, double>> opt_xy = solver.opt_xy();
127
128 // TODO(Jinyun): unify output data container
129 opt_x->resize(opt_xy.size());
130 opt_y->resize(opt_xy.size());
131 for (size_t i = 0; i < opt_xy.size(); ++i) {
132 (*opt_x)[i] = opt_xy[i].first;
133 (*opt_y)[i] = opt_xy[i].second;
134 }
135 return true;
136}

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