12#include "akreon/linalg/space/space_concepts.hpp"
25template <PortRole RoleT, std::
size_t OffsetT, std::
size_t SizeT>
28 static constexpr std::size_t
Offset = OffsetT;
29 static constexpr std::size_t
Size = SizeT;
32template <
typename Channel>
34 { Channel::Role } -> std::convertible_to<PortRole>;
35 { Channel::Offset } -> std::convertible_to<std::size_t>;
36 { Channel::Size } -> std::convertible_to<std::size_t>;
45 template <PortRole Role>
46 static consteval std::size_t
count() {
47 return (std::size_t{0} + ... +
48 (Channels::Role == Role ? std::size_t{1} : std::size_t{0}));
52 template <PortRole Role>
54 return (std::size_t{0} + ... +
55 (Channels::Role == Role ? Channels::Size : 0));
59 template <PortRole Role, std::
size_t Index>
60 static consteval std::size_t
offset() {
61 std::size_t current = 0;
62 std::size_t result = 0;
65 ((Channels::Role == Role
66 ? ((current == Index ? (result = Channels::Offset, 0) : 0), ++current,
70 static_assert(Index < count<Role>(),
"Requested port is missing");
75 template <PortRole Role, std::
size_t Index>
76 static consteval std::size_t
size() {
77 std::size_t current = 0;
78 std::size_t result = 0;
80 ((Channels::Role == Role
81 ? ((current == Index ? (result = Channels::Size, 0) : 0), ++current,
85 static_assert(Index < count<Role>(),
"Requested port is missing");
90 template <std::
size_t FullDim>
94 ((Channels::Size > 0 && Channels::Offset + Channels::Size <= FullDim) &&
96 bool occupied[FullDim == 0 ? 1 : FullDim]{};
97 auto mark = [&]<
typename Channel>()
consteval {
98 if constexpr (Channel::Offset + Channel::Size > FullDim) {
return; }
100 for (std::size_t i = Channel::Offset; i < Channel::Offset + Channel::Size;
102 if (occupied[i]) ok =
false;
107 (mark.template operator()<Channels>(), ...);
117 linalg::MatrixContainer ControlIn, linalg::MatrixContainer OutputIn>
121template <
class StateSpace>
126 linalg::MatrixContainer ControlIn, linalg::MatrixContainer OutputIn>
128 using Plant = linalg::remove_cvref_t<PlantIn>;
129 using Control = linalg::remove_cvref_t<ControlIn>;
130 using Output = linalg::remove_cvref_t<OutputIn>;
132 using T = linalg::matrix_scalar_t<Plant>;
133 using State = linalg::Vector<T, linalg::mat_cols_v<Plant>>;
134 using Input = linalg::Vector<T, linalg::mat_cols_v<Control>>;
135 using OutVec = linalg::Vector<T, linalg::mat_rows_v<Output>>;
140template <
typename StateSpace>
144template <
typename StateSpace>
149template <
typename StateSpace>
154template <
typename StateSpace>
159template <
typename StateSpace>
164template <
typename StateSpace>
169template <
typename StateSpace>
174template <
typename StateSpace>
180template <
typename StateSpace>
188template <
typename StateSpace>
193template <
typename StateSpace>
198template <StateSpaceLike SS,
typename InputPorts,
typename OutputPorts>
202template <
class Plant>
206template <StateSpaceLike SS,
typename InputPortsT,
typename OutputPortsT>
218 static constexpr std::size_t StateDim = linalg::vector_dim_v<State>;
219 static constexpr std::size_t InputDim = linalg::vector_dim_v<Input>;
220 static constexpr std::size_t OutputDim = linalg::vector_dim_v<Output>;
222 static constexpr std::size_t ExogenousDim =
224 static constexpr std::size_t ControlDim =
227 static constexpr std::size_t PerformanceDim =
229 static constexpr std::size_t MeasurementDim =
234template <
typename Plant>
238template <
typename Plant>
243template <
typename Plant>
248template <
typename Plant>
253template <
typename Plant>
258template <
typename Plant>
263template <
typename Plant>
268template <
typename Plant>
271 {
plant.state_space };
272 {
plant.exogenous_matrix() };
273 {
plant.control_matrix() };
274 {
plant.performance_matrix() };
275 {
plant.measurement_matrix() };
279template <
typename Plant>
285template <
typename Plant>
290template <
typename Plant>
ContinuousPlantModel concept.
ContinuousStateSpace concept.
DiscretePlantModel concept.
ContinuousStateSpace concept.
typename ss_traits< linalg::remove_cvref_t< StateSpace > >::Input input_vec_t
extract input vector
constexpr bool is_continuous_v
check if continuous or not
typename ss_traits< linalg::remove_cvref_t< StateSpace > >::Output ss_output_t
ss output type
@ PERFORMANCE
z: regulated/performance output
@ CONTROL
u: controller input to the plant
@ EXOGENOUS
w: disturbance, reference, noise, or other external input
@ MEASUREMENT
y: measured output available for feedback/estimation
typename ss_traits< linalg::remove_cvref_t< StateSpace > >::State state_vec_t
extract state vector
typename ss_traits< linalg::remove_cvref_t< StateSpace > >::T ss_type_t
extract scalar type from ss
typename plant_traits< linalg::remove_cvref_t< Plant > >::Output plant_output_vec_t
extract full output vector from plant
typename ss_traits< linalg::remove_cvref_t< StateSpace > >::OutVec output_vec_t
extract output vector
typename plant_traits< linalg::remove_cvref_t< Plant > >::State plant_state_vec_t
extract state vector from plant
typename plant_traits< linalg::remove_cvref_t< Plant > >::InputPorts plant_input_ports_t
extract input port layout type from plant
typename plant_traits< linalg::remove_cvref_t< Plant > >::T plant_type_t
extract scalar type from plant
typename ss_traits< linalg::remove_cvref_t< StateSpace > >::Control ss_control_t
ss control type
typename plant_traits< linalg::remove_cvref_t< Plant > >::StateSpace plant_state_space_t
extract state-space type from plant
typename plant_traits< linalg::remove_cvref_t< Plant > >::OutputPorts plant_output_ports_t
extract output port layout type from plant
TimeDomainType
time domain type
constexpr bool plant_is_continuous_v
check if plant model is continuous
typename ss_traits< linalg::remove_cvref_t< StateSpace > >::Plant ss_plant_t
ss plant type
typename plant_traits< linalg::remove_cvref_t< Plant > >::Input plant_input_vec_t
extract full input vector from plant
Forward declaration of PlantModel.
Port layout over either the state-space input or output axis.
static consteval std::size_t count()
count channels matching a port role
static consteval std::size_t size()
size of the Index-th channel matching a port role
static consteval std::size_t total_size()
total dimension for channels matching a port role
static consteval std::size_t offset()
offset of the Index-th channel matching a port role
static consteval bool validates()
validate port bounds and overlap against a full axis dimension
std::tuple< Channels... > ChannelsTuple
static constexpr PortRole Role
static constexpr std::size_t Size
static constexpr std::size_t Offset
forward decl of state space
base type traits for plant model
linalg::Vector< T, linalg::mat_rows_v< Output > > OutVec
linalg::remove_cvref_t< ControlIn > Control
linalg::remove_cvref_t< OutputIn > Output
linalg::remove_cvref_t< PlantIn > Plant
linalg::Vector< T, linalg::mat_cols_v< Plant > > State
linalg::matrix_scalar_t< Plant > T
linalg::Vector< T, linalg::mat_cols_v< Control > > Input
base type traits for state space