Apollo 10.0
自动驾驶开放平台
apollo::common::math::MpcOsqp类 参考

#include <mpc_osqp.h>

apollo::common::math::MpcOsqp 的协作图:

Public 成员函数

 MpcOsqp (const Eigen::MatrixXd &matrix_a, const Eigen::MatrixXd &matrix_b, const Eigen::MatrixXd &matrix_q, const Eigen::MatrixXd &matrix_r, const Eigen::MatrixXd &matrix_initial_x, const Eigen::MatrixXd &matrix_u_lower, const Eigen::MatrixXd &matrix_u_upper, const Eigen::MatrixXd &matrix_x_lower, const Eigen::MatrixXd &matrix_x_upper, const Eigen::MatrixXd &matrix_x_ref, const int max_iter, const int horizon, const double eps_abs)
 Solver for discrete-time model predictive control problem.
 
bool Solve (std::vector< double > *control_cmd)
 

详细描述

在文件 mpc_osqp.h33 行定义.

构造及析构函数说明

◆ MpcOsqp()

apollo::common::math::MpcOsqp::MpcOsqp ( const Eigen::MatrixXd &  matrix_a,
const Eigen::MatrixXd &  matrix_b,
const Eigen::MatrixXd &  matrix_q,
const Eigen::MatrixXd &  matrix_r,
const Eigen::MatrixXd &  matrix_initial_x,
const Eigen::MatrixXd &  matrix_u_lower,
const Eigen::MatrixXd &  matrix_u_upper,
const Eigen::MatrixXd &  matrix_x_lower,
const Eigen::MatrixXd &  matrix_x_upper,
const Eigen::MatrixXd &  matrix_x_ref,
const int  max_iter,
const int  horizon,
const double  eps_abs 
)

Solver for discrete-time model predictive control problem.

参数
matrix_aThe system dynamic matrix
matrix_bThe control matrix
matrix_qThe cost matrix for control state
matrix_lowerThe lower bound control constrain matrix
matrix_upperThe upper bound control constrain matrix
matrix_initial_stateThe initial state matrix
max_iterThe maximum iterations

在文件 mpc_osqp.cc22 行定义.

33 : matrix_a_(matrix_a),
34 matrix_b_(matrix_b),
35 matrix_q_(matrix_q),
36 matrix_r_(matrix_r),
37 matrix_initial_x_(matrix_initial_x),
38 matrix_u_lower_(matrix_u_lower),
39 matrix_u_upper_(matrix_u_upper),
40 matrix_x_lower_(matrix_x_lower),
41 matrix_x_upper_(matrix_x_upper),
42 matrix_x_ref_(matrix_x_ref),
43 max_iteration_(max_iter),
44 horizon_(horizon),
45 eps_abs_(eps_abs) {
46 state_dim_ = matrix_b.rows();
47 control_dim_ = matrix_b.cols();
48 ADEBUG << "state_dim" << state_dim_;
49 ADEBUG << "control_dim_" << control_dim_;
50 num_param_ = state_dim_ * (horizon_ + 1) + control_dim_ * horizon_;
51}
#define ADEBUG
Definition log.h:41

成员函数说明

◆ Solve()

bool apollo::common::math::MpcOsqp::Solve ( std::vector< double > *  control_cmd)

在文件 mpc_osqp.cc281 行定义.

281 {
282 ADEBUG << "Before Calc Gradient";
283 CalculateGradient();
284 ADEBUG << "After Calc Gradient";
285 CalculateConstraintVectors();
286 ADEBUG << "MPC2Matrix";
287
288 OSQPData *data = Data();
289 ADEBUG << "OSQP data done";
290 ADEBUG << "OSQP data n" << data->n;
291 ADEBUG << "OSQP data m" << data->m;
292 for (int i = 0; i < data->n; ++i) {
293 ADEBUG << "OSQP data q" << i << ":" << (data->q)[i];
294 }
295 ADEBUG << "OSQP data l" << data->l;
296 for (int i = 0; i < data->m; ++i) {
297 ADEBUG << "OSQP data l" << i << ":" << (data->l)[i];
298 }
299 ADEBUG << "OSQP data u" << data->u;
300 for (int i = 0; i < data->m; ++i) {
301 ADEBUG << "OSQP data u" << i << ":" << (data->u)[i];
302 }
303
304 OSQPSettings *settings = Settings();
305 ADEBUG << "OSQP setting done";
306 OSQPWorkspace *osqp_workspace = nullptr;
307 // osqp_setup(&osqp_workspace, data, settings);
308 osqp_workspace = osqp_setup(data, settings);
309 ADEBUG << "OSQP workspace ready";
310 osqp_solve(osqp_workspace);
311
312 auto status = osqp_workspace->info->status_val;
313 ADEBUG << "status:" << status;
314 // check status
315 if (status < 0 || (status != 1 && status != 2)) {
316 AERROR << "failed optimization status:\t" << osqp_workspace->info->status;
317 osqp_cleanup(osqp_workspace);
318 FreeData(data);
319 c_free(settings);
320 return false;
321 } else if (osqp_workspace->solution == nullptr) {
322 AERROR << "The solution from OSQP is nullptr";
323 osqp_cleanup(osqp_workspace);
324 FreeData(data);
325 c_free(settings);
326 return false;
327 }
328
329 size_t first_control = state_dim_ * (horizon_ + 1);
330 for (size_t i = 0; i < control_dim_; ++i) {
331 control_cmd->at(i) = osqp_workspace->solution->x[i + first_control];
332 ADEBUG << "control_cmd:" << i << ":" << control_cmd->at(i);
333 }
334
335 // Cleanup
336 osqp_cleanup(osqp_workspace);
337 FreeData(data);
338 c_free(settings);
339 return true;
340}
#define AERROR
Definition log.h:44

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