4#include <guanaqo/eigen/view.hpp>
13 const auto inf = std::numeric_limits<real_t>::infinity();
15 auto n_vehicle =
static_cast<index_t
>(p.
masses.size());
20 .ny = 2 * n_vehicle + (n_vehicle - 1),
21 .ny_N = n_vehicle + (n_vehicle - 1),
23 auto [N, nx, nu, ny, ny_N] = ocp.
dim;
26 eigen_mat A = eigen_mat::Zero(nx, nx), B = eigen_mat::Zero(nx, nu);
27 for (Eigen::Index
v = 0;
v < n_vehicle; ++
v) {
28 A(2 *
v, 2 *
v + 1) = 1;
37 ocp.
b().set_constant(0);
38 for (index_t
v = 0;
v < n_vehicle; ++
v)
39 ocp.
b(0)(2 *
v, 0) = -
static_cast<real_t
>(
v) * p.
dist_init;
40 ocp.
b_min().set_constant(-inf);
41 ocp.
b_max().set_constant(+inf);
44 for (index_t i = 0; i < N; ++i) {
45 auto Ai = ocp.
A(i), Bi = ocp.
B(i), Ci = ocp.
C(i), Di = ocp.
D(i);
46 auto Qi = ocp.
Q(i), Ri = ocp.
R(i);
48 for (index_t
v = 0;
v < n_vehicle; ++
v) {
54 Di(2 * n_vehicle - 1 +
v,
v) = 1;
55 lbi(2 * n_vehicle - 1 +
v, 0) = -p.
F_max;
56 ubi(2 * n_vehicle - 1 +
v, 0) = +p.
F_max;
60 Ci(n_vehicle +
v - 1, 2 *
v) = 1;
61 Ci(n_vehicle +
v - 1, 2 * (
v - 1)) = -1;
62 Ci(n_vehicle +
v - 1, 2 *
v + 1) = Ts;
63 Ci(n_vehicle +
v - 1, 2 * (
v - 1) + 1) = -Ts;
64 lbi(n_vehicle +
v - 1, 0) = -inf;
67 Qi(2 *
v, 2 *
v) = scal * 10;
68 Qi(2 *
v + 1, 2 *
v + 1) = scal * 1;
72 auto Ci = ocp.
C(N), Qi = ocp.
Q(N);
74 for (index_t
v = 0;
v < n_vehicle; ++
v) {
80 Ci(n_vehicle +
v - 1, 2 *
v) = 1;
81 Ci(n_vehicle +
v - 1, 2 * (
v - 1)) = -1;
82 Ci(n_vehicle +
v - 1, 2 *
v + 1) = Ts;
83 Ci(n_vehicle +
v - 1, 2 * (
v - 1) + 1) = -Ts;
84 lbi(n_vehicle +
v - 1, 0) = -inf;
87 Qi(2 *
v, 2 *
v) = scal * 100;
88 Qi(2 *
v + 1, 2 *
v + 1) = scal * 1;
90 std::vector<real_t> ref(nx + nu + nx);
91 for (index_t
v = 0;
v < n_vehicle; ++
v) {
98 .ocp = std::move(ocp),
99 .ref = std::move(ref),
Conversion utilities for optimal control problems.
auto as_view(Eigen::DenseBase< Derived > &M, with_index_type_t< I >={})
std::vector< real_t > masses
Eigen::MatrixX< real_t > eigen_mat
PlatooningProblem platooning(PlatooningParams p)
std::tuple< eigen_mat, eigen_mat > discretize_zoh(const Eigen::Ref< const eigen_mat > &A, const Eigen::Ref< const eigen_mat > &B, real_t Ts)
Storage for a linear-quadratic OCP of the form.
guanaqo::MatrixView< real_t, index_t > B(index_t i)
guanaqo::MatrixView< real_t, index_t > D(index_t i)
guanaqo::MatrixView< real_t, index_t > b_min()
guanaqo::MatrixView< real_t, index_t > b()
guanaqo::MatrixView< real_t, index_t > R(index_t i)
guanaqo::MatrixView< real_t, index_t > C(index_t i)
guanaqo::MatrixView< real_t, index_t > Q(index_t i)
guanaqo::MatrixView< real_t, index_t > A(index_t i)
guanaqo::MatrixView< real_t, index_t > b_max()