akreon-control
Optimal and robust control and state estimation in C++26.
Loading...
Searching...
No Matches
state_space.hpp
Go to the documentation of this file.
1/*
2 * Copyright © 2025-2026 Akreon LLC
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6#include "../control_traits.hpp"
7
8#pragma once
9
10namespace control {
11
18template <TimeDomainType Type, linalg::SquareMatrix PlantIn,
19 linalg::MatrixContainer ControlIn, linalg::MatrixContainer OutputIn>
20struct StateSpace {
22 using Plant = linalg::remove_cvref_t<PlantIn>;
23 using Control = linalg::remove_cvref_t<ControlIn>;
24 using Output = linalg::remove_cvref_t<OutputIn>;
25
26 using T = linalg::matrix_scalar_t<Plant>;
27 static constexpr std::size_t PlantRows = linalg::mat_rows_v<Plant>;
28 static constexpr std::size_t PlantCols = linalg::mat_cols_v<Plant>;
29 static constexpr std::size_t ControlRows = linalg::mat_rows_v<Control>;
30 static constexpr std::size_t ControlCols = linalg::mat_cols_v<Control>;
31 static constexpr std::size_t OutputRows = linalg::mat_rows_v<Output>;
32 static constexpr std::size_t OutputCols = linalg::mat_cols_v<Output>;
33
34 using Feedthrough = linalg::Matrix<T, OutputRows, ControlCols>;
35
36 static_assert(PlantRows == ControlRows,
37 "state dim is not aligned between plant and control matrices");
38
40 using State = linalg::Vector<T, PlantCols>;
41 using Input = linalg::Vector<T, ControlCols>;
42
50 constexpr explicit StateSpace(const Plant& A_in, const Control& B_in,
51 const Output& C_in)
52 : A(A_in), B(B_in), C(C_in) {}
53
62 constexpr explicit StateSpace(const Plant& A_in, const Control& B_in,
63 const Output& C_in, const Feedthrough& D_in)
64 : A(A_in), B(B_in), C(C_in), D(D_in) {}
65
80 constexpr auto state_update(const State& x, const Input& u) const {
81 return A * x + B * u;
82 }
83
95 constexpr auto output_map(const State& x, const Input& u) const {
96 return D.has_value() ? C * x + (*D) * u : C * x;
97 }
98
103 std::optional<Feedthrough> D;
104};
105
106} // namespace control
constexpr bool is_continuous_v
check if continuous or not
TimeDomainType
time domain type
forward decl of state space
static constexpr std::size_t ControlRows
linalg::matrix_scalar_t< Plant > T
static constexpr std::size_t OutputCols
constexpr StateSpace(const Plant &A_in, const Control &B_in, const Output &C_in, const Feedthrough &D_in)
CTOR.
linalg::remove_cvref_t< ControlIn > Control
Plant A
member var
static constexpr std::size_t OutputRows
Output C
Output matrix.
std::optional< Feedthrough > D
Feedthrough matrix.
linalg::Matrix< T, OutputRows, ControlCols > Feedthrough
constexpr auto state_update(const State &x, const Input &u) const
state_update
linalg::Vector< T, PlantCols > State
state vector
static constexpr std::size_t PlantRows
linalg::remove_cvref_t< PlantIn > Plant
extract type and alias
linalg::remove_cvref_t< OutputIn > Output
static constexpr std::size_t ControlCols
constexpr StateSpace(const Plant &A_in, const Control &B_in, const Output &C_in)
CTOR.
linalg::Vector< T, ControlCols > Input
constexpr auto output_map(const State &x, const Input &u) const
output_map
Control B
Control matrix.
static constexpr std::size_t PlantCols