cyqlone develop
Fast, parallel and vectorized solver for linear systems with optimal control structure.
Loading...
Searching...
No Matches
zoh.hpp
Go to the documentation of this file.
1#include <cyqlone/config.hpp>
2
3#include <Eigen/Core>
4#include <unsupported/Eigen/MatrixFunctions>
5#include <cassert>
6
7namespace CYQLONE_NS(cyqlone::qpalm::problems) {
8
9using eigen_mat = Eigen::MatrixX<real_t>;
10
11inline std::tuple<eigen_mat, eigen_mat> discretize_zoh(const Eigen::Ref<const eigen_mat> &A,
12 const Eigen::Ref<const eigen_mat> &B,
13 real_t Ts) {
14 assert(A.rows() == B.rows());
15 auto nx = A.rows(), nu = B.cols();
16 eigen_mat ABOO = eigen_mat::Zero(nx + nu, nx + nu);
17 ABOO.topLeftCorner(nx, nx) = A;
18 ABOO.topRightCorner(nx, nu) = B;
19 eigen_mat ABOId = (Ts * ABOO).exp();
20 return {ABOId.topLeftCorner(nx, nx), ABOId.topRightCorner(nx, nu)};
21}
22
23inline std::tuple<eigen_mat, eigen_mat, eigen_mat>
24discretize_zoh(const Eigen::Ref<const eigen_mat> &A, const Eigen::Ref<const eigen_mat> &B,
25 const Eigen::Ref<const eigen_mat> &b, real_t Ts) {
26 assert(A.rows() == B.rows());
27 assert(A.rows() == b.rows());
28 auto nx = A.rows(), nu = B.cols(), nb = b.cols();
29 eigen_mat ABOO = eigen_mat::Zero(nx + nu + nb, nx + nu + nb);
30 ABOO.block(0, 0, nx, nx) = A;
31 ABOO.block(0, nx, nx, nu) = B;
32 ABOO.block(0, nx + nu, nx, nb) = b;
33 eigen_mat ABOId = (Ts * ABOO).exp();
34 return {ABOId.block(0, 0, nx, nx), ABOId.block(0, nx, nx, nu), ABOId.block(0, nx + nu, nx, nb)};
35}
36
37} // namespace CYQLONE_NS(cyqlone::qpalm::problems)
#define CYQLONE_NS(ns)
Definition config.hpp:10
Eigen::MatrixX< real_t > eigen_mat
Definition zoh.hpp:9
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)
Definition zoh.hpp:11