RIT VEXU Core API
Loading...
Searching...
No Matches
discretization.h
1#pragma once
2
3#include "core/math/eigen_interface.h"
4#include "../vendor/eigen/unsupported/Eigen/MatrixFunctions"
5
6#include <tuple>
7
19template <int STATES, int INPUTS>
20std::tuple<EMat<STATES, STATES>, EMat<STATES, INPUTS>> discretize_AB(EMat<STATES, STATES> Ac, EMat<STATES, INPUTS> Bc, const double &dt) {
21 /*
22 * Form the intermediate matrix M
23 * [A B]
24 * M = [0 0]
25 */
26 EMat<STATES + INPUTS, STATES + INPUTS> M;
27 M.template block<STATES, STATES>(0, 0) = Ac;
28 M.template block<STATES, INPUTS>(0, STATES) = Bc;
29 M.template block<INPUTS, STATES + INPUTS>(STATES, 0).setZero();
30
31 /*
32 * M * T [Ad Bd]
33 * e = [0 I]
34 */
35 EMat<STATES + INPUTS, STATES + INPUTS> phi = (M * dt).exp();
36
37 // Extract Ad and Bd from phi and put them in a tuple
38 return std::make_tuple(phi.template block<STATES, STATES>(0, 0), phi.template block<STATES, INPUTS>(0, STATES));
39}