Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Pinoxchio
apollo
提交
68f6a785
A
apollo
项目概览
Pinoxchio
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
68f6a785
编写于
7月 24, 2017
作者:
Q
Qi Luo
提交者:
Dong Li
7月 24, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Replace qpSMOSolver with qpOASES
上级
ceef06be
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
55 addition
and
69 deletion
+55
-69
modules/common/math/BUILD
modules/common/math/BUILD
+4
-0
modules/common/math/mpc_solver.cc
modules/common/math/mpc_solver.cc
+31
-50
modules/common/math/mpc_solver.h
modules/common/math/mpc_solver.h
+17
-17
modules/common/math/mpc_solver_test.cc
modules/common/math/mpc_solver_test.cc
+3
-2
未找到文件。
modules/common/math/BUILD
浏览文件 @
68f6a785
...
...
@@ -277,6 +277,8 @@ cc_library(
],
deps
=
[
"//modules/common:log"
,
"//modules/common/math/qp_solver:qp_solver"
,
"//modules/common/math/qp_solver:active_set_qp_solver"
,
"@eigen//:eigen"
,
],
)
...
...
@@ -289,6 +291,8 @@ cc_test(
],
deps
=
[
":mpc"
,
"//modules/common/math/qp_solver:qp_solver"
,
"//modules/common/math/qp_solver:active_set_qp_solver"
,
"@gtest//:main"
,
],
)
...
...
modules/common/math/mpc_solver.cc
浏览文件 @
68f6a785
...
...
@@ -15,6 +15,7 @@
#include "modules/common/math/mpc_solver.h"
#include <algorithm>
#include <memory>
#include "modules/common/log.h"
...
...
@@ -23,6 +24,8 @@ namespace common {
namespace
math
{
using
Matrix
=
Eigen
::
MatrixXd
;
using
::
apollo
::
common
::
math
::
QPSolver
;
using
::
apollo
::
common
::
math
::
ActiveSetQPSolver
;
// discrete linear predictive control solver, with control format
// x(i + 1) = A * x(i) + B * u (i) + C
...
...
@@ -110,65 +113,43 @@ void SolveLinearMPC(const Matrix &matrix_a,
Matrix
matrix_m1
=
matrix_k
.
transpose
()
*
matrix_qq
*
matrix_k
+
matrix_rr
;
Matrix
matrix_m2
=
matrix_k
.
transpose
()
*
matrix_qq
*
(
matrix_m
-
matrix_t
);
// Method 1: QPOASES
Eigen
::
MatrixXd
matrix_inequality_constrain_ll
=
-
Eigen
::
MatrixXd
::
Identity
(
matrix_ll
.
rows
(),
matrix_ll
.
rows
());
Eigen
::
MatrixXd
matrix_inequality_constrain_uu
=
Eigen
::
MatrixXd
::
Identity
(
matrix_uu
.
rows
(),
matrix_uu
.
rows
());
Eigen
::
MatrixXd
matrix_inequality_constrain
=
Eigen
::
MatrixXd
::
Zero
(
matrix_ll
.
rows
()
+
matrix_uu
.
rows
(),
matrix_ll
.
rows
());
matrix_inequality_constrain
<<
matrix_inequality_constrain_ll
,
matrix_inequality_constrain_uu
;
Eigen
::
MatrixXd
matrix_inequality_boundary
=
Eigen
::
MatrixXd
::
Zero
(
matrix_ll
.
rows
()
+
matrix_uu
.
rows
(),
matrix_ll
.
cols
());
matrix_inequality_boundary
<<
matrix_ll
,
matrix_uu
;
Eigen
::
MatrixXd
matrix_equality_constrain
=
Eigen
::
MatrixXd
::
Zero
(
matrix_ll
.
rows
()
+
matrix_uu
.
rows
(),
matrix_ll
.
rows
());
Eigen
::
MatrixXd
matrix_equality_boundary
=
Eigen
::
MatrixXd
::
Zero
(
matrix_ll
.
rows
()
+
matrix_uu
.
rows
(),
matrix_ll
.
cols
());
std
::
unique_ptr
<
QPSolver
>
qp_solver
(
new
ActiveSetQPSolver
(
matrix_m1
,
matrix_m2
,
matrix_inequality_constrain
,
matrix_inequality_boundary
,
matrix_equality_constrain
,
matrix_equality_boundary
));
qp_solver
->
solve
();
matrix_v
=
qp_solver
->
params
();
/*
// Method 2: QP_SMO_Solver
SolveQPSMO(matrix_m1, matrix_m2, matrix_ll, matrix_uu, eps, max_iter,
&matrix_v);
i*/
for
(
unsigned
int
i
=
0
;
i
<
horizon
;
++
i
)
{
(
*
control
)[
i
]
=
matrix_v
.
block
(
i
*
(
*
control
)[
0
].
rows
(),
0
,
(
*
control
)[
0
].
rows
(),
1
);
}
}
void
SolveQPSMO
(
const
Matrix
&
matrix_q
,
const
Matrix
&
matrix_b
,
const
Matrix
&
matrix_lower
,
const
Matrix
&
matrix_upper
,
const
double
&
eps
,
const
int
&
max_iter
,
Matrix
*
matrix_v
)
{
// Warning: Skipped the sanity check since this is designed for solely used by
// mpc_solver.
// TODO(Capri2014): Replace this with available QP solver
Matrix
matrix_df
=
matrix_q
*
(
*
matrix_v
)
+
matrix_b
;
Matrix
matrix_q_inv
=
matrix_q
.
inverse
();
for
(
int
iter
=
0
;
iter
<
max_iter
;
++
iter
)
{
double
max_df
=
0
;
int
best_r
=
0
;
for
(
int
r
=
0
;
r
<
matrix_q
.
rows
();
++
r
)
{
if
((
*
matrix_v
)(
r
)
<=
matrix_lower
(
r
)
&&
matrix_df
(
r
)
>
0
)
{
continue
;
}
else
if
((
*
matrix_v
)(
r
)
>=
matrix_upper
(
r
)
&&
matrix_df
(
r
)
<
0
)
{
continue
;
}
else
if
(
std
::
abs
(
matrix_df
(
r
))
>
max_df
)
{
best_r
=
r
;
max_df
=
std
::
abs
(
matrix_df
(
r
));
}
}
int
r
=
best_r
;
{
const
double
old_alpha
=
(
*
matrix_v
)(
r
);
(
*
matrix_v
)(
r
)
=
-
(
matrix_df
(
r
)
-
matrix_q
(
r
,
r
)
*
(
*
matrix_v
)(
r
))
*
matrix_q_inv
(
r
);
if
((
*
matrix_v
)(
r
)
<
matrix_lower
(
r
))
{
(
*
matrix_v
)(
r
)
=
matrix_lower
(
r
);
}
else
if
((
*
matrix_v
)(
r
)
>
matrix_upper
(
r
))
{
(
*
matrix_v
)(
r
)
=
matrix_upper
(
r
);
}
const
double
delta
=
old_alpha
-
(
*
matrix_v
)(
r
);
// Gradient update.
for
(
int
k
=
0
;
k
<
matrix_df
.
rows
();
++
k
)
{
matrix_df
(
k
)
-=
matrix_q
(
r
,
k
)
*
delta
;
}
}
if
(
max_df
<
eps
)
{
break
;
}
}
}
}
// namespace math
}
// namespace common
}
// namespace apollo
modules/common/math/mpc_solver.h
浏览文件 @
68f6a785
...
...
@@ -26,6 +26,10 @@
#include "Eigen/Core"
#include "Eigen/LU"
#include "modules/common/math/qp_solver/qp_solver.h"
#include "modules/common/math/qp_solver/active_set_qp_solver.h"
/**
* @namespace apollo::common::math
* @brief apollo::common::math
...
...
@@ -36,14 +40,18 @@ namespace common {
namespace
math
{
/**
* @brief Solver for discrete-time model predictive control problem.
* @param A The system dynamic matrix
* @param B The control matrix
* @param Q The cost matrix for system state
* @param R The cost matrix for control output
* @param tolerance The numerical tolerance for solving
* Algebraic Riccati equation (ARE)
* @param max_num_iteration The maximum iterations for solving ARE
* @param ptr_K The feedback control matrix (pointer)
* @param matrix_a The system dynamic matrix
* @param matrix_b The control matrix
* @param matrix_c The disturbance matrix
* @param matrix_q The cost matrix for control state
* @param matrix_lower The lower bound control constrain matrix
* @param matrix_upper The upper bound control constrain matrix
* @param matrix_upper The upper bound control constrain matrix
* @param matrix_initial_state The intial state matrix
* @param reference The control reference vector with respect to time
* @param eps The control convergence tolerance
* @param max_iter The maximum iterations for solving ARE
* @param control The feedback control matrix (pointer)
*/
void
SolveLinearMPC
(
const
Eigen
::
MatrixXd
&
matrix_a
,
const
Eigen
::
MatrixXd
&
matrix_b
,
...
...
@@ -52,20 +60,12 @@ void SolveLinearMPC(const Eigen::MatrixXd &matrix_a,
const
Eigen
::
MatrixXd
&
matrix_r
,
const
Eigen
::
MatrixXd
&
matrix_lower
,
const
Eigen
::
MatrixXd
&
matrix_upper
,
const
Eigen
::
MatrixXd
&
_
matrix_initial_state
,
const
Eigen
::
MatrixXd
&
matrix_initial_state
,
const
std
::
vector
<
Eigen
::
MatrixXd
>
&
reference
,
const
double
eps
,
const
int
max_iter
,
std
::
vector
<
Eigen
::
MatrixXd
>
*
control
);
void
SolveQPSMO
(
const
Eigen
::
MatrixXd
&
matrix_q
,
const
Eigen
::
MatrixXd
&
matrix_b
,
const
Eigen
::
MatrixXd
&
matrix_lower
,
const
Eigen
::
MatrixXd
&
matrix_upper
,
const
double
&
eps
,
const
int
&
max_iter
,
Eigen
::
MatrixXd
*
matrix_alpha
);
}
// namespace math
}
// namespace common
}
// namespace apollo
...
...
modules/common/math/mpc_solver_test.cc
浏览文件 @
68f6a785
...
...
@@ -21,7 +21,7 @@
namespace
apollo
{
namespace
common
{
namespace
math
{
/*
TEST(MPCSolverTest, MPC) {
const int STATES = 4;
const int CONTROLS = 1;
...
...
@@ -145,8 +145,9 @@ TEST(MPCSolverTest, MPC) {
initial_state2 = A * initial_state2 + B * control2[0](0) + C;
}
}
*/
}
// namespace math
}
// namespace common
}
// namespace apollo
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录